From d36878bbca58c5d5ba6d29561a3b586843d3d5ec Mon Sep 17 00:00:00 2001 From: tb365 Date: Mon, 9 Aug 2021 16:30:16 +0800 Subject: [PATCH] fix(region): update huawei cloud stack update credential --- pkg/cloudprovider/endpoints.go | 2 +- pkg/compute/models/cloudaccounts.go | 32 ++++++++++++--- .../client/modules/manager_resource.go | 40 +++++++++---------- pkg/multicloud/huaweistack/region.go | 2 +- 4 files changed, 49 insertions(+), 27 deletions(-) diff --git a/pkg/cloudprovider/endpoints.go b/pkg/cloudprovider/endpoints.go index 5e786959f8..402cba09e0 100644 --- a/pkg/cloudprovider/endpoints.go +++ b/pkg/cloudprovider/endpoints.go @@ -115,7 +115,7 @@ func (self *SHuaweiCloudStackEndpoints) GetEndpoint(serviceName string, region s var endpoint string fileds := reflect.Indirect(reflect.ValueOf(self)) f := fileds.FieldByNameFunc(func(c string) bool { - return strings.ToLower(c) == sn + return c == sn }) if f.Kind() == reflect.String { diff --git a/pkg/compute/models/cloudaccounts.go b/pkg/compute/models/cloudaccounts.go index aa0aaf81ee..7a76231d4c 100644 --- a/pkg/compute/models/cloudaccounts.go +++ b/pkg/compute/models/cloudaccounts.go @@ -718,12 +718,34 @@ func (self *SCloudaccount) PerformUpdateCredential(ctx context.Context, userCred originSecret, _ := self.getPassword() + hcsoEndpoints := cloudprovider.SHuaweiCloudStackEndpoints{} + if self.Provider == api.CLOUD_PROVIDER_HUAWEI_CLOUD_STACK && input.SHuaweiCloudStackEndpoints != nil { + if self.Options == nil { + self.Options = jsonutils.NewDict() + } + + newOptions := jsonutils.Marshal(input.SHuaweiCloudStackEndpoints) + _, err = db.UpdateWithLock(ctx, self, func() error { + self.Options.Update(newOptions) + return nil + }) + if err != nil { + return nil, err + } + + err = self.Options.Unmarshal(&hcsoEndpoints) + if err != nil { + return nil, err + } + } + accountId, err := cloudprovider.IsValidCloudAccount(cloudprovider.ProviderConfig{ - Vendor: self.Provider, - URL: self.AccessUrl, - Account: account.Account, - Secret: account.Secret, - ProxyFunc: self.proxyFunc(), + Vendor: self.Provider, + URL: self.AccessUrl, + Account: account.Account, + Secret: account.Secret, + SHuaweiCloudStackEndpoints: hcsoEndpoints, + ProxyFunc: self.proxyFunc(), }) if err != nil { return nil, httperrors.NewInputParameterError("invalid cloud account info error: %s", err.Error()) diff --git a/pkg/multicloud/huaweistack/client/modules/manager_resource.go b/pkg/multicloud/huaweistack/client/modules/manager_resource.go index fd2d990947..376c33e4fb 100644 --- a/pkg/multicloud/huaweistack/client/modules/manager_resource.go +++ b/pkg/multicloud/huaweistack/client/modules/manager_resource.go @@ -31,26 +31,26 @@ type ServiceNameType string const HuaWeiDefaultDomain = "myhuaweicloud.com" const ( - ServiceNameECS ServiceNameType = "ecs" // 弹性云服务 - ServiceNameCCE ServiceNameType = "cce" // 云容器服务 - ServiceNameAS ServiceNameType = "as" // 弹性伸缩服务 - ServiceNameIAM ServiceNameType = "iam-pub" // 统一身份认证服务 - ServiceNameIMS ServiceNameType = "ims" // 镜像服务 - ServiceNameCSBS ServiceNameType = "csbs" // 云服务器备份服务 - ServiceNameCCI ServiceNameType = "cci" // 云容器实例 CCI - ServiceNameBMS ServiceNameType = "bms" // 裸金属服务器 - ServiceNameEVS ServiceNameType = "evs" // 云硬盘 EVS - ServiceNameVBS ServiceNameType = "vbs" // 云硬盘备份 VBS - ServiceNameOBS ServiceNameType = "obs" // 对象存储服务 OBS - ServiceNameVPC ServiceNameType = "vpc" // 虚拟私有云 VPC - ServiceNameELB ServiceNameType = "elb" // 弹性负载均衡 ELB - ServiceNameBSS ServiceNameType = "bss" // 合作伙伴运营能力 - ServiceNameNAT ServiceNameType = "nat" // Nat网关 NAT - ServiceNameDCS ServiceNameType = "dcs" // 分布式缓存服务 - ServiceNameRDS ServiceNameType = "rds" // 关系型数据库 RDS - ServiceNameCTS ServiceNameType = "cts" // 云审计服务 - ServiceNameCES ServiceNameType = "ces" // 监控服务 CloudEye - ServiceNameEPS ServiceNameType = "eps" // 企业项目 + ServiceNameECS ServiceNameType = "ecs" // 弹性云服务 + ServiceNameCCE ServiceNameType = "cce" // 云容器服务 + ServiceNameAS ServiceNameType = "as" // 弹性伸缩服务 + ServiceNameIAM ServiceNameType = "iam" // 统一身份认证服务 + ServiceNameIMS ServiceNameType = "ims" // 镜像服务 + ServiceNameCSBS ServiceNameType = "csbs" // 云服务器备份服务 + ServiceNameCCI ServiceNameType = "cci" // 云容器实例 CCI + ServiceNameBMS ServiceNameType = "bms" // 裸金属服务器 + ServiceNameEVS ServiceNameType = "evs" // 云硬盘 EVS + ServiceNameVBS ServiceNameType = "vbs" // 云硬盘备份 VBS + ServiceNameOBS ServiceNameType = "obs" // 对象存储服务 OBS + ServiceNameVPC ServiceNameType = "vpc" // 虚拟私有云 VPC + ServiceNameELB ServiceNameType = "elb" // 弹性负载均衡 ELB + ServiceNameBSS ServiceNameType = "bss" // 合作伙伴运营能力 + ServiceNameNAT ServiceNameType = "nat" // Nat网关 NAT + ServiceNameDCS ServiceNameType = "dcs" // 分布式缓存服务 + ServiceNameRDS ServiceNameType = "rds" // 关系型数据库 RDS + ServiceNameCTS ServiceNameType = "cts" // 云审计服务 + ServiceNameCES ServiceNameType = "ces" // 监控服务 CloudEye + ServiceNameEPS ServiceNameType = "eps" // 企业项目 ServiceNameSFSTurbo ServiceNameType = "sfs-turbo" // 文件系统 ) diff --git a/pkg/multicloud/huaweistack/region.go b/pkg/multicloud/huaweistack/region.go index 172b495d86..dcdad7a068 100644 --- a/pkg/multicloud/huaweistack/region.go +++ b/pkg/multicloud/huaweistack/region.go @@ -363,7 +363,7 @@ func (self *SRegion) GetI18n() cloudprovider.SModelI18nTable { } func (self *SRegion) GetGlobalId() string { - return fmt.Sprintf("%s/%s", self.client.GetAccessEnv(), self.ID) + return fmt.Sprintf("%s/%s", api.CLOUD_PROVIDER_HUAWEI_CLOUD_STACK, self.ID) } func (self *SRegion) GetStatus() string {