policy_assignment.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. package compute
  15. import (
  16. "yunion.io/x/jsonutils"
  17. "yunion.io/x/onecloud/pkg/mcclient"
  18. modules "yunion.io/x/onecloud/pkg/mcclient/modules/compute"
  19. "yunion.io/x/onecloud/pkg/mcclient/options"
  20. )
  21. func init() {
  22. type PolicyListOptions struct {
  23. options.BaseListOptions
  24. Policydefinition string `help:"filter by policydefinition"`
  25. }
  26. R(&PolicyListOptions{}, "policy-assignment-list", "List policy assignments", func(s *mcclient.ClientSession, args *PolicyListOptions) error {
  27. params, err := args.Params()
  28. if err != nil {
  29. return err
  30. }
  31. if len(args.Policydefinition) > 0 {
  32. params.Add(jsonutils.NewString(args.Policydefinition), "policydefinition")
  33. }
  34. result, err := modules.PolicyAssignment.List(s, params)
  35. if err != nil {
  36. return err
  37. }
  38. printList(result, modules.PolicyAssignment.GetColumns(s))
  39. return nil
  40. })
  41. type PolicyIdOptions struct {
  42. ID string `help:"policy assignment id or name"`
  43. }
  44. R(&PolicyIdOptions{}, "policy-assignment-show", "Show policy assignment details", func(s *mcclient.ClientSession, args *PolicyIdOptions) error {
  45. result, err := modules.PolicyAssignment.Get(s, args.ID, nil)
  46. if err != nil {
  47. return err
  48. }
  49. printObject(result)
  50. return nil
  51. })
  52. }