yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/apsara/shell/ram_policy.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/multicloud/apsara" 19 "yunion.io/x/onecloud/pkg/util/shellutils" 20 ) 21 22 func init() { 23 type GetPolicyOptions struct { 24 POLICYTYPE string 25 POLICYNAME string 26 } 27 shellutils.R(&GetPolicyOptions{}, "cloud-policy-show", "Show ram policy", func(cli *apsara.SRegion, args *GetPolicyOptions) error { 28 policy, err := cli.GetClient().GetPolicy(args.POLICYTYPE, args.POLICYNAME) 29 if err != nil { 30 return err 31 } 32 printObject(policy) 33 return nil 34 }) 35 36 type DeletePolicyOptions struct { 37 POLICYTYPE string 38 POLICYNAME string 39 } 40 shellutils.R(&DeletePolicyOptions{}, "cloud-policy-delete", "Delete policy", func(cli *apsara.SRegion, args *DeletePolicyOptions) error { 41 return cli.GetClient().DeletePolicy(args.POLICYTYPE, args.POLICYNAME) 42 }) 43 44 type PolicyListOptions struct { 45 PolicyType string `choices:"System|Custom"` 46 Offset string 47 Limit int 48 } 49 50 shellutils.R(&PolicyListOptions{}, "cloud-policy-list", "List cloud policies", func(cli *apsara.SRegion, args *PolicyListOptions) error { 51 policies, err := cli.GetClient().ListPolicies(args.PolicyType, args.Offset, args.Limit) 52 if err != nil { 53 return err 54 } 55 printList(policies.Policies.Policy, 0, 0, 0, nil) 56 return nil 57 }) 58 59 type PolicyCreateOptions struct { 60 NAME string 61 DOCUMENT string 62 Desc string 63 } 64 65 shellutils.R(&PolicyCreateOptions{}, "cloud-policy-create", "Create ram policy", func(cli *apsara.SRegion, args *PolicyCreateOptions) error { 66 policy, err := cli.GetClient().CreatePolicy(args.NAME, args.DOCUMENT, args.Desc) 67 if err != nil { 68 return err 69 } 70 printObject(policy) 71 return nil 72 }) 73 74 type PolicyCreateVersionOptions struct { 75 NAME string 76 DOCUMENT string 77 IsDefault bool 78 } 79 80 shellutils.R(&PolicyCreateVersionOptions{}, "cloud-policy-version-create", "Create ram policy version", func(cli *apsara.SRegion, args *PolicyCreateVersionOptions) error { 81 return cli.GetClient().CreatePolicyVersion(args.NAME, args.DOCUMENT, args.IsDefault) 82 }) 83 84 }