mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-10-25 10:16:12 +08:00
Merge pull request #487 in YUNIONIO/onecloud from ~QUXUAN/onecloud:hotfix/qx-cloudaccount-optimization to release/2.3.0
* commit '1ff0252f3f8ad3ae0db03d8f0d02c084270b5848': 优化cloudprovider删除enable、disable逻辑
This commit is contained in:
@@ -73,12 +73,46 @@ func (self *SCloudaccount) ValidateDeleteCondition(ctx context.Context) error {
|
||||
if self.Enabled {
|
||||
return httperrors.NewInvalidStatusError("account is enabled")
|
||||
}
|
||||
if len(self.GetCloudproviders()) > 0 {
|
||||
return httperrors.NewNotEmptyError("Not an empty cloud account")
|
||||
cloudproviders := self.GetCloudproviders()
|
||||
for i := 0; i < len(cloudproviders); i++ {
|
||||
if err := cloudproviders[i].ValidateDeleteCondition(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return self.SEnabledStatusStandaloneResourceBase.ValidateDeleteCondition(ctx)
|
||||
}
|
||||
|
||||
func (self *SCloudaccount) PerformEnable(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
_, err := self.SEnabledStatusStandaloneResourceBase.PerformEnable(ctx, userCred, query, data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
cloudproviders := self.GetCloudproviders()
|
||||
for i := 0; i < len(cloudproviders); i++ {
|
||||
_, err := cloudproviders[i].PerformEnable(ctx, userCred, query, data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (self *SCloudaccount) PerformDisable(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
_, err := self.SEnabledStatusStandaloneResourceBase.PerformDisable(ctx, userCred, query, data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
cloudproviders := self.GetCloudproviders()
|
||||
for i := 0; i < len(cloudproviders); i++ {
|
||||
_, err := cloudproviders[i].PerformDisable(ctx, userCred, query, data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (self *SCloudaccount) ValidateUpdateData(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) {
|
||||
return self.SEnabledStatusStandaloneResourceBase.ValidateUpdateData(ctx, userCred, query, data)
|
||||
}
|
||||
@@ -119,6 +153,13 @@ func (manager *SCloudaccountManager) ValidateCreateData(ctx context.Context, use
|
||||
return manager.SEnabledStatusStandaloneResourceBaseManager.ValidateCreateData(ctx, userCred, ownerProjId, query, data)
|
||||
}
|
||||
|
||||
func (self *SCloudaccount) PreDelete(ctx context.Context, userCred mcclient.TokenCredential) {
|
||||
cloudproviders := self.GetCloudproviders()
|
||||
for i := 0; i < len(cloudproviders); i++ {
|
||||
cloudproviders[i].Delete(ctx, userCred)
|
||||
}
|
||||
}
|
||||
|
||||
func (self *SCloudaccount) PostCreate(ctx context.Context, userCred mcclient.TokenCredential, ownerProjId string, query jsonutils.JSONObject, data jsonutils.JSONObject) {
|
||||
self.SEnabledStatusStandaloneResourceBase.PostCreate(ctx, userCred, ownerProjId, query, data)
|
||||
self.savePassword(self.Secret)
|
||||
|
||||
Reference in New Issue
Block a user