project_mappings.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. "io/ioutil"
  17. "yunion.io/x/jsonutils"
  18. "yunion.io/x/onecloud/pkg/mcclient/options"
  19. )
  20. type ProjectMappingListOptions struct {
  21. options.BaseListOptions
  22. }
  23. func (opts *ProjectMappingListOptions) Params() (jsonutils.JSONObject, error) {
  24. return options.ListStructToParams(opts)
  25. }
  26. type ProjectMappingCreateOption struct {
  27. options.BaseCreateOptions
  28. RULES_FILE string
  29. }
  30. func (opts *ProjectMappingCreateOption) Params() (jsonutils.JSONObject, error) {
  31. ret := jsonutils.NewDict()
  32. ret.Update(jsonutils.Marshal(opts.BaseCreateOptions))
  33. data, err := ioutil.ReadFile(opts.RULES_FILE)
  34. if err != nil {
  35. return nil, err
  36. }
  37. rules, err := jsonutils.Parse(data)
  38. if err != nil {
  39. return nil, err
  40. }
  41. ret.Add(rules, "rules")
  42. return ret, nil
  43. }
  44. type ProjectMappingUpdateOption struct {
  45. options.BaseUpdateOptions
  46. RulesFile string
  47. }
  48. func (opts *ProjectMappingUpdateOption) Params() (jsonutils.JSONObject, error) {
  49. ret := jsonutils.NewDict()
  50. ret.Update(jsonutils.Marshal(opts.BaseUpdateOptions))
  51. if len(opts.RulesFile) > 0 {
  52. data, err := ioutil.ReadFile(opts.RulesFile)
  53. if err != nil {
  54. return nil, err
  55. }
  56. rules, err := jsonutils.Parse(data)
  57. if err != nil {
  58. return nil, err
  59. }
  60. ret.Add(rules, "rules")
  61. }
  62. return ret, nil
  63. }