From a4173448208d7288678e2f24b7cc400bbad4495d Mon Sep 17 00:00:00 2001 From: rainzm Date: Thu, 15 Apr 2021 16:38:12 +0800 Subject: [PATCH] fix(region): try to connect when new a SEcloudClient --- pkg/multicloud/ecloud/client.go | 12 ++++++++++++ pkg/multicloud/ecloud/provider/provider.go | 4 ++++ 2 files changed, 16 insertions(+) diff --git a/pkg/multicloud/ecloud/client.go b/pkg/multicloud/ecloud/client.go index 6a926e9d70..3a2f5e01b5 100644 --- a/pkg/multicloud/ecloud/client.go +++ b/pkg/multicloud/ecloud/client.go @@ -103,6 +103,18 @@ func (ec *SEcloudClient) fetchRegions() { return } +func (ec *SEcloudClient) TryConnect() error { + iregions := ec.GetIRegions() + if len(iregions) == 0 { + return fmt.Errorf("no invalid region for ecloud") + } + _, err := iregions[0].GetIZones() + if err != nil { + return errors.Wrap(err, "try to connect failed") + } + return nil +} + func (ec *SEcloudClient) GetIRegions() []cloudprovider.ICloudRegion { if ec.iregions == nil { ec.fetchRegions() diff --git a/pkg/multicloud/ecloud/provider/provider.go b/pkg/multicloud/ecloud/provider/provider.go index 3399fedcd3..5496347475 100644 --- a/pkg/multicloud/ecloud/provider/provider.go +++ b/pkg/multicloud/ecloud/provider/provider.go @@ -91,6 +91,10 @@ func (f *SEcloudProviderFactory) GetProvider(cfg cloudprovider.ProviderConfig) ( if err != nil { return nil, err } + err = client.TryConnect() + if err != nil { + return nil, err + } return &SEcloudProvider{ SBaseProvider: cloudprovider.NewBaseProvider(f), client: client,