yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/aws/shell/vpc.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 VpcListOptions struct {
    25  		VpcIds []string
    26  	}
    27  	shellutils.R(&VpcListOptions{}, "vpc-list", "List vpcs", func(cli *aws.SRegion, args *VpcListOptions) error {
    28  		vpcs, err := cli.GetVpcs(args.VpcIds)
    29  		if err != nil {
    30  			return err
    31  		}
    32  		printList(vpcs, 0, 0, 0, []string{})
    33  		return nil
    34  	})
    35  
    36  	type VpcPeeringConnectionListOptions struct {
    37  		VPCID string
    38  	}
    39  	shellutils.R(&VpcPeeringConnectionListOptions{}, "vpc-peering-connection-list", "List vpcPeeringConnections", func(cli *aws.SRegion, args *VpcPeeringConnectionListOptions) error {
    40  		vpcPCs, err := cli.DescribeVpcPeeringConnections(args.VPCID)
    41  		if err != nil {
    42  			return err
    43  		}
    44  		printList(vpcPCs, len(vpcPCs), len(vpcPCs), len(vpcPCs), []string{})
    45  		return nil
    46  	})
    47  
    48  	type VpcPeeringConnectionShowOptions struct {
    49  		ID string
    50  	}
    51  	shellutils.R(&VpcPeeringConnectionShowOptions{}, "vpc-peering-connection-show", "show vpcPeeringConnections", func(cli *aws.SRegion, args *VpcPeeringConnectionShowOptions) error {
    52  		vpcPC, err := cli.GetVpcPeeringConnectionById(args.ID)
    53  		if err != nil {
    54  			return err
    55  		}
    56  		printObject(vpcPC)
    57  		return nil
    58  	})
    59  
    60  	type VpcPeeringConnectionCreateOptions struct {
    61  		NAME          string
    62  		VPCID         string
    63  		PEERVPCID     string
    64  		PEERACCOUNTID string
    65  		PEERREGIONID  string
    66  		Desc          string
    67  	}
    68  	shellutils.R(&VpcPeeringConnectionCreateOptions{}, "vpc-peering-connection-create", "create vpcPeeringConnection", func(cli *aws.SRegion, args *VpcPeeringConnectionCreateOptions) error {
    69  		opts := cloudprovider.VpcPeeringConnectionCreateOptions{}
    70  		opts.Desc = args.Desc
    71  		opts.Name = args.NAME
    72  		opts.PeerAccountId = args.PEERACCOUNTID
    73  		opts.PeerRegionId = args.PEERREGIONID
    74  		opts.PeerVpcId = args.PEERVPCID
    75  
    76  		vpcPC, err := cli.CreateVpcPeeringConnection(args.VPCID, &opts)
    77  		if err != nil {
    78  			return err
    79  		}
    80  		printObject(vpcPC)
    81  		return nil
    82  	})
    83  
    84  	type VpcPeeringConnectionAcceptOptions struct {
    85  		ID string
    86  	}
    87  	shellutils.R(&VpcPeeringConnectionAcceptOptions{}, "vpc-peering-connection-accept", "accept vpcPeeringConnection", func(cli *aws.SRegion, args *VpcPeeringConnectionAcceptOptions) error {
    88  		vpcPC, err := cli.AcceptVpcPeeringConnection(args.ID)
    89  		if err != nil {
    90  			return err
    91  		}
    92  		printObject(vpcPC)
    93  		return nil
    94  	})
    95  
    96  	type VpcPeeringConnectionDeleteOptions struct {
    97  		ID string
    98  	}
    99  	shellutils.R(&VpcPeeringConnectionDeleteOptions{}, "vpc-peering-connection-delete", "delete vpcPeeringConnection", func(cli *aws.SRegion, args *VpcPeeringConnectionDeleteOptions) error {
   100  		err := cli.DeleteVpcPeeringConnection(args.ID)
   101  		if err != nil {
   102  			return err
   103  		}
   104  		return nil
   105  	})
   106  
   107  	type VpcPeeringConnectionRouteDeleteOptions struct {
   108  		ID string
   109  	}
   110  	shellutils.R(&VpcPeeringConnectionAcceptOptions{}, "vpc-peering-connection-route-delete", "delete vpc-peering-connection route", func(cli *aws.SRegion, args *VpcPeeringConnectionAcceptOptions) error {
   111  		err := cli.DeleteVpcPeeringConnectionRoute(args.ID)
   112  		if err != nil {
   113  			printObject(err)
   114  			return err
   115  		}
   116  		return nil
   117  	})
   118  }