From 0c1027405875e53969e468e58b06b1bc2231aefa Mon Sep 17 00:00:00 2001 From: Qu Xuan Date: Wed, 8 Sep 2021 10:34:32 +0800 Subject: [PATCH] fix(region): apsara default region --- pkg/cloudprovider/endpoints.go | 1 + pkg/mcclient/options/cloudaccounts.go | 1 + pkg/multicloud/apsara/apsara.go | 6 +++++- pkg/multicloud/apsara/provider/provider.go | 3 +++ 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/pkg/cloudprovider/endpoints.go b/pkg/cloudprovider/endpoints.go index 5f4de55e94..3c76f960bc 100644 --- a/pkg/cloudprovider/endpoints.go +++ b/pkg/cloudprovider/endpoints.go @@ -33,6 +33,7 @@ type SApsaraEndpoints struct { RamEndpoint string `default:"$APSARA_RAM_ENDPOINT"` MetricsEndpoint string `default:"$APSRRA_METRICS_ENDPOINT"` ResourcemanagerEndpoint string `default:"$APSARA_RESOURCEMANAGER_ENDPOINT"` + DefaultRegion string `default:"$APSARA_DEFAULT_REGION"` } // SHCSOEndpoints 华为私有云endpoints配置 diff --git a/pkg/mcclient/options/cloudaccounts.go b/pkg/mcclient/options/cloudaccounts.go index 5d4ec112a1..927faf5174 100644 --- a/pkg/mcclient/options/cloudaccounts.go +++ b/pkg/mcclient/options/cloudaccounts.go @@ -866,6 +866,7 @@ func (opts *SVMwareCloudAccountPrepareNetsOptions) Params() (jsonutils.JSONObjec type SApsaraCloudAccountCreateOptions struct { SCloudAccountCreateBaseOptions cloudprovider.SApsaraEndpoints + Endpoint string SAccessKeyCredential } diff --git a/pkg/multicloud/apsara/apsara.go b/pkg/multicloud/apsara/apsara.go index 01c58c432c..c098986738 100644 --- a/pkg/multicloud/apsara/apsara.go +++ b/pkg/multicloud/apsara/apsara.go @@ -301,7 +301,11 @@ func (self *SApsaraClient) trialRequest(apiName string, params map[string]string } func (self *SApsaraClient) fetchRegions() error { - body, err := self.ecsRequest("DescribeRegions", map[string]string{"AcceptLanguage": "zh-CN"}) + params := map[string]string{"AcceptLanguage": "zh-CN"} + if len(self.endpoints.DefaultRegion) > 0 { + params["RegionId"] = self.endpoints.DefaultRegion + } + body, err := self.ecsRequest("DescribeRegions", params) if err != nil { return errors.Wrapf(err, "DescribeRegions") } diff --git a/pkg/multicloud/apsara/provider/provider.go b/pkg/multicloud/apsara/provider/provider.go index 3861e7c324..e2313ee557 100644 --- a/pkg/multicloud/apsara/provider/provider.go +++ b/pkg/multicloud/apsara/provider/provider.go @@ -57,6 +57,9 @@ func (self *SApsaraProviderFactory) ValidateCreateCloudaccountData(ctx context.C return output, httperrors.NewMissingParameterError("endpoint") } output.AccessUrl = input.Endpoint + if input.SApsaraEndpoints == nil || len(input.SApsaraEndpoints.DefaultRegion) == 0 { + return output, httperrors.NewMissingParameterError("default_region") + } return output, nil }