instancegroup.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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/pkg/errors"
  18. api "yunion.io/x/onecloud/pkg/apis/compute"
  19. "yunion.io/x/onecloud/pkg/mcclient/options"
  20. )
  21. type InstanceGroupListOptions struct {
  22. options.BaseListOptions
  23. ServiceType string `help:"Service Type"`
  24. ParentId string `help:"Parent ID"`
  25. ZoneId string `help:"Zone ID"`
  26. Server string `help:"Guest ID or Name"`
  27. OrderByVips string
  28. OrderByGuestCount string
  29. }
  30. func (opts *InstanceGroupListOptions) Params() (jsonutils.JSONObject, error) {
  31. params, err := options.ListStructToParams(opts)
  32. if err != nil {
  33. return nil, err
  34. }
  35. return params, nil
  36. }
  37. type InstanceGroupCreateOptions struct {
  38. NAME string `help:"name of instance group"`
  39. ZoneId string `help:"zone id" json:"zone_id"`
  40. ServiceType string `help:"service type"`
  41. ParentId string `help:"parent id"`
  42. SchedStrategy string `help:"scheduler strategy"`
  43. Granularity string `help:"the upper limit number of guests with this group in a host"`
  44. ForceDispersion bool `help:"force to make guest dispersion"`
  45. }
  46. func (opts *InstanceGroupCreateOptions) Params() (jsonutils.JSONObject, error) {
  47. params, err := options.StructToParams(opts)
  48. if err != nil {
  49. return nil, errors.Wrap(err, "StructToParams")
  50. }
  51. return params, nil
  52. }
  53. type InstanceGroupUpdateOptions struct {
  54. options.BaseIdOptions
  55. Name string `help:"New name to change"`
  56. Granularity string `help:"the upper limit number of guests with this group in a host"`
  57. ForceDispersion string `help:"force to make guest dispersion" choices:"yes|no" json:"-"`
  58. }
  59. func (opts *InstanceGroupUpdateOptions) Params() (jsonutils.JSONObject, error) {
  60. params, err := options.StructToParams(opts)
  61. if err != nil {
  62. return nil, errors.Wrap(err, "StructToParams")
  63. }
  64. if opts.ForceDispersion == "yes" {
  65. params.Set("force_dispersion", jsonutils.JSONTrue)
  66. } else {
  67. params.Set("force_dispersion", jsonutils.JSONFalse)
  68. }
  69. return params, nil
  70. }
  71. type InstanceGroupBindGuestsOptions struct {
  72. options.BaseIdOptions
  73. Guest []string `help:"ID or Name of Guest"`
  74. }
  75. func (opts *InstanceGroupBindGuestsOptions) Params() (jsonutils.JSONObject, error) {
  76. return options.StructToParams(opts)
  77. }
  78. type InstanceGroupAttachnetworkOptions struct {
  79. options.BaseIdOptions
  80. api.GroupAttachNetworkInput
  81. }
  82. func (opts *InstanceGroupAttachnetworkOptions) Params() (jsonutils.JSONObject, error) {
  83. return jsonutils.Marshal(opts), nil
  84. }
  85. type InstanceGroupDetachnetworkOptions struct {
  86. options.BaseIdOptions
  87. api.GroupDetachNetworkInput
  88. }
  89. func (opts *InstanceGroupDetachnetworkOptions) Params() (jsonutils.JSONObject, error) {
  90. return jsonutils.Marshal(opts), nil
  91. }
  92. type InstanceGroupCreateEipOptions struct {
  93. options.BaseIdOptions
  94. api.ServerCreateEipInput
  95. }
  96. func (opts *InstanceGroupCreateEipOptions) Params() (jsonutils.JSONObject, error) {
  97. return jsonutils.Marshal(opts), nil
  98. }
  99. type InstanceGroupAssociateEipOptions struct {
  100. options.BaseIdOptions
  101. api.ServerAssociateEipInput
  102. }
  103. func (opts *InstanceGroupAssociateEipOptions) Params() (jsonutils.JSONObject, error) {
  104. return jsonutils.Marshal(opts), nil
  105. }
  106. type InstanceGroupDissociateEipOptions struct {
  107. options.BaseIdOptions
  108. api.ServerDissociateEipInput
  109. }
  110. func (opts *InstanceGroupDissociateEipOptions) Params() (jsonutils.JSONObject, error) {
  111. return jsonutils.Marshal(opts), nil
  112. }