yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/azure/enterprise_redis.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 azure 16 17 import ( 18 "net/url" 19 "strings" 20 21 "yunion.io/x/jsonutils" 22 "yunion.io/x/pkg/errors" 23 24 api "yunion.io/x/cloudmux/pkg/apis/compute" 25 "yunion.io/x/cloudmux/pkg/cloudprovider" 26 "yunion.io/x/cloudmux/pkg/multicloud" 27 ) 28 29 type SEnterpriseRedisCache struct { 30 multicloud.SElasticcacheBase 31 AzureTags 32 33 region *SRegion 34 ID string `json:"id"` 35 Location string `json:"location"` 36 Name string `json:"name"` 37 Type string `json:"type"` 38 Sku struct { 39 Name string `json:"name"` 40 Capacity string `json:"capacity"` 41 } `json:"sku"` 42 Properties struct { 43 Provisioningstate string `json:"provisioningState"` 44 Redisversion string `json:"redisVersion"` 45 Accesskeys interface{} `json:"accessKeys"` 46 Hostname string `json:"hostName"` 47 } `json:"properties"` 48 } 49 50 func (self *SRegion) GetEnterpriseRedisCache(id string) (*SEnterpriseRedisCache, error) { 51 cache := &SEnterpriseRedisCache{region: self} 52 return cache, self.get(id, url.Values{}, cache) 53 } 54 55 func (self *SRegion) GetEnterpriseRedisCaches() ([]SEnterpriseRedisCache, error) { 56 redis := []SEnterpriseRedisCache{} 57 err := self.list("Microsoft.Cache/redisEnterprise", url.Values{}, &redis) 58 if err != nil { 59 return nil, errors.Wrapf(err, "list") 60 } 61 return redis, nil 62 } 63 64 func (self *SEnterpriseRedisCache) GetId() string { 65 return self.ID 66 } 67 68 func (self *SEnterpriseRedisCache) GetName() string { 69 return self.Name 70 } 71 72 func (self *SEnterpriseRedisCache) GetProjectId() string { 73 return getResourceGroup(self.ID) 74 } 75 76 func (self *SEnterpriseRedisCache) GetStatus() string { 77 switch self.Properties.Provisioningstate { 78 case "Creating": 79 return api.ELASTIC_CACHE_STATUS_DEPLOYING 80 case "Deleting", "Canceled": 81 return api.ELASTIC_CACHE_STATUS_DELETING 82 case "Disabled": 83 return api.ELASTIC_CACHE_STATUS_INACTIVE 84 case "Failed": 85 return api.ELASTIC_CACHE_STATUS_CREATE_FAILED 86 case "Succeeded", "Updating": 87 return api.ELASTIC_CACHE_STATUS_RUNNING 88 default: 89 return strings.ToLower(self.Properties.Provisioningstate) 90 } 91 } 92 93 func (self *SEnterpriseRedisCache) GetGlobalId() string { 94 return strings.ToLower(self.ID) 95 } 96 97 func (self *SEnterpriseRedisCache) GetInstanceType() string { 98 return self.Sku.Name 99 } 100 101 func (self *SEnterpriseRedisCache) GetCapacityMB() int { 102 switch self.Sku.Name { 103 case "EnterpriseFlash_F1500": 104 return 1455 * 1024 105 case "EnterpriseFlash_F300": 106 return 345 * 1024 107 case "EnterpriseFlash_F700": 108 return 715 * 1024 109 case "Enterprise_E10": 110 return 12 * 1024 111 case "Enterprise_E100": 112 return 100 * 1024 113 case "Enterprise_E20": 114 return 25 * 1024 115 case "Enterprise_E50": 116 return 50 * 1024 117 } 118 return 0 119 } 120 121 func (self *SEnterpriseRedisCache) GetArchType() string { 122 return api.ELASTIC_CACHE_ARCH_TYPE_CLUSTER 123 } 124 125 func (self *SEnterpriseRedisCache) GetNodeType() string { 126 return api.ELASTIC_CACHE_NODE_TYPE_SINGLE 127 } 128 129 func (self *SEnterpriseRedisCache) GetEngine() string { 130 return "Redis" 131 } 132 133 func (self *SEnterpriseRedisCache) GetEngineVersion() string { 134 if len(self.Properties.Redisversion) == 0 { 135 return "latest" 136 } 137 return self.Properties.Redisversion 138 } 139 140 func (self *SEnterpriseRedisCache) GetVpcId() string { 141 return "" 142 } 143 144 func (self *SEnterpriseRedisCache) GetZoneId() string { 145 return self.region.getZone().GetGlobalId() 146 } 147 148 func (self *SEnterpriseRedisCache) GetNetworkType() string { 149 return api.LB_NETWORK_TYPE_CLASSIC 150 } 151 152 func (self *SEnterpriseRedisCache) GetNetworkId() string { 153 return "" 154 } 155 156 func (self *SEnterpriseRedisCache) GetPrivateDNS() string { 157 return "" 158 } 159 160 func (self *SEnterpriseRedisCache) GetPrivateIpAddr() string { 161 return "" 162 } 163 164 func (self *SEnterpriseRedisCache) GetPrivateConnectPort() int { 165 return 10000 166 } 167 168 func (self *SEnterpriseRedisCache) GetPublicDNS() string { 169 return self.Properties.Hostname 170 } 171 172 func (self *SEnterpriseRedisCache) GetPublicIpAddr() string { 173 return "" 174 } 175 176 func (self *SEnterpriseRedisCache) GetPublicConnectPort() int { 177 return 10000 178 } 179 180 func (self *SEnterpriseRedisCache) GetMaintainStartTime() string { 181 return "" 182 } 183 184 func (self *SEnterpriseRedisCache) GetMaintainEndTime() string { 185 return "" 186 } 187 188 func (self *SEnterpriseRedisCache) AllocatePublicConnection(port int) (string, error) { 189 return "", errors.Wrapf(cloudprovider.ErrNotImplemented, "AllocatePublicConnection") 190 } 191 192 func (self *SEnterpriseRedisCache) ChangeInstanceSpec(spec string) error { 193 return errors.Wrapf(cloudprovider.ErrNotImplemented, "ChangeInstanceSpec") 194 } 195 196 func (self *SEnterpriseRedisCache) CreateAccount(account cloudprovider.SCloudElasticCacheAccountInput) (cloudprovider.ICloudElasticcacheAccount, error) { 197 return nil, errors.Wrapf(cloudprovider.ErrNotImplemented, "CreateAccount") 198 } 199 200 func (self *SEnterpriseRedisCache) CreateAcl(aclName, securityIps string) (cloudprovider.ICloudElasticcacheAcl, error) { 201 return nil, errors.Wrapf(cloudprovider.ErrNotImplemented, "CreateAcl") 202 } 203 204 func (self *SEnterpriseRedisCache) CreateBackup(desc string) (cloudprovider.ICloudElasticcacheBackup, error) { 205 return nil, errors.Wrapf(cloudprovider.ErrNotImplemented, "CreateBackup") 206 } 207 208 func (self *SEnterpriseRedisCache) Delete() error { 209 return self.region.Delete(self.ID) 210 } 211 212 func (self *SEnterpriseRedisCache) FlushInstance(input cloudprovider.SCloudElasticCacheFlushInstanceInput) error { 213 return errors.Wrapf(cloudprovider.ErrNotSupported, "FlushInstance") 214 } 215 216 func (self *SEnterpriseRedisCache) GetAuthMode() string { 217 return "on" 218 } 219 220 func (self *SEnterpriseRedisCache) GetICloudElasticcacheAccounts() ([]cloudprovider.ICloudElasticcacheAccount, error) { 221 return nil, errors.Wrapf(cloudprovider.ErrNotImplemented, "GetICloudElasticcacheAccounts") 222 } 223 224 func (self *SEnterpriseRedisCache) GetICloudElasticcacheAcls() ([]cloudprovider.ICloudElasticcacheAcl, error) { 225 return []cloudprovider.ICloudElasticcacheAcl{}, nil 226 } 227 228 func (self *SEnterpriseRedisCache) GetICloudElasticcacheAcl(aclId string) (cloudprovider.ICloudElasticcacheAcl, error) { 229 return nil, cloudprovider.ErrNotFound 230 } 231 232 func (self *SEnterpriseRedisCache) GetICloudElasticcacheBackups() ([]cloudprovider.ICloudElasticcacheBackup, error) { 233 return []cloudprovider.ICloudElasticcacheBackup{}, nil 234 } 235 236 func (self *SEnterpriseRedisCache) GetICloudElasticcacheParameters() ([]cloudprovider.ICloudElasticcacheParameter, error) { 237 return []cloudprovider.ICloudElasticcacheParameter{}, nil 238 } 239 240 func (self *SEnterpriseRedisCache) GetICloudElasticcacheAccount(accountId string) (cloudprovider.ICloudElasticcacheAccount, error) { 241 return nil, cloudprovider.ErrNotFound 242 } 243 244 func (self *SEnterpriseRedisCache) GetICloudElasticcacheBackup(backupId string) (cloudprovider.ICloudElasticcacheBackup, error) { 245 return nil, cloudprovider.ErrNotFound 246 } 247 248 func (self *SEnterpriseRedisCache) GetSecurityGroupIds() ([]string, error) { 249 return []string{}, nil 250 } 251 252 func (self *SEnterpriseRedisCache) ReleasePublicConnection() error { 253 return cloudprovider.ErrNotSupported 254 } 255 256 func (self *SEnterpriseRedisCache) Restart() error { 257 return cloudprovider.ErrNotImplemented 258 } 259 260 func (self *SEnterpriseRedisCache) SetMaintainTime(start, end string) error { 261 return cloudprovider.ErrNotImplemented 262 } 263 264 func (self *SEnterpriseRedisCache) UpdateAuthMode(noPasswordAccess bool, password string) error { 265 return cloudprovider.ErrNotSupported 266 } 267 268 func (self *SEnterpriseRedisCache) UpdateBackupPolicy(config cloudprovider.SCloudElasticCacheBackupPolicyUpdateInput) error { 269 return cloudprovider.ErrNotImplemented 270 } 271 272 func (self *SEnterpriseRedisCache) UpdateInstanceParameters(config jsonutils.JSONObject) error { 273 return cloudprovider.ErrNotImplemented 274 } 275 276 func (self *SEnterpriseRedisCache) UpdateSecurityGroups(secgroupIds []string) error { 277 return cloudprovider.ErrNotImplemented 278 }