yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/ctyun/shell/disk.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 "context" 19 20 "yunion.io/x/cloudmux/pkg/multicloud/ctyun" 21 "yunion.io/x/onecloud/pkg/util/shellutils" 22 ) 23 24 func init() { 25 type VDiskListOptions struct { 26 } 27 shellutils.R(&VDiskListOptions{}, "disk-list", "List disks", func(cli *ctyun.SRegion, args *VDiskListOptions) error { 28 disks, e := cli.GetDisks() 29 if e != nil { 30 return e 31 } 32 printList(disks, 0, 0, 0, nil) 33 return nil 34 }) 35 36 type DiskCreateOptions struct { 37 ZoneId string `help:"zone id"` 38 Name string `help:"disk name"` 39 DiskType string `help:"disk type" choice:"SSD|SAS|SATA"` 40 Size string `help:"disk size"` 41 } 42 shellutils.R(&DiskCreateOptions{}, "disk-create", "Create disk", func(cli *ctyun.SRegion, args *DiskCreateOptions) error { 43 disk, e := cli.CreateDisk(args.ZoneId, args.Name, args.DiskType, args.Size) 44 if e != nil { 45 return e 46 } 47 printObject(disk) 48 return nil 49 }) 50 51 type DiskResizeOptions struct { 52 DiskId string `help:"disk id"` 53 Size int64 `help:"disk size GB"` 54 } 55 shellutils.R(&DiskResizeOptions{}, "disk-resize", "Resize disk", func(cli *ctyun.SRegion, args *DiskResizeOptions) error { 56 disk, err := cli.GetDisk(args.DiskId) 57 if err != nil { 58 return err 59 } 60 61 e := disk.Resize(context.Background(), args.Size*1024) 62 if e != nil { 63 return e 64 } 65 printObject(disk) 66 return nil 67 }) 68 69 type VDiskRestoreOptions struct { 70 DiskId string `help:"disk id"` 71 SnapshotId string `help:"snapshot id"` 72 } 73 shellutils.R(&VDiskRestoreOptions{}, "disk-restore", "Restore disk", func(cli *ctyun.SRegion, args *VDiskRestoreOptions) error { 74 disk, err := cli.GetDisk(args.DiskId) 75 if err != nil { 76 return err 77 } 78 79 _, e := disk.Reset(context.Background(), args.SnapshotId) 80 if e != nil { 81 return e 82 } 83 printObject(disk) 84 return nil 85 }) 86 }