yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/nutanix/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 "os" 19 20 "yunion.io/x/cloudmux/pkg/cloudprovider" 21 "yunion.io/x/cloudmux/pkg/multicloud/nutanix" 22 "yunion.io/x/onecloud/pkg/util/shellutils" 23 ) 24 25 func init() { 26 type ImageListOptions struct { 27 } 28 shellutils.R(&ImageListOptions{}, "image-list", "list hosts", func(cli *nutanix.SRegion, args *ImageListOptions) error { 29 images, err := cli.GetImages() 30 if err != nil { 31 return err 32 } 33 printList(images, 0, 0, 0, []string{}) 34 return nil 35 }) 36 37 type ImageIdOptions struct { 38 ID string 39 } 40 41 shellutils.R(&ImageIdOptions{}, "image-show", "show host", func(cli *nutanix.SRegion, args *ImageIdOptions) error { 42 image, err := cli.GetImage(args.ID) 43 if err != nil { 44 return err 45 } 46 printObject(image) 47 return nil 48 }) 49 50 type ImageUploadOptions struct { 51 STOREG_ID string 52 NAME string 53 FILE string 54 } 55 56 shellutils.R(&ImageUploadOptions{}, "image-upload", "upload host", func(cli *nutanix.SRegion, args *ImageUploadOptions) error { 57 fi, err := os.Open(args.FILE) 58 if err != nil { 59 return err 60 } 61 defer fi.Close() 62 63 stat, _ := fi.Stat() 64 image, err := cli.CreateImage( 65 args.STOREG_ID, 66 &cloudprovider.SImageCreateOption{ 67 ImageName: args.NAME, 68 }, 69 stat.Size(), 70 fi, 71 nil, 72 ) 73 if err != nil { 74 return err 75 } 76 printObject(image) 77 return nil 78 }) 79 80 }