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