mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-21 14:19:49 +08:00
Merge pull request #10757 from rainzm/ecloud/validate_fix
Validate creating cloud account data about ecloud
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()
|
||||
|
||||
@@ -52,12 +52,8 @@ func (f *SEcloudProviderFactory) ValidateCreateCloudaccountData(ctx context.Cont
|
||||
if len(input.AccessKeySecret) == 0 {
|
||||
return output, errors.Wrap(httperrors.ErrMissingParameter, "access_key_secret")
|
||||
}
|
||||
if len(input.Environment) == 0 {
|
||||
return output, errors.Wrap(httperrors.ErrMissingParameter, "environment")
|
||||
}
|
||||
output.Account = input.AccessKeyId
|
||||
output.Secret = input.AccessKeySecret
|
||||
output.AccessUrl = input.Environment
|
||||
return output, nil
|
||||
}
|
||||
|
||||
@@ -91,6 +87,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