cloudproviders.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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/options"
  18. )
  19. type CloudproviderListOptions struct {
  20. options.BaseListOptions
  21. Usable bool `help:"Vpc & Network usable"`
  22. HasObjectStorage bool `help:"filter cloudproviders that has object storage" negative:"no-object-storage"`
  23. Capability []string `help:"capability filter" choices:"project|compute|network|loadbalancer|objectstore|rds|cache|event"`
  24. Cloudregion string `help:"filter cloudproviders by cloudregion"`
  25. ReadOnly *bool `help:"filter read only account" negative:"no-read-only"`
  26. HostSchedtagId string `help:"filter by host schedtag"`
  27. ZoneId string
  28. }
  29. func (opts *CloudproviderListOptions) Params() (jsonutils.JSONObject, error) {
  30. return options.ListStructToParams(opts)
  31. }
  32. type CloudproviderUpdateOptions struct {
  33. options.BaseIdOptions
  34. Name string `help:"New name to update"`
  35. AccessUrl string `help:"New access url"`
  36. Desc string `help:"Description"`
  37. }
  38. func (opts *CloudproviderUpdateOptions) Params() (jsonutils.JSONObject, error) {
  39. params := jsonutils.NewDict()
  40. if len(opts.Name) > 0 {
  41. params.Add(jsonutils.NewString(opts.Name), "name")
  42. }
  43. if len(opts.AccessUrl) > 0 {
  44. params.Add(jsonutils.NewString(opts.AccessUrl), "access_url")
  45. }
  46. if len(opts.Desc) > 0 {
  47. params.Add(jsonutils.NewString(opts.Desc), "description")
  48. }
  49. return params, nil
  50. }
  51. type CloudproviderChangeProjectOptions struct {
  52. options.BaseIdOptions
  53. TENANT string `help:"ID or Name of tenant"`
  54. }
  55. func (opts *CloudproviderChangeProjectOptions) Params() (jsonutils.JSONObject, error) {
  56. return jsonutils.Marshal(map[string]string{"project": opts.TENANT}), nil
  57. }
  58. type CloudproviderSyncOptions struct {
  59. options.BaseIdOptions
  60. Force bool `help:"Force sync no matter what"`
  61. FullSync bool `help:"Synchronize everything"`
  62. ProjectSync bool `help:"Auto sync project info"`
  63. Region []string `help:"region to sync"`
  64. Zone []string `help:"region to sync"`
  65. Host []string `help:"region to sync"`
  66. }
  67. func (opts *CloudproviderSyncOptions) Params() (jsonutils.JSONObject, error) {
  68. params := jsonutils.NewDict()
  69. if opts.Force {
  70. params.Add(jsonutils.JSONTrue, "force")
  71. }
  72. if opts.FullSync {
  73. params.Add(jsonutils.JSONTrue, "full_sync")
  74. }
  75. if opts.ProjectSync {
  76. params.Add(jsonutils.JSONTrue, "project_sync")
  77. }
  78. if len(opts.Region) > 0 {
  79. params.Add(jsonutils.NewStringArray(opts.Region), "region")
  80. }
  81. if len(opts.Zone) > 0 {
  82. params.Add(jsonutils.NewStringArray(opts.Zone), "zone")
  83. }
  84. if len(opts.Host) > 0 {
  85. params.Add(jsonutils.NewStringArray(opts.Host), "host")
  86. }
  87. return params, nil
  88. }
  89. type CloudproviderStorageClassesOptions struct {
  90. options.BaseIdOptions
  91. Cloudregion string `help:"cloud region name or Id"`
  92. }
  93. func (opts *CloudproviderStorageClassesOptions) Params() (jsonutils.JSONObject, error) {
  94. return options.StructToParams(opts)
  95. }
  96. type ClouproviderProjectMappingOptions struct {
  97. options.BaseIdOptions
  98. ProjectMappingId string `json:"project_mapping_id" help:"project mapping id"`
  99. }
  100. func (opts *ClouproviderProjectMappingOptions) Params() (jsonutils.JSONObject, error) {
  101. return jsonutils.Marshal(map[string]string{"project_mapping_id": opts.ProjectMappingId}), nil
  102. }
  103. type ClouproviderSetSyncingOptions struct {
  104. options.BaseIdOptions
  105. Enabled bool `help:"Enable or disable sync"`
  106. CloudregionIds []string `help:"Cloudregion ids for sync"`
  107. }
  108. func (opts *ClouproviderSetSyncingOptions) Params() (jsonutils.JSONObject, error) {
  109. return jsonutils.Marshal(map[string]interface{}{
  110. "enabled": opts.Enabled,
  111. "cloudregion_ids": opts.CloudregionIds,
  112. }), nil
  113. }