fix(region): try to connect when new a SEcloudClient

This commit is contained in:
rainzm
2021-04-15 16:38:12 +08:00
parent 453c4cb99f
commit a417344820
2 changed files with 16 additions and 0 deletions
+12
View File
@@ -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()
@@ -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,