yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/aliyun/shell/cloud_enterprise_network.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  // Copyright 2019 Yunion
    16  //
    17  // Licensed under the Apache License, Version 2.0 (the "License");
    18  // you may not use this file except in compliance with the License.
    19  // You may obtain a copy of the License at
    20  //
    21  //     http://www.apache.org/licenses/LICENSE-2.0
    22  //
    23  // Unless required by applicable law or agreed to in writing, software
    24  // distributed under the License is distributed on an "AS IS" BASIS,
    25  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    26  // See the License for the specific language governing permissions and
    27  // PageSizeations under the License.
    28  
    29  package shell
    30  
    31  import (
    32  	"yunion.io/x/cloudmux/pkg/cloudprovider"
    33  	"yunion.io/x/cloudmux/pkg/multicloud/aliyun"
    34  	"yunion.io/x/onecloud/pkg/util/shellutils"
    35  )
    36  
    37  func init() {
    38  	type CenListOptions struct {
    39  		PageSize   int `help:"page size"`
    40  		PageNumber int `help:"page PageNumber"`
    41  	}
    42  	shellutils.R(&CenListOptions{}, "cen-list", "List cloud enterprise network", func(cli *aliyun.SRegion, args *CenListOptions) error {
    43  		scens, e := cli.GetClient().DescribeCens(args.PageNumber, args.PageSize)
    44  		if e != nil {
    45  			return e
    46  		}
    47  		printList(scens.Cens.Cen, scens.TotalCount, args.PageNumber, args.PageSize, []string{})
    48  		return nil
    49  	})
    50  
    51  	type CenChildListOptions struct {
    52  		ID         string `help:"cen id"`
    53  		PageSize   int    `help:"page size"`
    54  		PageNumber int    `help:"page PageNumber"`
    55  	}
    56  	shellutils.R(&CenChildListOptions{}, "cen-child-list", "List cloud enterprise network childs", func(cli *aliyun.SRegion, args *CenChildListOptions) error {
    57  		schilds, e := cli.GetClient().DescribeCenAttachedChildInstances(args.ID, args.PageNumber, args.PageSize)
    58  		if e != nil {
    59  			return e
    60  		}
    61  		printList(schilds.ChildInstances.ChildInstance, schilds.TotalCount, args.PageNumber, args.PageSize, []string{})
    62  		return nil
    63  	})
    64  
    65  	type CenCreateOptions struct {
    66  		Name        string
    67  		Description string
    68  	}
    69  	shellutils.R(&CenCreateOptions{}, "cen-create", "Create cloud enterprise network", func(cli *aliyun.SRegion, args *CenCreateOptions) error {
    70  		opts := cloudprovider.SInterVpcNetworkCreateOptions{}
    71  		opts.Name = args.Name
    72  		opts.Desc = args.Description
    73  		scen, e := cli.GetClient().CreateCen(&opts)
    74  		if e != nil {
    75  			return e
    76  		}
    77  		print(scen)
    78  		return nil
    79  	})
    80  
    81  	type CenDeleteOptions struct {
    82  		ID string
    83  	}
    84  	shellutils.R(&CenDeleteOptions{}, "cen-delete", "delete cloud enterprise network", func(cli *aliyun.SRegion, args *CenDeleteOptions) error {
    85  		e := cli.GetClient().DeleteCen(args.ID)
    86  		if e != nil {
    87  			return e
    88  		}
    89  		return nil
    90  	})
    91  
    92  	type CenAddVpcOptions struct {
    93  		ID          string
    94  		VpcId       string
    95  		VpcRegionId string
    96  	}
    97  	shellutils.R(&CenAddVpcOptions{}, "cen-add-vpc", "add vpc to cloud enterprise network", func(cli *aliyun.SRegion, args *CenAddVpcOptions) error {
    98  		instance := aliyun.SCenAttachInstanceInput{
    99  			InstanceType:   "VPC",
   100  			InstanceId:     args.VpcId,
   101  			InstanceRegion: args.VpcRegionId,
   102  		}
   103  
   104  		e := cli.GetClient().AttachCenChildInstance(args.ID, instance)
   105  		if e != nil {
   106  			return e
   107  		}
   108  		return nil
   109  	})
   110  
   111  	type CenRemoveVpcOptions struct {
   112  		ID          string
   113  		VpcId       string
   114  		VpcRegionId string
   115  	}
   116  	shellutils.R(&CenRemoveVpcOptions{}, "cen-remove-vpc", "remove vpc to cloud enterprise network", func(cli *aliyun.SRegion, args *CenRemoveVpcOptions) error {
   117  		instance := aliyun.SCenAttachInstanceInput{
   118  			InstanceType:   "VPC",
   119  			InstanceId:     args.VpcId,
   120  			InstanceRegion: args.VpcRegionId,
   121  		}
   122  
   123  		e := cli.GetClient().DetachCenChildInstance(args.ID, instance)
   124  		if e != nil {
   125  			return e
   126  		}
   127  		return nil
   128  	})
   129  }