yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/apsara/shell/snapshot.go (about)

     1  // Copyright 2019 Yunion
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package shell
    16  
    17  import (
    18  	"fmt"
    19  
    20  	"yunion.io/x/cloudmux/pkg/multicloud/apsara"
    21  	"yunion.io/x/onecloud/pkg/util/shellutils"
    22  )
    23  
    24  func init() {
    25  	type SnapshotListOptions struct {
    26  		DiskId      string   `help:"Disk ID"`
    27  		InstanceId  string   `help:"Instance ID"`
    28  		SnapshotIds []string `helo:"Snapshot ids"`
    29  		Name        string   `help:"Snapshot Name"`
    30  		Limit       int      `help:"page size"`
    31  		Offset      int      `help:"page offset"`
    32  	}
    33  	shellutils.R(&SnapshotListOptions{}, "snapshot-list", "List snapshot", func(cli *apsara.SRegion, args *SnapshotListOptions) error {
    34  		if snapshots, total, err := cli.GetSnapshots(args.InstanceId, args.DiskId, args.Name, args.SnapshotIds, args.Offset, args.Limit); err != nil {
    35  			return err
    36  		} else {
    37  			printList(snapshots, total, args.Offset, args.Limit, []string{})
    38  			return nil
    39  		}
    40  	})
    41  
    42  	type SnapshotDeleteOptions struct {
    43  		ID string `help:"Snapshot ID"`
    44  	}
    45  
    46  	shellutils.R(&SnapshotDeleteOptions{}, "snapshot-delete", "Delete snapshot", func(cli *apsara.SRegion, args *SnapshotDeleteOptions) error {
    47  		if err := cli.SnapshotPreDelete(args.ID); err != nil {
    48  			return fmt.Errorf("Snapshot PreDelete error: %s", err)
    49  		}
    50  		return cli.DeleteSnapshot(args.ID)
    51  	})
    52  
    53  	type SnapshotCreateOptions struct {
    54  		DiskId string `help:"Disk ID"`
    55  		Name   string `help:"Snapeshot Name"`
    56  		Desc   string `help:"Snapshot Desc"`
    57  	}
    58  
    59  	shellutils.R(&SnapshotCreateOptions{}, "snapshot-create", "Create snapshot", func(cli *apsara.SRegion, args *SnapshotCreateOptions) error {
    60  		snapshotId, err := cli.CreateSnapshot(args.DiskId, args.Name, args.Desc)
    61  		if err != nil {
    62  			return err
    63  		}
    64  		fmt.Println(snapshotId)
    65  		return nil
    66  	})
    67  
    68  }