yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/aliyun/shell/access_groups.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/aliyun"
    20  	"yunion.io/x/onecloud/pkg/util/shellutils"
    21  )
    22  
    23  func init() {
    24  	type NasAccessGroupListOptions struct {
    25  		FileSystemType string `choices:"standard|extreme" default:"standard"`
    26  	}
    27  	shellutils.R(&NasAccessGroupListOptions{}, "access-group-list", "List Nas AccessGroups", func(cli *aliyun.SRegion, args *NasAccessGroupListOptions) error {
    28  		ags, err := cli.GetAccessGroups(args.FileSystemType)
    29  		if err != nil {
    30  			return err
    31  		}
    32  		printList(ags, 0, 0, 0, []string{})
    33  		return nil
    34  	})
    35  
    36  	shellutils.R(&cloudprovider.SAccessGroup{}, "access-group-create", "Create Nas AccessGroup", func(cli *aliyun.SRegion, args *cloudprovider.SAccessGroup) error {
    37  		return cli.CreateAccessGroup(args)
    38  	})
    39  
    40  	type AccessGroupDeleteOptions struct {
    41  		FileSystemType string
    42  		NAME           string
    43  	}
    44  
    45  	shellutils.R(&AccessGroupDeleteOptions{}, "access-group-delete", "Delete AccessGroup", func(cli *aliyun.SRegion, args *AccessGroupDeleteOptions) error {
    46  		return cli.DeleteAccessGroup(args.FileSystemType, args.NAME)
    47  	})
    48  
    49  	type NasAccessGroupRuleListOptions struct {
    50  		GROUP    string
    51  		PageSize int `help:"page size"`
    52  		PageNum  int `help:"page num"`
    53  	}
    54  
    55  	shellutils.R(&NasAccessGroupRuleListOptions{}, "access-group-rule-list", "List Nas AccessGroup Rules", func(cli *aliyun.SRegion, args *NasAccessGroupRuleListOptions) error {
    56  		rules, _, err := cli.GetAccessGroupRules(args.GROUP, args.PageSize, args.PageNum)
    57  		if err != nil {
    58  			return err
    59  		}
    60  		printList(rules, 0, 0, 0, []string{})
    61  		return nil
    62  	})
    63  
    64  	type AccessRuleDeleteOptions struct {
    65  		FileSystemType string
    66  		GROUP          string
    67  		RULE_ID        string
    68  	}
    69  
    70  	shellutils.R(&AccessRuleDeleteOptions{}, "access-group-rule-delete", "Delete AccessGroup Rule", func(cli *aliyun.SRegion, args *AccessRuleDeleteOptions) error {
    71  		return cli.DeleteAccessGroupRule(args.FileSystemType, args.GROUP, args.RULE_ID)
    72  	})
    73  
    74  	type AccessRuleCreateOptions struct {
    75  		SOURCE         string
    76  		FileSystemType string
    77  		GroupName      string
    78  		RwType         cloudprovider.TRWAccessType
    79  		UserType       cloudprovider.TUserAccessType
    80  		Priority       int
    81  	}
    82  
    83  	shellutils.R(&AccessRuleCreateOptions{}, "access-group-rule-create", "Delete AccessGroup Rule", func(cli *aliyun.SRegion, args *AccessRuleCreateOptions) error {
    84  		return cli.CreateAccessGroupRule(args.SOURCE, args.FileSystemType, args.GroupName, args.RwType, args.UserType, args.Priority)
    85  	})
    86  
    87  }