yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/zstack/shell/instance.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/zstack" 21 "yunion.io/x/onecloud/pkg/util/shellutils" 22 ) 23 24 func init() { 25 type InstanceListOptions struct { 26 HostId string 27 InstanceId string 28 NicId string 29 } 30 shellutils.R(&InstanceListOptions{}, "instance-list", "List instances", func(cli *zstack.SRegion, args *InstanceListOptions) error { 31 instances, err := cli.GetInstances(args.HostId, args.InstanceId, args.NicId) 32 if err != nil { 33 return err 34 } 35 printList(instances, len(instances), 0, 0, []string{}) 36 return nil 37 }) 38 39 type InstanceOperation struct { 40 ID string 41 } 42 43 shellutils.R(&InstanceOperation{}, "instance-delete", "Delete instance", func(cli *zstack.SRegion, args *InstanceOperation) error { 44 return cli.DeleteVM(args.ID) 45 }) 46 47 shellutils.R(&InstanceOperation{}, "instance-console-password", "Show instance console password", func(cli *zstack.SRegion, args *InstanceOperation) error { 48 password, err := cli.GetInstanceConsolePassword(args.ID) 49 if err != nil { 50 return err 51 } 52 fmt.Println(password) 53 return nil 54 }) 55 56 shellutils.R(&InstanceOperation{}, "instance-console-info", "Show instance console info", func(cli *zstack.SRegion, args *InstanceOperation) error { 57 info, err := cli.GetInstanceConsoleInfo(args.ID) 58 if err != nil { 59 return err 60 } 61 printObject(info) 62 return nil 63 }) 64 65 shellutils.R(&InstanceOperation{}, "instance-start", "Start instance", func(cli *zstack.SRegion, args *InstanceOperation) error { 66 return cli.StartVM(args.ID) 67 }) 68 69 shellutils.R(&InstanceOperation{}, "instance-boot-order", "Show instance boot order", func(cli *zstack.SRegion, args *InstanceOperation) error { 70 fmt.Println(cli.GetBootOrder(args.ID)) 71 return nil 72 }) 73 74 type InstanceStopOption struct { 75 ID string 76 IsForce bool 77 } 78 79 shellutils.R(&InstanceStopOption{}, "instance-stop", "Start instance", func(cli *zstack.SRegion, args *InstanceStopOption) error { 80 return cli.StopVM(args.ID, args.IsForce) 81 }) 82 83 type InstanceSecgroupOption struct { 84 ID string 85 SECGRPID string 86 } 87 88 shellutils.R(&InstanceSecgroupOption{}, "instance-assign-secgroup", "Assign secgroup for a instance", func(cli *zstack.SRegion, args *InstanceSecgroupOption) error { 89 return cli.AssignSecurityGroup(args.ID, args.SECGRPID) 90 }) 91 92 shellutils.R(&InstanceSecgroupOption{}, "instance-revoke-secgroup", "Assign secgroup for a instance", func(cli *zstack.SRegion, args *InstanceSecgroupOption) error { 93 return cli.RevokeSecurityGroup(args.ID, args.SECGRPID) 94 }) 95 96 }