yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/qcloud/shell/eip.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 EipListOptions struct { 24 Eip string `help:"EIP ID"` 25 InstanceId string `help:"Instance Id"` 26 Offset int `help:"List offset"` 27 Limit int `help:"List limit"` 28 } 29 shellutils.R(&EipListOptions{}, "eip-list", "List eips", func(cli *qcloud.SRegion, args *EipListOptions) error { 30 eips, total, err := cli.GetEips(args.Eip, args.InstanceId, args.Offset, args.Limit) 31 if err != nil { 32 return err 33 } 34 printList(eips, total, args.Offset, args.Limit, []string{}) 35 return nil 36 }) 37 38 type EipAllocateOptions struct { 39 BANDWIDTH int `help:"EIP bandwoidth"` 40 NAME string `help:"EIP Name"` 41 ChargeType string `help:"EIP ChargeType" choices:"traffic|bandwidth"` 42 } 43 shellutils.R(&EipAllocateOptions{}, "eip-create", "Allocate an EIP", func(cli *qcloud.SRegion, args *EipAllocateOptions) error { 44 eip, err := cli.AllocateEIP(args.NAME, args.BANDWIDTH, args.ChargeType) 45 if err != nil { 46 return err 47 } 48 printObject(eip) 49 return nil 50 }) 51 52 type EipReleaseOptions struct { 53 ID string `help:"EIP allocation ID"` 54 } 55 shellutils.R(&EipReleaseOptions{}, "eip-delete", "Release an EIP", func(cli *qcloud.SRegion, args *EipReleaseOptions) error { 56 return cli.DeallocateEIP(args.ID) 57 }) 58 59 type EipShowOptions struct { 60 ID string `help:"EIP ID"` 61 } 62 shellutils.R(&EipShowOptions{}, "eip-show", "Show an EIP", func(cli *qcloud.SRegion, args *EipShowOptions) error { 63 eip, err := cli.GetEip(args.ID) 64 if err != nil { 65 return err 66 } 67 printObject(eip) 68 return nil 69 }) 70 71 type EipAssociateOptions struct { 72 ID string `help:"EIP allocation ID"` 73 INSTANCE string `help:"Instance ID"` 74 } 75 shellutils.R(&EipAssociateOptions{}, "eip-associate", "Associate an EIP", func(cli *qcloud.SRegion, args *EipAssociateOptions) error { 76 return cli.AssociateEip(args.ID, args.INSTANCE) 77 }) 78 79 type EipDissociateOptions struct { 80 ID string `help:"EIP allocation ID"` 81 } 82 83 shellutils.R(&EipDissociateOptions{}, "eip-dissociate", "Dissociate an EIP", func(cli *qcloud.SRegion, args *EipDissociateOptions) error { 84 return cli.DissociateEip(args.ID) 85 }) 86 }