zone.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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 ZoneListOptions struct {
  20. options.BaseListOptions
  21. Region string `help:"cloud region ID or Name"`
  22. City string `help:"Filter zone by city of cloudregions"`
  23. Usable *bool `help:"List all zones where networks are usable"`
  24. UsableVpc *bool `help:"List all zones where vpc are usable"`
  25. OrderByWires string
  26. OrderByHosts string
  27. OrderByHostsEnabled string
  28. OrderByBaremetals string
  29. OrderByBaremetalsEnabled string
  30. }
  31. func (opts *ZoneListOptions) Params() (jsonutils.JSONObject, error) {
  32. return options.ListStructToParams(opts)
  33. }
  34. type ZoneIdOptions struct {
  35. ID string `help:"ID or Name of zone to update"`
  36. }
  37. func (opts *ZoneIdOptions) GetId() string {
  38. return opts.ID
  39. }
  40. func (opts *ZoneIdOptions) Params() (jsonutils.JSONObject, error) {
  41. return jsonutils.NewDict(), nil
  42. }
  43. type ZoneUpdateOptions struct {
  44. ZoneIdOptions
  45. Name string `help:"Name of zone"`
  46. NameCN string `help:"Name in Chinese"`
  47. Desc string `metavar:"<DESCRIPTION>" help:"Description"`
  48. Location string `help:"Location"`
  49. }
  50. func (opts *ZoneUpdateOptions) Params() (jsonutils.JSONObject, error) {
  51. params := jsonutils.NewDict()
  52. if len(opts.Name) > 0 {
  53. params.Add(jsonutils.NewString(opts.Name), "name")
  54. }
  55. if len(opts.NameCN) > 0 {
  56. params.Add(jsonutils.NewString(opts.NameCN), "name_cn")
  57. }
  58. if len(opts.Desc) > 0 {
  59. params.Add(jsonutils.NewString(opts.Desc), "description")
  60. }
  61. if len(opts.Location) > 0 {
  62. params.Add(jsonutils.NewString(opts.Location), "location")
  63. }
  64. return params, nil
  65. }
  66. type ZoneCapabilityOptions struct {
  67. ZoneIdOptions
  68. Domain string
  69. }
  70. func (opts *ZoneCapabilityOptions) Params() (jsonutils.JSONObject, error) {
  71. ret := jsonutils.NewDict()
  72. if len(opts.Domain) > 0 {
  73. ret.Add(jsonutils.NewString(opts.Domain), "domain")
  74. }
  75. return ret, nil
  76. }
  77. type ZoneCreateOptions struct {
  78. NAME string `help:"Name of zone"`
  79. NameCN string `help:"Name in Chinese"`
  80. Desc string `metavar:"<DESCRIPTION>" help:"Description"`
  81. Location string `help:"Location"`
  82. Region string `help:"Cloudregion in which zone created"`
  83. }
  84. func (opts *ZoneCreateOptions) Params() (jsonutils.JSONObject, error) {
  85. params := jsonutils.NewDict()
  86. params.Add(jsonutils.NewString(opts.NAME), "name")
  87. if len(opts.NameCN) > 0 {
  88. params.Add(jsonutils.NewString(opts.NameCN), "name_cn")
  89. }
  90. if len(opts.Desc) > 0 {
  91. params.Add(jsonutils.NewString(opts.Desc), "description")
  92. }
  93. if len(opts.Location) > 0 {
  94. params.Add(jsonutils.NewString(opts.Location), "location")
  95. }
  96. if len(opts.Region) > 0 {
  97. params.Add(jsonutils.NewString(opts.Region), "region")
  98. }
  99. return params, nil
  100. }
  101. type ZoneStatusOptions struct {
  102. ZoneIdOptions
  103. STATUS string `help:"zone status" choices:"enable|disable|soldout"`
  104. REASON string `help:"why update status"`
  105. }
  106. func (opts *ZoneStatusOptions) Params() (jsonutils.JSONObject, error) {
  107. params := jsonutils.NewDict()
  108. params.Set("status", jsonutils.NewString(opts.STATUS))
  109. params.Set("reason", jsonutils.NewString(opts.REASON))
  110. return params, nil
  111. }
  112. type ZonePurgeOptions struct {
  113. ZoneIdOptions
  114. MANAGER_ID string
  115. }
  116. func (opts *ZonePurgeOptions) Params() (jsonutils.JSONObject, error) {
  117. params := jsonutils.NewDict()
  118. params.Set("manager_id", jsonutils.NewString(opts.MANAGER_ID))
  119. return params, nil
  120. }