mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix(region): try to connect when new a SEcloudClient
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user