Merge pull request #5404 from swordqiu/automated-cherry-pick-of-#5403-upstream-release-3.1

Automated cherry pick of #5403: fix: cloudprovider performEnable should also enable its cloudaccount
This commit is contained in:
Zexi Li
2020-03-09 12:30:27 +08:00
committed by GitHub
2 changed files with 10 additions and 9 deletions
+4
View File
@@ -227,6 +227,10 @@ func (self *SCloudaccount) ValidateDeleteCondition(ctx context.Context) error {
return self.SEnabledStatusStandaloneResourceBase.ValidateDeleteCondition(ctx)
}
func (self *SCloudaccount) enableAccountOnly(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
return self.SEnabledStatusStandaloneResourceBase.PerformEnable(ctx, userCred, query, data)
}
func (self *SCloudaccount) PerformEnable(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
if strings.Index(self.Status, "delet") >= 0 {
return nil, httperrors.NewInvalidStatusError("Cannot enable deleting account")
+6 -9
View File
@@ -18,6 +18,7 @@ import (
"context"
"database/sql"
"fmt"
"strings"
"sync"
"time"
@@ -1239,21 +1240,17 @@ func (self *SCloudprovider) ClearSchedDescCache() error {
}
func (self *SCloudprovider) PerformEnable(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (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, data)
if err != nil {
return nil, err
}
account := self.GetCloudaccount()
if account != nil {
allEnabled := true
providers := account.GetCloudproviders()
for i := range providers {
if !providers[i].Enabled {
allEnabled = false
}
}
if allEnabled && !account.Enabled {
return account.PerformEnable(ctx, userCred, nil, nil)
if !account.Enabled {
return account.enableAccountOnly(ctx, userCred, nil, nil)
}
}
return nil, nil