yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/aliyun/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/aliyun" 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 *aliyun.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 SecurityGroupIdOptions struct { 42 ID string `help:"ID or name of security group"` 43 } 44 shellutils.R(&SecurityGroupIdOptions{}, "security-group-show", "Show details of a security group", func(cli *aliyun.SRegion, args *SecurityGroupIdOptions) 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 shellutils.R(&SecurityGroupIdOptions{}, "security-group-references", "Show references of a security group", func(cli *aliyun.SRegion, args *SecurityGroupIdOptions) error { 54 references, err := cli.DescribeSecurityGroupReferences(args.ID) 55 if err != nil { 56 return err 57 } 58 printList(references, 0, 0, 0, nil) 59 return nil 60 }) 61 62 type SecurityGroupCreateOptions struct { 63 NAME string `help:"SecurityGroup name"` 64 VpcId string `help:"VPC ID"` 65 Desc string `help:"SecurityGroup description"` 66 } 67 68 shellutils.R(&SecurityGroupCreateOptions{}, "security-group-create", "Create details of a security group", func(cli *aliyun.SRegion, args *SecurityGroupCreateOptions) error { 69 secgroupId, err := cli.CreateSecurityGroup(args.VpcId, args.NAME, args.Desc) 70 if err != nil { 71 return err 72 } 73 fmt.Printf("secgroupId: %s", secgroupId) 74 return nil 75 }) 76 77 }