yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/hcs/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/hcs" 19 "yunion.io/x/onecloud/pkg/util/shellutils" 20 ) 21 22 func init() { 23 type EipListOptions struct { 24 PortId string 25 Address []string 26 } 27 shellutils.R(&EipListOptions{}, "eip-list", "List eips", func(cli *hcs.SRegion, args *EipListOptions) error { 28 eips, err := cli.GetEips(args.PortId, args.Address) 29 if err != nil { 30 return nil 31 } 32 printList(eips, 0, 0, 0, nil) 33 return nil 34 }) 35 36 type EipTypeListOptions struct { 37 } 38 39 shellutils.R(&EipTypeListOptions{}, "eip-type-list", "List eip types", func(cli *hcs.SRegion, args *EipTypeListOptions) error { 40 types, err := cli.GetEipTypes() 41 if err != nil { 42 return nil 43 } 44 printList(types, 0, 0, 0, nil) 45 return nil 46 }) 47 48 type EipAllocateOptions struct { 49 NAME string `help:"eip name"` 50 BW int `help:"Bandwidth limit in Mbps"` 51 BGP string `help:"bgp type"` 52 ChargeType string `help:"eip charge type" default:"traffic" choices:"traffic|bandwidth"` 53 ProjectId string 54 } 55 shellutils.R(&EipAllocateOptions{}, "eip-create", "Allocate an EIP", func(cli *hcs.SRegion, args *EipAllocateOptions) error { 56 eip, err := cli.AllocateEIP(args.NAME, args.BW, hcs.TInternetChargeType(args.ChargeType), args.BGP, args.ProjectId) 57 if err != nil { 58 return err 59 } 60 printObject(eip) 61 return nil 62 }) 63 64 type EipReleaseOptions struct { 65 ID string `help:"EIP allocation ID"` 66 } 67 shellutils.R(&EipReleaseOptions{}, "eip-delete", "Release an EIP", func(cli *hcs.SRegion, args *EipReleaseOptions) error { 68 err := cli.DeallocateEIP(args.ID) 69 return err 70 }) 71 72 type EipAssociateOptions struct { 73 ID string `help:"EIP allocation ID"` 74 INSTANCE string `help:"Instance ID"` 75 } 76 shellutils.R(&EipAssociateOptions{}, "eip-associate", "Associate an EIP", func(cli *hcs.SRegion, args *EipAssociateOptions) error { 77 return cli.AssociateEip(args.ID, args.INSTANCE) 78 }) 79 80 type EipDissociateOptions struct { 81 ID string `help:"EIP allocation ID"` 82 } 83 84 shellutils.R(&EipDissociateOptions{}, "eip-dissociate", "Dissociate an EIP", func(cli *hcs.SRegion, args *EipDissociateOptions) error { 85 return cli.DissociateEip(args.ID) 86 }) 87 88 }