yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/hcso/shell/cloudgroup.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  	huawei "yunion.io/x/cloudmux/pkg/multicloud/hcso"
    19  	"yunion.io/x/onecloud/pkg/util/shellutils"
    20  )
    21  
    22  func init() {
    23  	type CloudgroupListOptions struct {
    24  		DomainId string
    25  		Name     string
    26  	}
    27  	shellutils.R(&CloudgroupListOptions{}, "cloud-group-list", "List cloudgroups", func(cli *huawei.SRegion, args *CloudgroupListOptions) error {
    28  		groups, err := cli.GetClient().GetGroups(args.DomainId, args.Name)
    29  		if err != nil {
    30  			return err
    31  		}
    32  		printList(groups, 0, 0, 0, nil)
    33  		return nil
    34  	})
    35  
    36  	type CloudgroupIdOptions struct {
    37  		ID string
    38  	}
    39  
    40  	shellutils.R(&CloudgroupIdOptions{}, "cloud-group-delete", "Delete cloudgroup", func(cli *huawei.SRegion, args *CloudgroupIdOptions) error {
    41  		return cli.GetClient().DeleteGroup(args.ID)
    42  	})
    43  
    44  	type CloudgroupCreateOptions struct {
    45  		NAME string
    46  		Desc string
    47  	}
    48  
    49  	shellutils.R(&CloudgroupCreateOptions{}, "cloud-group-create", "Create cloudgroup", func(cli *huawei.SRegion, args *CloudgroupCreateOptions) error {
    50  		group, err := cli.GetClient().CreateGroup(args.NAME, args.Desc)
    51  		if err != nil {
    52  			return err
    53  		}
    54  		printObject(group)
    55  		return nil
    56  	})
    57  
    58  	type GroupRoleListOptions struct {
    59  		GROUP_ID string
    60  	}
    61  
    62  	shellutils.R(&GroupRoleListOptions{}, "cloud-group-policy-list", "List role", func(cli *huawei.SRegion, args *GroupRoleListOptions) error {
    63  		roles, err := cli.GetClient().GetGroupRoles(args.GROUP_ID)
    64  		if err != nil {
    65  			return err
    66  		}
    67  		printList(roles, 0, 0, 0, nil)
    68  		return nil
    69  	})
    70  
    71  	type GroupRoleOptions struct {
    72  		GROUP_ID string
    73  		ROLE_ID  string
    74  	}
    75  
    76  	shellutils.R(&GroupRoleOptions{}, "cloud-group-detach-policy", "Detach group role", func(cli *huawei.SRegion, args *GroupRoleOptions) error {
    77  		return cli.GetClient().DetachGroupRole(args.GROUP_ID, args.ROLE_ID)
    78  	})
    79  
    80  	shellutils.R(&GroupRoleOptions{}, "cloud-group-attach-policy", "Detach group role", func(cli *huawei.SRegion, args *GroupRoleOptions) error {
    81  		return cli.GetClient().AttachGroupRole(args.GROUP_ID, args.ROLE_ID)
    82  	})
    83  
    84  	type GroupUserListOptions struct {
    85  		GROUP_ID string
    86  	}
    87  
    88  	shellutils.R(&GroupUserListOptions{}, "cloud-group-user-list", "List user", func(cli *huawei.SRegion, args *GroupUserListOptions) error {
    89  		users, err := cli.GetClient().GetGroupUsers(args.GROUP_ID)
    90  		if err != nil {
    91  			return err
    92  		}
    93  		printList(users, 0, 0, 0, nil)
    94  		return nil
    95  	})
    96  
    97  }