yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/hcso/client/modules/mod_elasticcache.go (about) 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 15 package modules 16 17 import ( 18 "fmt" 19 20 "yunion.io/x/jsonutils" 21 22 "yunion.io/x/cloudmux/pkg/multicloud/hcso/client/manager" 23 "yunion.io/x/cloudmux/pkg/multicloud/hcso/client/responses" 24 ) 25 26 type SElasticcacheManager struct { 27 SResourceManager 28 } 29 30 type SDcsAvailableZoneManager struct { 31 SResourceManager 32 } 33 34 func NewElasticcacheManager(cfg manager.IManagerConfig) *SElasticcacheManager { 35 return &SElasticcacheManager{SResourceManager: SResourceManager{ 36 SBaseManager: NewBaseManager(cfg), 37 ServiceName: ServiceNameDCS, 38 Region: cfg.GetRegionId(), 39 ProjectId: cfg.GetProjectId(), 40 version: "v1.0", 41 Keyword: "", 42 KeywordPlural: "instances", 43 44 ResourceKeyword: "instances", 45 }} 46 } 47 48 // https://support.huaweicloud.com/api-dcs/dcs-zh-api-180423035.html 49 func (self *SElasticcacheManager) ListBackups(queries map[string]string) (*responses.ListResult, error) { 50 var spec string 51 if id, _ := queries["instance_id"]; len(id) == 0 { 52 return nil, fmt.Errorf("SElasticcacheManager.ListBackups missing parameter instance_id") 53 } else { 54 spec = fmt.Sprintf("%s/backups", id) 55 } 56 57 delete(queries, "instance_id") 58 return self.ListInContextWithSpec(nil, spec, queries, "backup_record_response") 59 } 60 61 // https://support.huaweicloud.com/api-dcs/dcs-zh-api-180423027.html 62 func (self *SElasticcacheManager) ListParameters(queries map[string]string) (*responses.ListResult, error) { 63 var spec string 64 if id, _ := queries["instance_id"]; len(id) == 0 { 65 return nil, fmt.Errorf("SElasticcacheManager.ListParameters missing parameter instance_id") 66 } else { 67 spec = fmt.Sprintf("%s/configs", id) 68 } 69 70 delete(queries, "instance_id") 71 return self.ListInContextWithSpec(nil, spec, queries, "redis_config") 72 } 73 74 func (self *SElasticcacheManager) Restart(instanceId string) (jsonutils.JSONObject, error) { 75 params := jsonutils.NewDict() 76 params.Add(jsonutils.NewArray(jsonutils.NewString(instanceId)), "instances") 77 params.Add(jsonutils.NewString("restart"), "action") 78 return self.UpdateInContextWithSpec(nil, "", "status", params, "") 79 } 80 81 // 当前版本,只有DCS2.0实例支持清空数据功能,即flush操作。 82 func (self *SElasticcacheManager) Flush(instanceId string) (jsonutils.JSONObject, error) { 83 params := jsonutils.NewDict() 84 params.Add(jsonutils.NewArray(jsonutils.NewString(instanceId)), "instances") 85 params.Add(jsonutils.NewString("flush"), "action") 86 return self.UpdateInContextWithSpec(nil, "", "status", params, "") 87 } 88 89 // https://support.huaweicloud.com/api-dcs/dcs-zh-api-180423034.html 90 func (self *SElasticcacheManager) RestoreInstance(instanceId string, backupId string) (jsonutils.JSONObject, error) { 91 params := jsonutils.NewDict() 92 params.Add(jsonutils.NewArray(jsonutils.NewString(backupId)), "backup_id") 93 94 return self.CreateInContextWithSpec(nil, fmt.Sprintf("%s/restores", instanceId), params, "") 95 } 96 97 // https://support.huaweicloud.com/api-dcs/dcs-zh-api-180423024.html 98 func (self *SElasticcacheManager) ChangeInstanceSpec(instanceId string, specCode string, newCapacity int64) (jsonutils.JSONObject, error) { 99 params := jsonutils.NewDict() 100 params.Set("new_capacity", jsonutils.NewInt(newCapacity)) 101 params.Set("spec_code", jsonutils.NewString(specCode)) 102 103 return self.CreateInContextWithSpec(nil, fmt.Sprintf("%s/extend", instanceId), params, "") 104 } 105 106 func NewDcsAvailableZoneManager(cfg manager.IManagerConfig) *SDcsAvailableZoneManager { 107 return &SDcsAvailableZoneManager{SResourceManager: SResourceManager{ 108 SBaseManager: NewBaseManager(cfg), 109 ServiceName: ServiceNameDCS, 110 Region: cfg.GetRegionId(), 111 ProjectId: "", 112 version: "v1.0", 113 Keyword: "available_zone", 114 KeywordPlural: "available_zones", 115 116 ResourceKeyword: "availableZones", 117 }} 118 }