Merge pull request #5403 from swordqiu/hotfix/qj-cloud-provider-perform-enable-should-enable-account

fix: cloudprovider performEnable should also enable its cloudaccount
This commit is contained in:
Zexi Li
2020-03-09 12:30:15 +08:00
committed by GitHub
2 changed files with 11 additions and 11 deletions
+5 -1
View File
@@ -207,11 +207,15 @@ func (self *SCloudaccount) ValidateDeleteCondition(ctx context.Context) error {
return self.SEnabledStatusDomainLevelResourceBase.ValidateDeleteCondition(ctx)
}
func (self *SCloudaccount) enableAccountOnly(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input apis.PerformEnableInput) (jsonutils.JSONObject, error) {
return self.SEnabledStatusDomainLevelResourceBase.PerformEnable(ctx, userCred, query, input)
}
func (self *SCloudaccount) PerformEnable(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input apis.PerformEnableInput) (jsonutils.JSONObject, error) {
if strings.Index(self.Status, "delet") >= 0 {
return nil, httperrors.NewInvalidStatusError("Cannot enable deleting account")
}
_, err := self.SEnabledStatusDomainLevelResourceBase.PerformEnable(ctx, userCred, query, input)
_, err := self.enableAccountOnly(ctx, userCred, query, input)
if err != nil {
return nil, err
}
+6 -10
View File
@@ -18,6 +18,7 @@ import (
"context"
"database/sql"
"fmt"
"strings"
"sync"
"time"
@@ -1277,22 +1278,17 @@ func (self *SCloudprovider) ClearSchedDescCache() error {
}
func (self *SCloudprovider) PerformEnable(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input apis.PerformEnableInput) (jsonutils.JSONObject, error) {
if strings.Index(self.Status, "delet") >= 0 {
return nil, httperrors.NewInvalidStatusError("Cannot enable deleting account")
}
_, err := self.SEnabledStatusStandaloneResourceBase.PerformEnable(ctx, userCred, query, input)
if err != nil {
return nil, err
}
account := self.GetCloudaccount()
if account != nil {
allEnabled := true
providers := account.GetCloudproviders()
for i := range providers {
if !providers[i].GetEnabled() {
allEnabled = false
break
}
}
if allEnabled && !account.GetEnabled() {
return account.PerformEnable(ctx, userCred, nil, input)
if !account.GetEnabled() {
return account.enableAccountOnly(ctx, userCred, nil, input)
}
}
return nil, nil