yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/qcloud/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 "yunion.io/x/cloudmux/pkg/multicloud/qcloud" 19 "yunion.io/x/onecloud/pkg/util/shellutils" 20 ) 21 22 func init() { 23 type SnapshotListOptions struct { 24 DiskId string `help:"Disk ID"` 25 InstanceId string `help:"Instance ID"` 26 SnapshotIds []string `helo:"Snapshot ids"` 27 Name string `help:"Snapshot Name"` 28 Limit int `help:"page size"` 29 Offset int `help:"page offset"` 30 } 31 shellutils.R(&SnapshotListOptions{}, "snapshot-list", "List snapshot", func(cli *qcloud.SRegion, args *SnapshotListOptions) error { 32 snapshots, total, err := cli.GetSnapshots(args.InstanceId, args.DiskId, args.Name, args.SnapshotIds, args.Offset, args.Limit) 33 if err != nil { 34 return err 35 } 36 printList(snapshots, total, args.Offset, args.Limit, []string{}) 37 return nil 38 }) 39 40 type SnapshotDeleteOptions struct { 41 ID string `help:"Snapshot ID"` 42 } 43 44 shellutils.R(&SnapshotDeleteOptions{}, "snapshot-delete", "Delete snapshot", func(cli *qcloud.SRegion, args *SnapshotDeleteOptions) error { 45 return cli.DeleteSnapshot(args.ID) 46 }) 47 48 type SnapshotCreateOptions struct { 49 DISK string `help:"Disk ID"` 50 Name string `help:"Snapeshot Name"` 51 Desc string `help:"Snapshot Desc"` 52 } 53 54 shellutils.R(&SnapshotCreateOptions{}, "snapshot-create", "Create snapshot", func(cli *qcloud.SRegion, args *SnapshotCreateOptions) error { 55 _, err := cli.CreateSnapshot(args.DISK, args.Name, args.Desc) 56 return err 57 }) 58 59 }