cloudgroup.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 cloudid
  15. import (
  16. "yunion.io/x/jsonutils"
  17. "yunion.io/x/onecloud/pkg/mcclient/options"
  18. )
  19. type CloudgroupListOptions struct {
  20. options.BaseListOptions
  21. ClouduserId string `json:"clouduser_id"`
  22. CloudpolicyId string `json:"cloudpolicy_id"`
  23. Usable bool `json:"usable"`
  24. }
  25. func (opts *CloudgroupListOptions) Params() (jsonutils.JSONObject, error) {
  26. return options.ListStructToParams(opts)
  27. }
  28. type CloudgroupCreateOptions struct {
  29. NAME string `json:"name"`
  30. MANAGER_ID string
  31. CloudpolicyIds []string `json:"cloudpolicy_ids"`
  32. Desc string `json:"description"`
  33. }
  34. func (opts *CloudgroupCreateOptions) Params() (jsonutils.JSONObject, error) {
  35. return jsonutils.Marshal(opts), nil
  36. }
  37. type CloudgroupIdOptions struct {
  38. ID string `help:"Cloudgroup Id"`
  39. }
  40. func (opts *CloudgroupIdOptions) GetId() string {
  41. return opts.ID
  42. }
  43. func (opts *CloudgroupIdOptions) Params() (jsonutils.JSONObject, error) {
  44. return nil, nil
  45. }
  46. type CloudgroupPolicyOptions struct {
  47. CloudgroupIdOptions
  48. CLOUDPOLICY_ID string `help:"Cloudpolicy Id"`
  49. }
  50. func (opts *CloudgroupPolicyOptions) Params() (jsonutils.JSONObject, error) {
  51. return jsonutils.Marshal(map[string]string{"cloudpolicy_id": opts.CLOUDPOLICY_ID}), nil
  52. }
  53. type CloudgroupUserOptions struct {
  54. CloudgroupIdOptions
  55. CLOUDUSER_ID string `help:"Clouduser Id"`
  56. }
  57. func (opts *CloudgroupUserOptions) Params() (jsonutils.JSONObject, error) {
  58. return jsonutils.Marshal(map[string]string{"clouduser_id": opts.CLOUDUSER_ID}), nil
  59. }
  60. type CloudgroupPoliciesOptions struct {
  61. CloudgroupIdOptions
  62. CloudpolicyIds []string `json:"cloudpolicy_ids"`
  63. }
  64. func (opts *CloudgroupPoliciesOptions) Params() (jsonutils.JSONObject, error) {
  65. return jsonutils.Marshal(map[string][]string{"cloudpolicy_ids": opts.CloudpolicyIds}), nil
  66. }
  67. type CloudgroupUsersOptions struct {
  68. CloudgroupIdOptions
  69. ClouduserIds []string `json:"clouduser_ids"`
  70. }
  71. func (opts *CloudgroupUsersOptions) Params() (jsonutils.JSONObject, error) {
  72. return jsonutils.Marshal(map[string][]string{"clouduser_ids": opts.ClouduserIds}), nil
  73. }
  74. type CloudgroupPublicOptions struct {
  75. CloudgroupIdOptions
  76. Scope string `help:"sharing scope" choices:"system|domain"`
  77. SharedDomains []string `help:"share to domains"`
  78. }
  79. func (opts *CloudgroupPublicOptions) Params() (jsonutils.JSONObject, error) {
  80. params := jsonutils.NewDict()
  81. if len(opts.Scope) > 0 {
  82. params.Add(jsonutils.NewString(opts.Scope), "scope")
  83. }
  84. if len(opts.SharedDomains) > 0 {
  85. params.Add(jsonutils.Marshal(opts.SharedDomains), "shared_domains")
  86. }
  87. return params, nil
  88. }