yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/apsara/shell/image.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 ImageListOptions struct { 26 Status string `help:"image status type" choices:"Creating|Available|UnAvailable|CreateFailed"` 27 Owner string `help:"Owner type" choices:"system|self|others|marketplace"` 28 Id []string `help:"Image ID"` 29 Name string `help:"image name"` 30 Limit int `help:"page size"` 31 Offset int `help:"page offset"` 32 } 33 shellutils.R(&ImageListOptions{}, "image-list", "List images", func(cli *apsara.SRegion, args *ImageListOptions) error { 34 images, total, e := cli.GetImages(apsara.ImageStatusType(args.Status), apsara.ImageOwnerType(args.Owner), args.Id, args.Name, args.Offset, args.Limit) 35 if e != nil { 36 return e 37 } 38 printList(images, total, args.Offset, args.Limit, []string{}) 39 return nil 40 }) 41 42 type ImageShowOptions struct { 43 ID string `help:"image ID"` 44 } 45 shellutils.R(&ImageShowOptions{}, "image-show", "Show image", func(cli *apsara.SRegion, args *ImageShowOptions) error { 46 img, err := cli.GetImage(args.ID) 47 if err != nil { 48 return err 49 } 50 printObject(img) 51 return nil 52 }) 53 54 type ImageDeleteOptions struct { 55 ID string `help:"ID or Name to delete"` 56 } 57 shellutils.R(&ImageDeleteOptions{}, "image-delete", "Delete image", func(cli *apsara.SRegion, args *ImageDeleteOptions) error { 58 return cli.DeleteImage(args.ID) 59 }) 60 61 type ImageCreateOptions struct { 62 SNAPSHOT string `help:"Snapshot id"` 63 NAME string `help:"Image name"` 64 Desc string `help:"Image desc"` 65 } 66 shellutils.R(&ImageCreateOptions{}, "image-create", "Create image", func(cli *apsara.SRegion, args *ImageCreateOptions) error { 67 imageId, err := cli.CreateImage(args.SNAPSHOT, args.NAME, args.Desc) 68 if err != nil { 69 return err 70 } 71 fmt.Println(imageId) 72 return nil 73 }) 74 75 type ImageExportOptions struct { 76 ID string `help:"ID or Name to export"` 77 BUCKET string `help:"Bucket name"` 78 } 79 80 shellutils.R(&ImageExportOptions{}, "image-export", "Export image", func(cli *apsara.SRegion, args *ImageExportOptions) error { 81 task, err := cli.ExportImage(args.ID, args.BUCKET) 82 if err != nil { 83 return err 84 } 85 printObject(task) 86 return nil 87 }) 88 }