yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/aliyun/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/aliyun" 19 "yunion.io/x/onecloud/pkg/util/shellutils" 20 ) 21 22 func init() { 23 type EipListOptions struct { 24 Id string `help:"Eip id"` 25 AssociateId string `help:"Id of associate resource"` 26 Addr string `help:"Eip "` 27 Offset int `help:"List offset"` 28 Limit int `help:"List limit"` 29 } 30 shellutils.R(&EipListOptions{}, "eip-list", "List eips", func(cli *aliyun.SRegion, args *EipListOptions) error { 31 eips, total, e := cli.GetEips(args.Id, args.AssociateId, args.Addr, args.Offset, args.Limit) 32 if e != nil { 33 return e 34 } 35 printList(eips, total, args.Offset, args.Limit, []string{}) 36 return nil 37 }) 38 39 type EipAllocateOptions struct { 40 Name string 41 BW int `help:"Bandwidth limit in Mbps"` 42 ResourceGroupId string `help:"Resource group Id"` 43 } 44 shellutils.R(&EipAllocateOptions{}, "eip-create", "Allocate an EIP", func(cli *aliyun.SRegion, args *EipAllocateOptions) error { 45 eip, err := cli.AllocateEIP(args.Name, args.BW, aliyun.InternetChargeByTraffic, args.ResourceGroupId) 46 if err != nil { 47 return err 48 } 49 printObject(eip) 50 return nil 51 }) 52 53 type EipReleaseOptions struct { 54 ID string `help:"EIP allocation ID"` 55 } 56 shellutils.R(&EipReleaseOptions{}, "eip-delete", "Release an EIP", func(cli *aliyun.SRegion, args *EipReleaseOptions) error { 57 err := cli.DeallocateEIP(args.ID) 58 return err 59 }) 60 61 type EipAssociateOptions struct { 62 ID string `help:"EIP allocation ID"` 63 INSTANCE string `help:"Instance ID"` 64 } 65 shellutils.R(&EipAssociateOptions{}, "eip-associate", "Associate an EIP", func(cli *aliyun.SRegion, args *EipAssociateOptions) error { 66 err := cli.AssociateEip(args.ID, args.INSTANCE) 67 return err 68 }) 69 shellutils.R(&EipAssociateOptions{}, "eip-dissociate", "Dissociate an EIP", func(cli *aliyun.SRegion, args *EipAssociateOptions) error { 70 err := cli.DissociateEip(args.ID, args.INSTANCE) 71 return err 72 }) 73 }