yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/apsara/shell/secgroup.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/apsara"
    21  	"yunion.io/x/onecloud/pkg/util/shellutils"
    22  )
    23  
    24  func init() {
    25  	type SecurityGroupListOptions struct {
    26  		VpcId            string   `help:"VPC ID"`
    27  		Name             string   `help:"Secgroup Name"`
    28  		SecurityGroupIds []string `help:"SecurityGroup ids"`
    29  		Limit            int      `help:"page size"`
    30  		Offset           int      `help:"page offset"`
    31  	}
    32  	shellutils.R(&SecurityGroupListOptions{}, "security-group-list", "List security group", func(cli *apsara.SRegion, args *SecurityGroupListOptions) error {
    33  		secgrps, total, e := cli.GetSecurityGroups(args.VpcId, args.Name, args.SecurityGroupIds, args.Offset, args.Limit)
    34  		if e != nil {
    35  			return e
    36  		}
    37  		printList(secgrps, total, args.Offset, args.Limit, []string{})
    38  		return nil
    39  	})
    40  
    41  	type SecurityGroupShowOptions struct {
    42  		ID string `help:"ID or name of security group"`
    43  	}
    44  	shellutils.R(&SecurityGroupShowOptions{}, "security-group-show", "Show details of a security group", func(cli *apsara.SRegion, args *SecurityGroupShowOptions) error {
    45  		secgrp, err := cli.GetSecurityGroupDetails(args.ID)
    46  		if err != nil {
    47  			return err
    48  		}
    49  		printObject(secgrp)
    50  		return nil
    51  	})
    52  
    53  	type SecurityGroupCreateOptions struct {
    54  		NAME  string `help:"SecurityGroup name"`
    55  		VpcId string `help:"VPC ID"`
    56  		Desc  string `help:"SecurityGroup description"`
    57  	}
    58  
    59  	shellutils.R(&SecurityGroupCreateOptions{}, "security-group-create", "Create details of a security group", func(cli *apsara.SRegion, args *SecurityGroupCreateOptions) error {
    60  		secgroupId, err := cli.CreateSecurityGroup(args.VpcId, args.NAME, args.Desc)
    61  		if err != nil {
    62  			return err
    63  		}
    64  		fmt.Printf("secgroupId: %s", secgroupId)
    65  		return nil
    66  	})
    67  
    68  }