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