From 59eb84fb272ed86db9f353b068456322af4375f9 Mon Sep 17 00:00:00 2001 From: Qu Xuan Date: Fri, 25 Jun 2021 16:43:15 +0800 Subject: [PATCH] feat(region): add azure redis --- cmd/climc/shell/compute/elasticcache.go | 9 + pkg/multicloud/azure/azure.go | 19 +- pkg/multicloud/azure/enterprise_redis.go | 274 ++++++++++++++++ pkg/multicloud/azure/redis.go | 394 +++++++++++++++++++++++ pkg/multicloud/azure/redis_acl.go | 90 ++++++ pkg/multicloud/azure/shell/redis.go | 55 ++++ 6 files changed, 832 insertions(+), 9 deletions(-) create mode 100644 pkg/multicloud/azure/enterprise_redis.go create mode 100644 pkg/multicloud/azure/redis.go create mode 100644 pkg/multicloud/azure/redis_acl.go create mode 100644 pkg/multicloud/azure/shell/redis.go diff --git a/cmd/climc/shell/compute/elasticcache.go b/cmd/climc/shell/compute/elasticcache.go index de4b290f90..bccad29421 100644 --- a/cmd/climc/shell/compute/elasticcache.go +++ b/cmd/climc/shell/compute/elasticcache.go @@ -93,6 +93,15 @@ func init() { return nil }) + R(&options.ElasticCacheIdOptions{}, "elastic-cache-sync", "Sync elastisc cache instance", func(s *mcclient.ClientSession, opts *options.ElasticCacheIdOptions) error { + result, err := modules.ElasticCache.PerformAction(s, opts.ID, "sync", nil) + if err != nil { + return err + } + printObject(result) + return nil + }) + R(&options.ElasticCacheIdOptions{}, "elastic-cache-delete", "Delete elastisc cache instance", func(s *mcclient.ClientSession, opts *options.ElasticCacheIdOptions) error { result, err := modules.ElasticCache.Delete(s, opts.ID, nil) if err != nil { diff --git a/pkg/multicloud/azure/azure.go b/pkg/multicloud/azure/azure.go index 8332ba9c29..91cb476484 100644 --- a/pkg/multicloud/azure/azure.go +++ b/pkg/multicloud/azure/azure.go @@ -399,23 +399,19 @@ func (self *SAzureClient) _apiVersion(resource string, params url.Values) string info := strings.Split(strings.ToLower(resource), "/") if utils.IsInStringArray("microsoft.dbformariadb", info) { return "2018-06-01-preview" - } - if utils.IsInStringArray("microsoft.dbformysql", info) { + } else if utils.IsInStringArray("microsoft.dbformysql", info) { if utils.IsInStringArray("flexibleservers", info) { return "2020-07-01-privatepreview" } return "2017-12-01" - } - if utils.IsInStringArray("microsoft.dbforpostgresql", info) { + } else if utils.IsInStringArray("microsoft.dbforpostgresql", info) { if utils.IsInStringArray("flexibleservers", info) { return "2020-02-14-preview" } return "2017-12-01" - } - if utils.IsInStringArray("microsoft.sql", info) { + } else if utils.IsInStringArray("microsoft.sql", info) { return "2020-08-01-preview" - } - if utils.IsInStringArray("microsoft.compute", info) { + } else if utils.IsInStringArray("microsoft.compute", info) { if utils.IsInStringArray("tags", info) { return "2020-06-01" } @@ -476,6 +472,11 @@ func (self *SAzureClient) _apiVersion(resource string, params url.Values) string return "2017-03-01-preview" } else if utils.IsInStringArray("microsoft.authorization", info) { return "2018-01-01-preview" + } else if utils.IsInStringArray("microsoft.cache", info) { + if utils.IsInStringArray("redisenterprise", info) { + return "2021-03-01" + } + return "2020-06-01" } return AZURE_API_VERSION } @@ -967,7 +968,7 @@ func (self *SAzureClient) GetCapabilities() []string { // cloudprovider.CLOUD_CAPABILITY_LOADBALANCER, cloudprovider.CLOUD_CAPABILITY_OBJECTSTORE, cloudprovider.CLOUD_CAPABILITY_RDS, - // cloudprovider.CLOUD_CAPABILITY_CACHE, + cloudprovider.CLOUD_CAPABILITY_CACHE, cloudprovider.CLOUD_CAPABILITY_EVENT, cloudprovider.CLOUD_CAPABILITY_CLOUDID, cloudprovider.CLOUD_CAPABILITY_SAML_AUTH, diff --git a/pkg/multicloud/azure/enterprise_redis.go b/pkg/multicloud/azure/enterprise_redis.go new file mode 100644 index 0000000000..7d509efbe8 --- /dev/null +++ b/pkg/multicloud/azure/enterprise_redis.go @@ -0,0 +1,274 @@ +// Copyright 2019 Yunion +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package azure + +import ( + "net/url" + "strings" + + "yunion.io/x/jsonutils" + "yunion.io/x/pkg/errors" + + api "yunion.io/x/onecloud/pkg/apis/compute" + "yunion.io/x/onecloud/pkg/cloudprovider" + "yunion.io/x/onecloud/pkg/multicloud" +) + +type SEnterpriseRedisCache struct { + multicloud.SElasticcacheBase + multicloud.AzureTags + + region *SRegion + ID string `json:"id"` + Location string `json:"location"` + Name string `json:"name"` + Type string `json:"type"` + Sku struct { + Name string `json:"name"` + Capacity string `json:"capacity"` + } `json:"sku"` + Properties struct { + Provisioningstate string `json:"provisioningState"` + Redisversion string `json:"redisVersion"` + Accesskeys interface{} `json:"accessKeys"` + Hostname string `json:"hostName"` + } `json:"properties"` +} + +func (self *SRegion) GetEnterpriseRedisCache(id string) (*SEnterpriseRedisCache, error) { + cache := &SEnterpriseRedisCache{region: self} + return cache, self.get(id, url.Values{}, cache) +} + +func (self *SRegion) GetEnterpriseRedisCaches() ([]SEnterpriseRedisCache, error) { + redis := []SEnterpriseRedisCache{} + err := self.list("Microsoft.Cache/redisEnterprise", url.Values{}, &redis) + if err != nil { + return nil, errors.Wrapf(err, "list") + } + return redis, nil +} + +func (self *SEnterpriseRedisCache) GetId() string { + return self.ID +} + +func (self *SEnterpriseRedisCache) GetName() string { + return self.Name +} + +func (self *SEnterpriseRedisCache) GetStatus() string { + switch self.Properties.Provisioningstate { + case "Creating": + return api.ELASTIC_CACHE_STATUS_DEPLOYING + case "Deleting", "Canceled": + return api.ELASTIC_CACHE_STATUS_DELETING + case "Disabled": + return api.ELASTIC_CACHE_STATUS_INACTIVE + case "Failed": + return api.ELASTIC_CACHE_STATUS_CREATE_FAILED + case "Succeeded", "Updating": + return api.ELASTIC_CACHE_STATUS_RUNNING + default: + return strings.ToLower(self.Properties.Provisioningstate) + } +} + +func (self *SEnterpriseRedisCache) GetGlobalId() string { + return strings.ToLower(self.ID) +} + +func (self *SEnterpriseRedisCache) GetInstanceType() string { + return self.Sku.Name +} + +func (self *SEnterpriseRedisCache) GetCapacityMB() int { + switch self.Sku.Name { + case "EnterpriseFlash_F1500": + return 1455 * 1024 + case "EnterpriseFlash_F300": + return 345 * 1024 + case "EnterpriseFlash_F700": + return 715 * 1024 + case "Enterprise_E10": + return 12 * 1024 + case "Enterprise_E100": + return 100 * 1024 + case "Enterprise_E20": + return 25 * 1024 + case "Enterprise_E50": + return 50 * 1024 + } + return 0 +} + +func (self *SEnterpriseRedisCache) GetArchType() string { + return api.ELASTIC_CACHE_ARCH_TYPE_CLUSTER +} + +func (self *SEnterpriseRedisCache) GetNodeType() string { + return api.ELASTIC_CACHE_NODE_TYPE_SINGLE +} + +func (self *SEnterpriseRedisCache) GetEngine() string { + return "Redis" +} + +func (self *SEnterpriseRedisCache) GetEngineVersion() string { + if len(self.Properties.Redisversion) == 0 { + return "latest" + } + return self.Properties.Redisversion +} + +func (self *SEnterpriseRedisCache) GetVpcId() string { + return "" +} + +func (self *SEnterpriseRedisCache) GetZoneId() string { + return self.region.getZone().GetGlobalId() +} + +func (self *SEnterpriseRedisCache) GetNetworkType() string { + return api.LB_NETWORK_TYPE_CLASSIC +} + +func (self *SEnterpriseRedisCache) GetNetworkId() string { + return "" +} + +func (self *SEnterpriseRedisCache) GetPrivateDNS() string { + return "" +} + +func (self *SEnterpriseRedisCache) GetPrivateIpAddr() string { + return "" +} + +func (self *SEnterpriseRedisCache) GetPrivateConnectPort() int { + return 10000 +} + +func (self *SEnterpriseRedisCache) GetPublicDNS() string { + return self.Properties.Hostname +} + +func (self *SEnterpriseRedisCache) GetPublicIpAddr() string { + return "" +} + +func (self *SEnterpriseRedisCache) GetPublicConnectPort() int { + return 10000 +} + +func (self *SEnterpriseRedisCache) GetMaintainStartTime() string { + return "" +} + +func (self *SEnterpriseRedisCache) GetMaintainEndTime() string { + return "" +} + +func (self *SEnterpriseRedisCache) AllocatePublicConnection(port int) (string, error) { + return "", errors.Wrapf(cloudprovider.ErrNotImplemented, "AllocatePublicConnection") +} + +func (self *SEnterpriseRedisCache) ChangeInstanceSpec(spec string) error { + return errors.Wrapf(cloudprovider.ErrNotImplemented, "ChangeInstanceSpec") +} + +func (self *SEnterpriseRedisCache) CreateAccount(account cloudprovider.SCloudElasticCacheAccountInput) (cloudprovider.ICloudElasticcacheAccount, error) { + return nil, errors.Wrapf(cloudprovider.ErrNotImplemented, "CreateAccount") +} + +func (self *SEnterpriseRedisCache) CreateAcl(aclName, securityIps string) (cloudprovider.ICloudElasticcacheAcl, error) { + return nil, errors.Wrapf(cloudprovider.ErrNotImplemented, "CreateAcl") +} + +func (self *SEnterpriseRedisCache) CreateBackup(desc string) (cloudprovider.ICloudElasticcacheBackup, error) { + return nil, errors.Wrapf(cloudprovider.ErrNotImplemented, "CreateBackup") +} + +func (self *SEnterpriseRedisCache) Delete() error { + return self.region.Delete(self.ID) +} + +func (self *SEnterpriseRedisCache) FlushInstance(input cloudprovider.SCloudElasticCacheFlushInstanceInput) error { + return errors.Wrapf(cloudprovider.ErrNotSupported, "FlushInstance") +} + +func (self *SEnterpriseRedisCache) GetAuthMode() string { + return "on" +} + +func (self *SEnterpriseRedisCache) GetICloudElasticcacheAccounts() ([]cloudprovider.ICloudElasticcacheAccount, error) { + return nil, errors.Wrapf(cloudprovider.ErrNotImplemented, "GetICloudElasticcacheAccounts") +} + +func (self *SEnterpriseRedisCache) GetICloudElasticcacheAcls() ([]cloudprovider.ICloudElasticcacheAcl, error) { + return []cloudprovider.ICloudElasticcacheAcl{}, nil +} + +func (self *SEnterpriseRedisCache) GetICloudElasticcacheAcl(aclId string) (cloudprovider.ICloudElasticcacheAcl, error) { + return nil, cloudprovider.ErrNotFound +} + +func (self *SEnterpriseRedisCache) GetICloudElasticcacheBackups() ([]cloudprovider.ICloudElasticcacheBackup, error) { + return []cloudprovider.ICloudElasticcacheBackup{}, nil +} + +func (self *SEnterpriseRedisCache) GetICloudElasticcacheParameters() ([]cloudprovider.ICloudElasticcacheParameter, error) { + return []cloudprovider.ICloudElasticcacheParameter{}, nil +} + +func (self *SEnterpriseRedisCache) GetICloudElasticcacheAccount(accountId string) (cloudprovider.ICloudElasticcacheAccount, error) { + return nil, cloudprovider.ErrNotFound +} + +func (self *SEnterpriseRedisCache) GetICloudElasticcacheBackup(backupId string) (cloudprovider.ICloudElasticcacheBackup, error) { + return nil, cloudprovider.ErrNotFound +} + +func (self *SEnterpriseRedisCache) GetSecurityGroupIds() ([]string, error) { + return []string{}, nil +} + +func (self *SEnterpriseRedisCache) ReleasePublicConnection() error { + return cloudprovider.ErrNotSupported +} + +func (self *SEnterpriseRedisCache) Restart() error { + return cloudprovider.ErrNotImplemented +} + +func (self *SEnterpriseRedisCache) SetMaintainTime(start, end string) error { + return cloudprovider.ErrNotImplemented +} + +func (self *SEnterpriseRedisCache) UpdateAuthMode(noPasswordAccess bool, password string) error { + return cloudprovider.ErrNotSupported +} + +func (self *SEnterpriseRedisCache) UpdateBackupPolicy(config cloudprovider.SCloudElasticCacheBackupPolicyUpdateInput) error { + return cloudprovider.ErrNotImplemented +} + +func (self *SEnterpriseRedisCache) UpdateInstanceParameters(config jsonutils.JSONObject) error { + return cloudprovider.ErrNotImplemented +} + +func (self *SEnterpriseRedisCache) UpdateSecurityGroups(secgroupIds []string) error { + return cloudprovider.ErrNotImplemented +} diff --git a/pkg/multicloud/azure/redis.go b/pkg/multicloud/azure/redis.go new file mode 100644 index 0000000000..5f4e567519 --- /dev/null +++ b/pkg/multicloud/azure/redis.go @@ -0,0 +1,394 @@ +// Copyright 2019 Yunion +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package azure + +import ( + "fmt" + "net/url" + "strings" + + "yunion.io/x/jsonutils" + "yunion.io/x/pkg/errors" + + api "yunion.io/x/onecloud/pkg/apis/compute" + "yunion.io/x/onecloud/pkg/cloudprovider" + "yunion.io/x/onecloud/pkg/multicloud" +) + +type SRedisCache struct { + multicloud.SElasticcacheBase + multicloud.AzureTags + + region *SRegion + ID string `json:"id"` + Location string `json:"location"` + Name string `json:"name"` + Type string `json:"type"` + Properties struct { + Provisioningstate string `json:"provisioningState"` + Redisversion string `json:"redisVersion"` + Sku struct { + Name string `json:"name"` + Family string `json:"family"` + Capacity int `json:"capacity"` + } `json:"sku"` + Enablenonsslport bool `json:"enableNonSslPort"` + Instances []struct { + Sslport int `json:"sslPort"` + Shardid int `json:"shardId"` + Ismaster bool `json:"isMaster"` + } `json:"instances"` + Publicnetworkaccess string `json:"publicNetworkAccess"` + Redisconfiguration struct { + Maxclients string `json:"maxclients"` + MaxmemoryReserved string `json:"maxmemory-reserved"` + MaxfragmentationmemoryReserved string `json:"maxfragmentationmemory-reserved"` + MaxmemoryDelta string `json:"maxmemory-delta"` + } `json:"redisConfiguration"` + Accesskeys interface{} `json:"accessKeys"` + Hostname string `json:"hostName"` + Port int `json:"port"` + Sslport int `json:"sslPort"` + Shardcount int `json:"shardCount"` + SubnetId string `json:"subnetId"` + StaticIP string `json:"staticIP"` + Linkedservers []interface{} `json:"linkedServers"` + } `json:"properties"` +} + +func (self *SRegion) GetRedisCache(id string) (*SRedisCache, error) { + cache := &SRedisCache{region: self} + return cache, self.get(id, url.Values{}, cache) +} + +func (self *SRegion) GetRedisCaches() ([]SRedisCache, error) { + redis := []SRedisCache{} + err := self.list("Microsoft.Cache/redis", url.Values{}, &redis) + if err != nil { + return nil, errors.Wrapf(err, "list") + } + return redis, nil +} + +func (self *SRedisCache) GetId() string { + return self.ID +} + +func (self *SRedisCache) GetName() string { + return self.Name +} + +func (self *SRedisCache) GetStatus() string { + switch self.Properties.Provisioningstate { + case "Creating": + return api.ELASTIC_CACHE_STATUS_DEPLOYING + case "Deleting": + return api.ELASTIC_CACHE_STATUS_DELETING + case "Disabled": + return api.ELASTIC_CACHE_STATUS_INACTIVE + case "Failed": + return api.ELASTIC_CACHE_STATUS_CREATE_FAILED + case "Linking": + return api.ELASTIC_CACHE_STATUS_RUNNING + case "Provisioning": + return api.ELASTIC_CACHE_STATUS_RUNNING + case "RecoveringScaleFailure": + return api.ELASTIC_CACHE_STATUS_CHANGE_FAILED + case "Scaling": + return api.ELASTIC_CACHE_STATUS_CHANGING + case "Succeeded": + return api.ELASTIC_CACHE_STATUS_RUNNING + case "Unlinking": + return api.ELASTIC_CACHE_STATUS_RUNNING + case "Unprovisioning": + return api.ELASTIC_CACHE_STATUS_RUNNING + case "Updating": + return api.ELASTIC_CACHE_STATUS_RUNNING + default: + return strings.ToLower(self.Properties.Provisioningstate) + } +} + +func (self *SRedisCache) GetGlobalId() string { + return strings.ToLower(self.ID) +} + +func (self *SRedisCache) GetInstanceType() string { + return self.Properties.Sku.Name +} + +func (self *SRedisCache) GetCapacityMB() int { + switch self.Properties.Sku.Family { + case "P": + switch self.Properties.Sku.Capacity { + case 1: + return 6 * 1024 + case 2: + return 13 * 1024 + case 3: + return 26 * 1024 + case 4: + return 53 * 1024 + case 5: + return 120 * 1024 + } + case "C": + switch self.Properties.Sku.Capacity { + case 0: + return 250 + case 1: + return 1024 + case 2: + return 2.5 * 1024 + case 3: + return 6 * 1024 + case 4: + return 13 * 1024 + case 5: + return 26 * 1024 + case 6: + return 53 * 1024 + } + } + return 0 +} + +func (self *SRedisCache) GetArchType() string { + if self.Properties.Sku.Family == "P" { + return api.ELASTIC_CACHE_ARCH_TYPE_MASTER + } + return api.ELASTIC_CACHE_ARCH_TYPE_SINGLE +} + +func (self *SRedisCache) GetNodeType() string { + switch len(self.Properties.Instances) { + case 1: + return api.ELASTIC_CACHE_NODE_TYPE_SINGLE + case 2: + return api.ELASTIC_CACHE_NODE_TYPE_DOUBLE + case 3: + return api.ELASTIC_CACHE_NODE_TYPE_THREE + case 4: + return api.ELASTIC_CACHE_NODE_TYPE_FOUR + case 5: + return api.ELASTIC_CACHE_NODE_TYPE_FIVE + case 6: + return api.ELASTIC_CACHE_NODE_TYPE_SIX + } + return fmt.Sprintf("%d", self.Properties.Shardcount) +} + +func (self *SRedisCache) GetEngine() string { + return "Redis" +} + +func (self *SRedisCache) GetEngineVersion() string { + return self.Properties.Redisversion +} + +func (self *SRedisCache) GetVpcId() string { + if len(self.Properties.SubnetId) > 0 { + info := strings.Split(self.Properties.SubnetId, "/") + if len(info) > 2 { + return strings.Join(info[:len(info)-2], "/") + } + } + return "" +} + +func (self *SRedisCache) GetZoneId() string { + return self.region.getZone().GetGlobalId() +} + +func (self *SRedisCache) GetNetworkType() string { + if len(self.Properties.SubnetId) > 0 { + return api.LB_NETWORK_TYPE_VPC + } + return api.LB_NETWORK_TYPE_CLASSIC +} + +func (self *SRedisCache) GetNetworkId() string { + return strings.ToLower(self.Properties.SubnetId) +} + +func (self *SRedisCache) GetPrivateDNS() string { + return "" +} + +func (self *SRedisCache) GetPrivateIpAddr() string { + return self.Properties.StaticIP +} + +func (self *SRedisCache) GetPrivateConnectPort() int { + return self.Properties.Port +} + +func (self *SRedisCache) GetPublicDNS() string { + return self.Properties.Hostname +} + +func (self *SRedisCache) GetPublicIpAddr() string { + return "" +} + +func (self *SRedisCache) GetPublicConnectPort() int { + return self.Properties.Sslport +} + +func (self *SRedisCache) GetMaintainStartTime() string { + return "" +} + +func (self *SRedisCache) GetMaintainEndTime() string { + return "" +} + +func (self *SRedisCache) AllocatePublicConnection(port int) (string, error) { + return "", errors.Wrapf(cloudprovider.ErrNotImplemented, "AllocatePublicConnection") +} + +func (self *SRedisCache) ChangeInstanceSpec(spec string) error { + return errors.Wrapf(cloudprovider.ErrNotImplemented, "ChangeInstanceSpec") +} + +func (self *SRedisCache) CreateAccount(account cloudprovider.SCloudElasticCacheAccountInput) (cloudprovider.ICloudElasticcacheAccount, error) { + return nil, errors.Wrapf(cloudprovider.ErrNotImplemented, "CreateAccount") +} + +func (self *SRedisCache) CreateAcl(aclName, securityIps string) (cloudprovider.ICloudElasticcacheAcl, error) { + return nil, errors.Wrapf(cloudprovider.ErrNotImplemented, "CreateAcl") +} + +func (self *SRedisCache) CreateBackup(desc string) (cloudprovider.ICloudElasticcacheBackup, error) { + return nil, errors.Wrapf(cloudprovider.ErrNotImplemented, "CreateBackup") +} + +func (self *SRedisCache) Delete() error { + return self.region.Delete(self.ID) +} + +func (self *SRedisCache) FlushInstance(input cloudprovider.SCloudElasticCacheFlushInstanceInput) error { + return errors.Wrapf(cloudprovider.ErrNotSupported, "FlushInstance") +} + +func (self *SRedisCache) GetAuthMode() string { + return "on" +} + +func (self *SRedisCache) GetICloudElasticcacheAccounts() ([]cloudprovider.ICloudElasticcacheAccount, error) { + return nil, errors.Wrapf(cloudprovider.ErrNotImplemented, "GetICloudElasticcacheAccounts") +} + +func (self *SRedisCache) GetICloudElasticcacheAcls() ([]cloudprovider.ICloudElasticcacheAcl, error) { + acls, err := self.region.GetRedisAcls(self.ID) + if err != nil { + return nil, errors.Wrapf(err, "GetRedisAcls") + } + ret := []cloudprovider.ICloudElasticcacheAcl{} + for i := range acls { + acls[i].redis = self + ret = append(ret, &acls[i]) + } + return ret, nil +} + +func (self *SRedisCache) GetICloudElasticcacheAcl(aclId string) (cloudprovider.ICloudElasticcacheAcl, error) { + acl, err := self.region.GetRedisAcl(aclId) + if err != nil { + return nil, errors.Wrapf(err, "GetRedisAcl") + } + acl.redis = self + return acl, nil +} + +func (self *SRedisCache) GetICloudElasticcacheBackups() ([]cloudprovider.ICloudElasticcacheBackup, error) { + return []cloudprovider.ICloudElasticcacheBackup{}, nil +} + +func (self *SRedisCache) GetICloudElasticcacheParameters() ([]cloudprovider.ICloudElasticcacheParameter, error) { + return []cloudprovider.ICloudElasticcacheParameter{}, nil +} + +func (self *SRedisCache) GetICloudElasticcacheAccount(accountId string) (cloudprovider.ICloudElasticcacheAccount, error) { + return nil, cloudprovider.ErrNotFound +} + +func (self *SRedisCache) GetICloudElasticcacheBackup(backupId string) (cloudprovider.ICloudElasticcacheBackup, error) { + return nil, cloudprovider.ErrNotFound +} + +func (self *SRedisCache) GetSecurityGroupIds() ([]string, error) { + return []string{}, nil +} + +func (self *SRedisCache) ReleasePublicConnection() error { + return cloudprovider.ErrNotSupported +} + +func (self *SRedisCache) Restart() error { + return cloudprovider.ErrNotImplemented +} + +func (self *SRedisCache) SetMaintainTime(start, end string) error { + return cloudprovider.ErrNotImplemented +} + +func (self *SRedisCache) UpdateAuthMode(noPasswordAccess bool, password string) error { + return cloudprovider.ErrNotSupported +} + +func (self *SRedisCache) UpdateBackupPolicy(config cloudprovider.SCloudElasticCacheBackupPolicyUpdateInput) error { + return cloudprovider.ErrNotImplemented +} + +func (self *SRedisCache) UpdateInstanceParameters(config jsonutils.JSONObject) error { + return cloudprovider.ErrNotImplemented +} + +func (self *SRedisCache) UpdateSecurityGroups(secgroupIds []string) error { + return cloudprovider.ErrNotImplemented +} + +func (self *SRegion) GetIElasticcaches() ([]cloudprovider.ICloudElasticcache, error) { + redis, err := self.GetRedisCaches() + if err != nil { + return nil, errors.Wrapf(err, "GetRedisCaches") + } + ret := []cloudprovider.ICloudElasticcache{} + for i := range redis { + redis[i].region = self + ret = append(ret, &redis[i]) + } + enterpriseRedis, err := self.GetEnterpriseRedisCaches() + if err != nil { + return nil, errors.Wrapf(err, "GetEnterpriseRedisCaches") + } + for i := range enterpriseRedis { + enterpriseRedis[i].region = self + ret = append(ret, &enterpriseRedis[i]) + } + return ret, nil +} + +func (self *SRegion) GetIElasticcacheById(id string) (cloudprovider.ICloudElasticcache, error) { + id = strings.ToLower(id) + if strings.Index(id, "microsoft.cache/redis") > 0 { + return self.GetRedisCache(id) + } else if strings.Index(id, "Microsoft.Cache/redisEnterprise") > 0 { + return self.GetEnterpriseRedisCache(id) + } else { + return nil, errors.Wrapf(cloudprovider.ErrNotFound, id) + } +} diff --git a/pkg/multicloud/azure/redis_acl.go b/pkg/multicloud/azure/redis_acl.go new file mode 100644 index 0000000000..89117eb82d --- /dev/null +++ b/pkg/multicloud/azure/redis_acl.go @@ -0,0 +1,90 @@ +// Copyright 2019 Yunion +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package azure + +import ( + "fmt" + "net/url" + "strings" + + "yunion.io/x/jsonutils" + "yunion.io/x/pkg/errors" + + api "yunion.io/x/onecloud/pkg/apis/compute" + "yunion.io/x/onecloud/pkg/cloudprovider" + "yunion.io/x/onecloud/pkg/multicloud" +) + +type SRedisAcl struct { + redis *SRedisCache + multicloud.SResourceBase + multicloud.AzureTags + + ID string `json:"id"` + Name string `json:"name"` + Type string `json:"type"` + Properties struct { + Startip string `json:"startIP"` + Endip string `json:"endIP"` + } `json:"properties"` +} + +func (self *SRedisAcl) GetId() string { + return self.ID +} + +func (self *SRedisAcl) GetGlobalId() string { + return strings.ToLower(self.ID) +} + +func (self *SRedisAcl) GetName() string { + return self.Name +} + +func (self *SRedisAcl) GetStatus() string { + return api.ELASTIC_CACHE_ACL_STATUS_AVAILABLE +} + +func (self *SRedisAcl) Refresh() error { + acl, err := self.redis.region.GetRedisAcl(self.ID) + if err != nil { + return err + } + return jsonutils.Update(self, acl) +} + +func (self *SRedisAcl) GetIpList() string { + return fmt.Sprintf("%s-%s", self.Properties.Startip, self.Properties.Endip) +} + +func (self *SRedisAcl) Delete() error { + return self.redis.region.Delete(self.ID) +} + +func (self *SRedisAcl) UpdateAcl(securityIps string) error { + return errors.Wrapf(cloudprovider.ErrNotImplemented, "UpdateAcl") +} + +func (self *SRegion) GetRedisAcls(id string) ([]SRedisAcl, error) { + result := struct { + Value []SRedisAcl + }{} + return result.Value, self.get(id+"/firewallRules", url.Values{}, &result) +} + +func (self *SRegion) GetRedisAcl(id string) (*SRedisAcl, error) { + acl := &SRedisAcl{} + return acl, self.get(id, url.Values{}, acl) +} diff --git a/pkg/multicloud/azure/shell/redis.go b/pkg/multicloud/azure/shell/redis.go new file mode 100644 index 0000000000..fdbb6388ca --- /dev/null +++ b/pkg/multicloud/azure/shell/redis.go @@ -0,0 +1,55 @@ +// Copyright 2019 Yunion +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package shell + +import ( + "yunion.io/x/onecloud/pkg/multicloud/azure" + "yunion.io/x/onecloud/pkg/util/shellutils" +) + +func init() { + type RedisListOptions struct { + } + shellutils.R(&RedisListOptions{}, "redis-list", "List redis", func(cli *azure.SRegion, args *RedisListOptions) error { + redis, err := cli.GetRedisCaches() + if err != nil { + return err + } + printList(redis, 0, 0, 0, nil) + return nil + }) + + shellutils.R(&RedisListOptions{}, "enterprise-redis-list", "List enterprise redis", func(cli *azure.SRegion, args *RedisListOptions) error { + redis, err := cli.GetEnterpriseRedisCaches() + if err != nil { + return err + } + printList(redis, 0, 0, 0, nil) + return nil + }) + + type RedisIdOptions struct { + ID string + } + shellutils.R(&RedisIdOptions{}, "redis-acl-list", "List redis acls", func(cli *azure.SRegion, args *RedisIdOptions) error { + acls, err := cli.GetRedisAcls(args.ID) + if err != nil { + return err + } + printList(acls, 0, 0, 0, nil) + return nil + }) + +}