elasticache.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. "fmt"
  17. "strings"
  18. "yunion.io/x/jsonutils"
  19. "yunion.io/x/onecloud/pkg/mcclient/options"
  20. )
  21. type ElasticCacheListOptions struct {
  22. options.BaseListOptions
  23. SecgroupId string
  24. }
  25. func (opts *ElasticCacheListOptions) Params() (jsonutils.JSONObject, error) {
  26. return options.ListStructToParams(opts)
  27. }
  28. type ElasticCacheIdOption struct {
  29. ID string `help:"Elasticache Id"`
  30. }
  31. func (opts *ElasticCacheIdOption) GetId() string {
  32. return opts.ID
  33. }
  34. func (opts *ElasticCacheIdOption) Params() (jsonutils.JSONObject, error) {
  35. return nil, nil
  36. }
  37. type ElasticCacheCreateOptions struct {
  38. NAME string
  39. Manager string
  40. Cloudregion string
  41. Zone string
  42. VpcId string
  43. Network string `help:"network id"`
  44. SecurityGroup string `help:"elastic cache security group. required by huawei."`
  45. SecgroupIds []string `help:"elastic cache security group. required by qcloud."`
  46. Engine string `choices:"redis"`
  47. EngineVersion string `choices:"2.8|3.0|3.2|4.0|5.0"`
  48. PrivateIP string `help:"private ip address in specificated network"`
  49. Password string `help:"set auth password"`
  50. InstanceType string
  51. CapacityMB string `help:"elastic cache capacity. required by huawei."`
  52. BillingType string `choices:"postpaid|prepaid" default:"postpaid"`
  53. Month int `help:"billing duration (unit:month)"`
  54. Tags []string `help:"Tags info,prefix with 'user:', eg: user:project=default" json:"-"`
  55. }
  56. func (opts *ElasticCacheCreateOptions) Params() (jsonutils.JSONObject, error) {
  57. params, err := options.StructToParams(opts)
  58. if err != nil {
  59. return nil, err
  60. }
  61. Tagparams := jsonutils.NewDict()
  62. for _, tag := range opts.Tags {
  63. info := strings.Split(tag, "=")
  64. if len(info) == 2 {
  65. if len(info[0]) == 0 {
  66. return nil, fmt.Errorf("invalidate tag info %s", tag)
  67. }
  68. Tagparams.Add(jsonutils.NewString(info[1]), info[0])
  69. } else if len(info) == 1 {
  70. Tagparams.Add(jsonutils.NewString(info[0]), info[0])
  71. } else {
  72. return nil, fmt.Errorf("invalidate tag info %s", tag)
  73. }
  74. }
  75. if len(opts.SecgroupIds) > 0 {
  76. params.Set("secgroup_ids", jsonutils.NewStringArray(opts.SecgroupIds))
  77. }
  78. params.Add(Tagparams, "__meta__")
  79. return params, nil
  80. }
  81. type ElasticCacheChangeSpecOptions struct {
  82. ElasticCacheIdOption
  83. Sku string `help:"elastic cache sku id"`
  84. }
  85. func (opts *ElasticCacheChangeSpecOptions) Params() (jsonutils.JSONObject, error) {
  86. return jsonutils.Marshal(map[string]string{"sku": opts.Sku}), nil
  87. }
  88. type ElasticCacheMainteananceTimeOptions struct {
  89. ElasticCacheIdOption
  90. START_TIME string `help:"elastic cache sku maintenance start time,format: HH:mm"`
  91. END_TIME string `help:"elastic cache sku maintenance end time, format: HH:mm"`
  92. }
  93. func (opts *ElasticCacheMainteananceTimeOptions) Params() (jsonutils.JSONObject, error) {
  94. params := jsonutils.NewDict()
  95. start := fmt.Sprintf("%sZ", opts.START_TIME)
  96. end := fmt.Sprintf("%sZ", opts.END_TIME)
  97. params.Set("maintain_start_time", jsonutils.NewString(start))
  98. params.Set("maintain_end_time", jsonutils.NewString(end))
  99. return params, nil
  100. }
  101. type ElasticCacheEnableAuthOptions struct {
  102. ElasticCacheIdOption
  103. }
  104. func (opts *ElasticCacheEnableAuthOptions) Params() (jsonutils.JSONObject, error) {
  105. return jsonutils.Marshal(map[string]string{"auth_mod": "on"}), nil
  106. }
  107. type ElasticCacheDisableAuthOptions struct {
  108. ElasticCacheIdOption
  109. }
  110. func (opts *ElasticCacheDisableAuthOptions) Params() (jsonutils.JSONObject, error) {
  111. return jsonutils.Marshal(map[string]string{"auth_mod": "off"}), nil
  112. }