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