yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/qcloud/shell/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  package shell
    16  
    17  import (
    18  	"fmt"
    19  
    20  	"yunion.io/x/cloudmux/pkg/multicloud/qcloud"
    21  	"yunion.io/x/onecloud/pkg/util/shellutils"
    22  )
    23  
    24  func init() {
    25  	type NetworkListOptions struct {
    26  		Limit  int `help:"page size"`
    27  		Offset int `help:"page offset"`
    28  	}
    29  	shellutils.R(&NetworkListOptions{}, "network-list", "List networks", func(cli *qcloud.SRegion, args *NetworkListOptions) error {
    30  		networks, total, e := cli.GetNetworks(nil, "", args.Offset, args.Limit)
    31  		if e != nil {
    32  			return e
    33  		}
    34  		printList(networks, total, args.Offset, args.Limit, []string{})
    35  		return nil
    36  	})
    37  
    38  	type NetworkOptions struct {
    39  		ID string `help:"Network ID"`
    40  	}
    41  	shellutils.R(&NetworkOptions{}, "network-delete", "Delete network", func(cli *qcloud.SRegion, args *NetworkOptions) error {
    42  		return cli.DeleteNetwork(args.ID)
    43  	})
    44  
    45  	shellutils.R(&NetworkOptions{}, "network-show", "Show network", func(cli *qcloud.SRegion, args *NetworkOptions) error {
    46  		network, err := cli.GetNetwork(args.ID)
    47  		if err != nil {
    48  			return err
    49  		}
    50  		printObject(network)
    51  		return nil
    52  	})
    53  
    54  	type NetworkCreateOptions struct {
    55  		ZONE string `help:"Zone ID"`
    56  		VPC  string `help:"VPC ID"`
    57  		CIDR string `help:"Network CIDR"`
    58  		NAME string `help:"Network Name"`
    59  	}
    60  	shellutils.R(&NetworkCreateOptions{}, "network-create", "Create network", func(cli *qcloud.SRegion, args *NetworkCreateOptions) error {
    61  		networkId, err := cli.CreateNetwork(args.ZONE, args.VPC, args.NAME, args.CIDR, "")
    62  		if err != nil {
    63  			return err
    64  		}
    65  		fmt.Println(networkId)
    66  		return nil
    67  	})
    68  }