mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-08-30 17:13:08 +08:00
fix(region): optimized validate delete condition query
This commit is contained in:
@@ -121,7 +121,7 @@ func (man *SAnsiblePlaybookManager) InitializeData() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (apb *SAnsiblePlaybook) ValidateDeleteCondition(ctx context.Context) error {
|
||||
func (apb *SAnsiblePlaybook) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
if apb.Status == api.AnsiblePlaybookStatusRunning {
|
||||
return httperrors.NewConflictError("playbook is in running state")
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ func (man *SAnsiblePlaybookV2Manager) InitializeData() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (apb *SAnsiblePlaybookV2) ValidateDeleteCondition(ctx context.Context) error {
|
||||
func (apb *SAnsiblePlaybookV2) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
if apb.Status == api.AnsiblePlaybookStatusRunning {
|
||||
return httperrors.NewConflictError("playbook is in running state")
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import (
|
||||
"yunion.io/x/pkg/gotypes"
|
||||
"yunion.io/x/sqlchemy"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/pkg/util/stringutils2"
|
||||
@@ -284,12 +285,32 @@ func FetchCustomizeColumns(
|
||||
if ret[0].Len() != len(objs) {
|
||||
return nil, httperrors.NewInternalServerError("Invalid FetchCustomizeColumns return value, inconsistent obj count: input %d != output %d", len(objs), ret[0].Len())
|
||||
}
|
||||
|
||||
showReason := false
|
||||
if query.Contains("show_fail_reason") {
|
||||
showReason = true
|
||||
}
|
||||
|
||||
retVal := make([]*jsonutils.JSONDict, ret[0].Len())
|
||||
for i := 0; i < ret[0].Len(); i += 1 {
|
||||
jsonDict := ValueToJSONDict(ret[0].Index(i))
|
||||
// NOTE: don't use obj update jsonDict as retval
|
||||
jsonDict.Update(jsonutils.Marshal(objs[i]).(*jsonutils.JSONDict))
|
||||
out := apis.ModelBaseDetails{
|
||||
CanDelete: true,
|
||||
}
|
||||
|
||||
err = ValidateDeleteCondition(objs[i].(IModel), ctx, jsonDict)
|
||||
if err != nil {
|
||||
out.CanDelete = false
|
||||
if showReason {
|
||||
out.DeleteFailReason = httperrors.NewErrorFromGeneralError(ctx, err)
|
||||
}
|
||||
}
|
||||
jsonDict.Update(jsonutils.Marshal(out))
|
||||
|
||||
retVal[i] = jsonDict
|
||||
|
||||
}
|
||||
return retVal, nil
|
||||
}
|
||||
@@ -319,3 +340,14 @@ func CustomizeDelete(model IModel, ctx context.Context, userCred mcclient.TokenC
|
||||
}
|
||||
return ValueToError(ret[0])
|
||||
}
|
||||
|
||||
func ValidateDeleteCondition(model IModel, ctx context.Context, data jsonutils.JSONObject) error {
|
||||
ret, err := call(model, "ValidateDeleteCondition", ctx, data)
|
||||
if err != nil {
|
||||
return httperrors.NewGeneralError(err)
|
||||
}
|
||||
if len(ret) != 1 {
|
||||
return httperrors.NewInternalServerError("Invald ValidateDeleteCondition return value")
|
||||
}
|
||||
return ValueToError(ret[0])
|
||||
}
|
||||
|
||||
@@ -854,17 +854,9 @@ func (dispatcher *DBModelDispatcher) List(ctx context.Context, query jsonutils.J
|
||||
|
||||
func getModelExtraDetails(item IModel, ctx context.Context, showReason bool) apis.ModelBaseDetails {
|
||||
out := apis.ModelBaseDetails{
|
||||
CanDelete: true,
|
||||
CanUpdate: true,
|
||||
}
|
||||
err := item.ValidateDeleteCondition(ctx)
|
||||
if err != nil {
|
||||
out.CanDelete = false
|
||||
if showReason {
|
||||
out.DeleteFailReason = httperrors.NewErrorFromGeneralError(ctx, err)
|
||||
}
|
||||
}
|
||||
err = item.ValidateUpdateCondition(ctx)
|
||||
err := item.ValidateUpdateCondition(ctx)
|
||||
if err != nil {
|
||||
out.CanUpdate = false
|
||||
if showReason {
|
||||
@@ -1834,9 +1826,9 @@ func DeleteModel(ctx context.Context, userCred mcclient.TokenCredential, item IM
|
||||
|
||||
func deleteItem(manager IModelManager, model IModel, ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
// log.Debugf("deleteItem %s", jsonutils.Marshal(model))
|
||||
err := model.ValidateDeleteCondition(ctx)
|
||||
|
||||
err := ValidateDeleteCondition(model, ctx, nil)
|
||||
if err != nil {
|
||||
log.Errorf("validate delete condition error: %s", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
@@ -286,7 +286,7 @@ func (dispatcher *DBJointModelDispatcher) Detach(ctx context.Context, id1 string
|
||||
}
|
||||
|
||||
func DetachJoint(ctx context.Context, userCred mcclient.TokenCredential, item IJointModel) error {
|
||||
err := item.ValidateDeleteCondition(ctx)
|
||||
err := ValidateDeleteCondition(item, ctx, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -181,7 +181,7 @@ type IModel interface {
|
||||
|
||||
// delete hooks
|
||||
AllowDeleteItem(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool
|
||||
ValidateDeleteCondition(ctx context.Context) error
|
||||
// ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error
|
||||
// CustomizeDelete(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) error
|
||||
PreDelete(ctx context.Context, userCred mcclient.TokenCredential)
|
||||
MarkDelete() error
|
||||
|
||||
@@ -580,7 +580,7 @@ func (model *SModelBase) ValidateUpdateCondition(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (model *SModelBase) ValidateDeleteCondition(ctx context.Context) error {
|
||||
func (model *SModelBase) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -363,7 +363,7 @@ func (self *SOpsLog) AllowDeleteItem(ctx context.Context, userCred mcclient.Toke
|
||||
return false
|
||||
}
|
||||
|
||||
func (self *SOpsLog) ValidateDeleteCondition(ctx context.Context) error {
|
||||
func (self *SOpsLog) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
return httperrors.NewForbiddenError("not allow to delete log")
|
||||
}
|
||||
|
||||
|
||||
@@ -106,7 +106,7 @@ func (ps *SProxySetting) HttpTransportProxyFunc() httputils.TransportProxyFunc {
|
||||
}
|
||||
}
|
||||
|
||||
func (ps *SProxySetting) ValidateDeleteCondition(ctx context.Context) error {
|
||||
func (ps *SProxySetting) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
if ps.Id == proxyapi.ProxySettingId_DIRECT {
|
||||
return httperrors.NewConflictError("DIRECT setting cannot be deleted")
|
||||
}
|
||||
@@ -122,7 +122,7 @@ func (ps *SProxySetting) ValidateDeleteCondition(ctx context.Context) error {
|
||||
ps.Id, n, man.KeywordPlural())
|
||||
}
|
||||
}
|
||||
return ps.SInfrasResourceBase.ValidateDeleteCondition(ctx)
|
||||
return ps.SInfrasResourceBase.ValidateDeleteCondition(ctx, nil)
|
||||
}
|
||||
|
||||
func (ps *SProxySetting) AllowPerformTest(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool {
|
||||
|
||||
@@ -173,7 +173,7 @@ func (self *STask) AllowDeleteItem(ctx context.Context, userCred mcclient.TokenC
|
||||
return false
|
||||
}
|
||||
|
||||
func (self *STask) ValidateDeleteCondition(ctx context.Context) error {
|
||||
func (self *STask) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
return httperrors.NewForbiddenError("forbidden")
|
||||
}
|
||||
|
||||
|
||||
@@ -262,7 +262,7 @@ func (self *SCloudpolicy) GetCloudgroups() ([]SCloudgroup, error) {
|
||||
return groups, nil
|
||||
}
|
||||
|
||||
func (self *SCloudpolicy) ValidateDeleteCondition(ctx context.Context) error {
|
||||
func (self *SCloudpolicy) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
users, err := self.GetCloudusers()
|
||||
if err != nil {
|
||||
return httperrors.NewGeneralError(errors.Wrapf(err, "GetCloudusers"))
|
||||
@@ -277,14 +277,14 @@ func (self *SCloudpolicy) ValidateDeleteCondition(ctx context.Context) error {
|
||||
if len(groups) > 0 {
|
||||
return httperrors.NewNotEmptyError("policy %s has %d groups used", self.Name, len(groups))
|
||||
}
|
||||
return self.SStatusInfrasResourceBase.ValidateDeleteCondition(ctx)
|
||||
return self.SStatusInfrasResourceBase.ValidateDeleteCondition(ctx, nil)
|
||||
}
|
||||
|
||||
func (self *SCloudpolicy) syncRemove(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
lockman.LockObject(ctx, self)
|
||||
defer lockman.ReleaseObject(ctx, self)
|
||||
|
||||
err := self.ValidateDeleteCondition(ctx)
|
||||
err := self.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ func (iface *SIface) ValidateUpdateCondition(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (iface *SIface) ValidateDeleteCondition(ctx context.Context) error {
|
||||
func (iface *SIface) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
// if networkid != "" {
|
||||
// return errors.New("part of network, remove it by remove network memeber")
|
||||
// }
|
||||
|
||||
@@ -79,7 +79,7 @@ func (proxyagent *SProxyAgent) ValidateUpdateData(ctx context.Context, userCred
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func (proxyagent *SProxyAgent) ValidateDeleteCondition(ctx context.Context) error {
|
||||
func (proxyagent *SProxyAgent) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
q := ForwardManager.Query().Equals("proxy_agent_id", proxyagent.Id)
|
||||
if count, err := q.CountWithError(); err != nil {
|
||||
return httperrors.NewServerError("count forwards using proxy endpoint %s(%s)",
|
||||
|
||||
@@ -231,7 +231,7 @@ func (proxyendpoint *SProxyEndpoint) ValidateUpdateData(ctx context.Context, use
|
||||
return input, nil
|
||||
}
|
||||
|
||||
func (proxyendpoint *SProxyEndpoint) ValidateDeleteCondition(ctx context.Context) error {
|
||||
func (proxyendpoint *SProxyEndpoint) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
q := ForwardManager.Query().Equals("proxy_endpoint_id", proxyendpoint.Id)
|
||||
if count, err := q.CountWithError(); err != nil {
|
||||
return httperrors.NewServerError("count forwards using proxy endpoint %s(%s)",
|
||||
|
||||
@@ -594,14 +594,14 @@ func (manager *SAccessGroupCacheManager) Register(ctx context.Context, opts *SAc
|
||||
return cache, cache.CreateIAccessGroup()
|
||||
}
|
||||
|
||||
func (self *SAccessGroupCache) ValidateDeleteCondition(ctx context.Context) error {
|
||||
func (self *SAccessGroupCache) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
if self.AccessGroupId == api.DEFAULT_ACCESS_GROUP {
|
||||
return httperrors.NewProtectedResourceError("not allow to delete default access group")
|
||||
}
|
||||
if self.MountTargetCount > 0 && self.Status != api.ACCESS_GROUP_STATUS_UNKNOWN {
|
||||
return httperrors.NewNotEmptyError("access group not empty, please delete mount target first")
|
||||
}
|
||||
return self.SStatusStandaloneResourceBase.ValidateDeleteCondition(ctx)
|
||||
return self.SStatusStandaloneResourceBase.ValidateDeleteCondition(ctx, nil)
|
||||
}
|
||||
|
||||
func (self *SAccessGroupCache) CustomizeDelete(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) error {
|
||||
|
||||
@@ -351,11 +351,11 @@ func (self *SAccessGroupRule) PreDelete(ctx context.Context, userCred mcclient.T
|
||||
}
|
||||
}
|
||||
|
||||
func (self *SAccessGroupRule) ValidateDeleteCondition(ctx context.Context) error {
|
||||
func (self *SAccessGroupRule) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
if self.AccessGroupId == api.DEFAULT_ACCESS_GROUP {
|
||||
return httperrors.NewProtectedResourceError("not allow to delete default access group rule")
|
||||
}
|
||||
return self.SResourceBase.ValidateDeleteCondition(ctx)
|
||||
return self.SResourceBase.ValidateDeleteCondition(ctx, nil)
|
||||
}
|
||||
|
||||
func (manager *SAccessGroupRuleManager) InitializeData() error {
|
||||
|
||||
@@ -250,7 +250,7 @@ func (self *SAccessGroup) RealDelete(ctx context.Context, userCred mcclient.Toke
|
||||
return self.SStatusInfrasResourceBase.Delete(ctx, userCred)
|
||||
}
|
||||
|
||||
func (self *SAccessGroup) ValidateDeleteCondition(ctx context.Context) error {
|
||||
func (self *SAccessGroup) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
if self.Id == api.DEFAULT_ACCESS_GROUP {
|
||||
return httperrors.NewProtectedResourceError("not allow to delete default access group")
|
||||
}
|
||||
@@ -261,7 +261,7 @@ func (self *SAccessGroup) ValidateDeleteCondition(ctx context.Context) error {
|
||||
if len(mts) > 0 {
|
||||
return httperrors.NewNotEmptyError("access group not empty, please delete mount target first")
|
||||
}
|
||||
return self.SStatusInfrasResourceBase.ValidateDeleteCondition(ctx)
|
||||
return self.SStatusInfrasResourceBase.ValidateDeleteCondition(ctx, nil)
|
||||
}
|
||||
|
||||
func (self *SAccessGroup) DoSync(ctx context.Context, userCred mcclient.TokenCredential) {
|
||||
|
||||
@@ -65,18 +65,18 @@ func init() {
|
||||
BaremetalagentManager.SetVirtualObject(BaremetalagentManager)
|
||||
}
|
||||
|
||||
func (self *SBaremetalagent) ValidateDeleteCondition(ctx context.Context) error {
|
||||
func (self *SBaremetalagent) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
if self.Status == api.BAREMETAL_AGENT_ENABLED {
|
||||
return fmt.Errorf("Cannot delete in status %s", self.Status)
|
||||
}
|
||||
storageCache, _ := self.getStorageCache()
|
||||
if storageCache != nil {
|
||||
err := storageCache.ValidateDeleteCondition(ctx)
|
||||
err := storageCache.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil {
|
||||
return fmt.Errorf("storagecache cannot be delete: %s", err)
|
||||
}
|
||||
}
|
||||
return self.SStandaloneResourceBase.ValidateDeleteCondition(ctx)
|
||||
return self.SStandaloneResourceBase.ValidateDeleteCondition(ctx, nil)
|
||||
}
|
||||
|
||||
func (self *SBaremetalagent) ValidateUpdateData(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input api.BaremetalagentUpdateInput) (api.BaremetalagentUpdateInput, error) {
|
||||
|
||||
@@ -1182,12 +1182,12 @@ func (bucket *SBucket) PerformSync(
|
||||
}
|
||||
|
||||
func (bucket *SBucket) ValidatePurgeCondition(ctx context.Context) error {
|
||||
return bucket.SSharableVirtualResourceBase.ValidateDeleteCondition(ctx)
|
||||
return bucket.SSharableVirtualResourceBase.ValidateDeleteCondition(ctx, nil)
|
||||
}
|
||||
|
||||
func (bucket *SBucket) ValidateDeleteCondition(ctx context.Context) error {
|
||||
func (bucket *SBucket) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
if bucket.Status == api.BUCKET_STATUS_UNKNOWN {
|
||||
return bucket.SSharableVirtualResourceBase.ValidateDeleteCondition(ctx)
|
||||
return bucket.SSharableVirtualResourceBase.ValidateDeleteCondition(ctx, nil)
|
||||
}
|
||||
if bucket.ObjectCnt > 0 {
|
||||
return httperrors.NewNotEmptyError("Buckets that are not empty do not support this operation")
|
||||
|
||||
@@ -101,7 +101,7 @@ func (self SCachedimage) GetGlobalId() string {
|
||||
return self.ExternalId
|
||||
}
|
||||
|
||||
func (self *SCachedimage) ValidateDeleteCondition(ctx context.Context) error {
|
||||
func (self *SCachedimage) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
cnt, err := self.getStoragecacheCount()
|
||||
if err != nil {
|
||||
return httperrors.NewInternalServerError("ValidateDeleteCondition error %s", err)
|
||||
@@ -112,7 +112,7 @@ func (self *SCachedimage) ValidateDeleteCondition(ctx context.Context) error {
|
||||
if self.GetStatus() == api.CACHED_IMAGE_STATUS_ACTIVE && !self.isReferenceSessionExpire() {
|
||||
return httperrors.NewConflictError("the image reference session has not been expired!")
|
||||
}
|
||||
return self.SSharableVirtualResourceBase.ValidateDeleteCondition(ctx)
|
||||
return self.SSharableVirtualResourceBase.ValidateDeleteCondition(ctx, nil)
|
||||
}
|
||||
|
||||
func (self *SCachedimage) isReferenceSessionExpire() bool {
|
||||
|
||||
@@ -161,7 +161,7 @@ func (self *SCDNDomain) syncRemoveCloudCDNDomain(ctx context.Context, userCred m
|
||||
|
||||
self.DeletePreventionOff(self, userCred)
|
||||
|
||||
err := self.ValidateDeleteCondition(ctx)
|
||||
err := self.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "ValidateDeleteCondition")
|
||||
}
|
||||
|
||||
@@ -203,7 +203,7 @@ func (self *SCloudaccount) getCloudprovidersInternal(enabled tristate.TriState)
|
||||
return cloudproviders
|
||||
}
|
||||
|
||||
func (self *SCloudaccount) ValidateDeleteCondition(ctx context.Context) error {
|
||||
func (self *SCloudaccount) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
// allow delete cloudaccount if it is disabled
|
||||
// if self.EnableAutoSync {
|
||||
// return httperrors.NewInvalidStatusError("automatic syncing is enabled")
|
||||
@@ -216,12 +216,12 @@ func (self *SCloudaccount) ValidateDeleteCondition(ctx context.Context) error {
|
||||
}
|
||||
cloudproviders := self.GetCloudproviders()
|
||||
for i := 0; i < len(cloudproviders); i++ {
|
||||
if err := cloudproviders[i].ValidateDeleteCondition(ctx); err != nil {
|
||||
if err := cloudproviders[i].ValidateDeleteCondition(ctx, nil); err != nil {
|
||||
return httperrors.NewInvalidStatusError("provider %s: %v", cloudproviders[i].Name, err)
|
||||
}
|
||||
}
|
||||
|
||||
return self.SEnabledStatusInfrasResourceBase.ValidateDeleteCondition(ctx)
|
||||
return self.SEnabledStatusInfrasResourceBase.ValidateDeleteCondition(ctx, nil)
|
||||
}
|
||||
|
||||
func (self *SCloudaccount) enableAccountOnly(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input apis.PerformEnableInput) (jsonutils.JSONObject, error) {
|
||||
|
||||
@@ -84,7 +84,7 @@ func (self *SCloudimage) syncRemove(ctx context.Context, userCred mcclient.Token
|
||||
}
|
||||
image := _image.(*SCachedimage)
|
||||
|
||||
err = image.ValidateDeleteCondition(ctx)
|
||||
err = image.ValidateDeleteCondition(ctx, nil)
|
||||
if err == nil {
|
||||
image.Delete(ctx, userCred)
|
||||
}
|
||||
|
||||
@@ -171,7 +171,7 @@ func (manager *SCloudproviderregion) ValidateCreateData(ctx context.Context, use
|
||||
return nil, httperrors.NewForbiddenError("not allow to create")
|
||||
}
|
||||
|
||||
func (self *SCloudproviderregion) ValidateDeleteCondition(ctx context.Context) error {
|
||||
func (self *SCloudproviderregion) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -173,7 +173,7 @@ func (self *SCloudprovider) GetProjectMapping() (*SProjectMapping, error) {
|
||||
return cache.GetProjectMapping()
|
||||
}
|
||||
|
||||
func (self *SCloudprovider) ValidateDeleteCondition(ctx context.Context) error {
|
||||
func (self *SCloudprovider) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
// allow delete cloudprovider if it is disabled
|
||||
// account := self.GetCloudaccount()
|
||||
// if account != nil && account.EnableAutoSync {
|
||||
@@ -189,7 +189,7 @@ func (self *SCloudprovider) ValidateDeleteCondition(ctx context.Context) error {
|
||||
// if !usage.isEmpty() {
|
||||
// return httperrors.NewNotEmptyError("Not an empty cloud provider")
|
||||
// }
|
||||
return self.SEnabledStatusStandaloneResourceBase.ValidateDeleteCondition(ctx)
|
||||
return self.SEnabledStatusStandaloneResourceBase.ValidateDeleteCondition(ctx, nil)
|
||||
}
|
||||
|
||||
func (manager *SCloudproviderManager) GetPublicProviderIdsQuery() *sqlchemy.SSubQuery {
|
||||
|
||||
@@ -103,7 +103,7 @@ func (self *SCloudregion) CustomizeCreate(ctx context.Context, userCred mcclient
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SCloudregion) ValidateDeleteCondition(ctx context.Context) error {
|
||||
func (self *SCloudregion) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
zoneCnt, err := self.GetZoneCount()
|
||||
if err != nil {
|
||||
return httperrors.NewInternalServerError("GetZoneCount fail %s", err)
|
||||
@@ -118,7 +118,7 @@ func (self *SCloudregion) ValidateDeleteCondition(ctx context.Context) error {
|
||||
if self.Id == api.DEFAULT_REGION_ID {
|
||||
return httperrors.NewProtectedResourceError("not allow to delete default cloud region")
|
||||
}
|
||||
return self.SEnabledStatusStandaloneResourceBase.ValidateDeleteCondition(ctx)
|
||||
return self.SEnabledStatusStandaloneResourceBase.ValidateDeleteCondition(ctx, nil)
|
||||
}
|
||||
|
||||
func (self *SCloudregion) GetElasticIps(managerId, eipMode string) ([]SElasticip, error) {
|
||||
|
||||
@@ -1495,11 +1495,11 @@ func (self *SDBInstance) syncRemoveCloudDBInstance(ctx context.Context, userCred
|
||||
return self.Purge(ctx, userCred)
|
||||
}
|
||||
|
||||
func (self *SDBInstance) ValidateDeleteCondition(ctx context.Context) error {
|
||||
func (self *SDBInstance) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
if self.DisableDelete.IsTrue() {
|
||||
return httperrors.NewInvalidStatusError("DBInstance is locked, cannot delete")
|
||||
}
|
||||
return self.SStatusStandaloneResourceBase.ValidateDeleteCondition(ctx)
|
||||
return self.SStatusStandaloneResourceBase.ValidateDeleteCondition(ctx, nil)
|
||||
}
|
||||
|
||||
func (self *SDBInstance) GetDBInstanceSkuQuery(skipZoneCheck bool) *sqlchemy.SQuery {
|
||||
|
||||
@@ -1078,7 +1078,7 @@ func (self *SDisk) StartDiskSaveTask(ctx context.Context, userCred mcclient.Toke
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SDisk) ValidateDeleteCondition(ctx context.Context) error {
|
||||
func (self *SDisk) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
provider := self.GetCloudprovider()
|
||||
if provider != nil {
|
||||
if !provider.IsAvailable() {
|
||||
@@ -1120,7 +1120,7 @@ func (self *SDisk) validateDeleteCondition(ctx context.Context, isPurge bool) er
|
||||
if !isPurge && self.IsNotDeletablePrePaid() {
|
||||
return httperrors.NewForbiddenError("not allow to delete prepaid disk in valid status")
|
||||
}
|
||||
return self.SVirtualResourceBase.ValidateDeleteCondition(ctx)
|
||||
return self.SVirtualResourceBase.ValidateDeleteCondition(ctx, nil)
|
||||
}
|
||||
|
||||
func (self *SDisk) AllowDeleteItem(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool {
|
||||
|
||||
@@ -339,11 +339,11 @@ func (man *SElasticSearchManager) TotalCount(
|
||||
}
|
||||
|
||||
// 判断资源是否可以删除
|
||||
func (self *SElasticSearch) ValidateDeleteCondition(ctx context.Context) error {
|
||||
func (self *SElasticSearch) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
if self.DisableDelete.IsTrue() {
|
||||
return httperrors.NewInvalidStatusError("ElasticSearch is locked, cannot delete")
|
||||
}
|
||||
return self.SStatusStandaloneResourceBase.ValidateDeleteCondition(ctx)
|
||||
return self.SStatusStandaloneResourceBase.ValidateDeleteCondition(ctx, nil)
|
||||
}
|
||||
|
||||
func (self *SElasticSearch) Delete(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
|
||||
@@ -130,7 +130,7 @@ func (self *SElasticcacheAccount) syncRemoveCloudElasticcacheAccount(ctx context
|
||||
lockman.LockObject(ctx, self)
|
||||
defer lockman.ReleaseObject(ctx, self)
|
||||
|
||||
err := self.ValidateDeleteCondition(ctx)
|
||||
err := self.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "newFromCloudElasticcacheAccount.Remove")
|
||||
}
|
||||
|
||||
@@ -126,7 +126,7 @@ func (self *SElasticcacheAcl) syncRemoveCloudElasticcacheAcl(ctx context.Context
|
||||
lockman.LockObject(ctx, self)
|
||||
defer lockman.ReleaseObject(ctx, self)
|
||||
|
||||
err := self.ValidateDeleteCondition(ctx)
|
||||
err := self.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "newFromCloudElasticcacheAcl.Remove")
|
||||
}
|
||||
@@ -311,7 +311,7 @@ func (self *SElasticcacheAcl) StartUpdateElasticcacheAclTask(ctx context.Context
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SElasticcacheAcl) ValidateDeleteCondition(ctx context.Context) error {
|
||||
func (self *SElasticcacheAcl) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -139,7 +139,7 @@ func (self *SElasticcacheBackup) syncRemoveCloudElasticcacheBackup(ctx context.C
|
||||
lockman.LockObject(ctx, self)
|
||||
defer lockman.ReleaseObject(ctx, self)
|
||||
|
||||
err := self.ValidateDeleteCondition(ctx)
|
||||
err := self.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "newFromCloudElasticcacheBackup.Remove")
|
||||
}
|
||||
@@ -332,7 +332,7 @@ func (self *SElasticcacheBackup) GetRegion() *SCloudregion {
|
||||
return region
|
||||
}
|
||||
|
||||
func (self *SElasticcacheBackup) ValidateDeleteCondition(ctx context.Context) error {
|
||||
func (self *SElasticcacheBackup) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
icache, err := db.FetchById(ElasticcacheManager, self.ElasticcacheId)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -1193,7 +1193,7 @@ func (self *SElasticcache) StartRestartTask(ctx context.Context, userCred mcclie
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SElasticcache) ValidateDeleteCondition(ctx context.Context) error {
|
||||
func (self *SElasticcache) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
if self.DisableDelete.IsTrue() {
|
||||
return httperrors.NewInvalidStatusError("Elastic cache is locked, cannot delete")
|
||||
}
|
||||
@@ -1206,7 +1206,7 @@ func (self *SElasticcache) ValidateDeleteCondition(ctx context.Context) error {
|
||||
}
|
||||
|
||||
func (self *SElasticcache) ValidatePurgeCondition(ctx context.Context) error {
|
||||
return self.SVirtualResourceBase.ValidateDeleteCondition(ctx)
|
||||
return self.SVirtualResourceBase.ValidateDeleteCondition(ctx, nil)
|
||||
}
|
||||
|
||||
func (self *SElasticcache) CustomizeDelete(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) error {
|
||||
|
||||
@@ -134,7 +134,7 @@ func (self *SElasticcacheParameter) syncRemoveCloudElasticcacheParameter(ctx con
|
||||
lockman.LockObject(ctx, self)
|
||||
defer lockman.ReleaseObject(ctx, self)
|
||||
|
||||
err := self.ValidateDeleteCondition(ctx)
|
||||
err := self.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "newFromCloudElasticcacheParameter.Remove")
|
||||
}
|
||||
|
||||
@@ -930,11 +930,11 @@ func (self *SElasticip) CustomizeDelete(ctx context.Context, userCred mcclient.T
|
||||
return self.StartEipDeallocateTask(ctx, userCred, "")
|
||||
}
|
||||
|
||||
func (self *SElasticip) ValidateDeleteCondition(ctx context.Context) error {
|
||||
func (self *SElasticip) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
if self.IsAssociated() {
|
||||
return fmt.Errorf("eip is associated with resources")
|
||||
}
|
||||
return self.SVirtualResourceBase.ValidateDeleteCondition(ctx)
|
||||
return self.SVirtualResourceBase.ValidateDeleteCondition(ctx, nil)
|
||||
}
|
||||
|
||||
func (self *SElasticip) StartEipDeallocateTask(ctx context.Context, userCred mcclient.TokenCredential, parentTaskId string) error {
|
||||
@@ -1491,7 +1491,7 @@ func (self *SElasticip) AllowPerformPurge(ctx context.Context, userCred mcclient
|
||||
}
|
||||
|
||||
func (self *SElasticip) PerformPurge(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
err := self.ValidateDeleteCondition(ctx)
|
||||
err := self.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -376,7 +376,7 @@ func (self *SFileSystem) syncRemove(ctx context.Context, userCred mcclient.Token
|
||||
|
||||
self.DeletePreventionOff(self, userCred)
|
||||
|
||||
err := self.ValidateDeleteCondition(ctx)
|
||||
err := self.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil { // cannot delete
|
||||
return self.SetStatus(userCred, api.NAS_STATUS_UNKNOWN, "sync to delete")
|
||||
}
|
||||
@@ -423,11 +423,11 @@ func (self *SFileSystem) RealDelete(ctx context.Context, userCred mcclient.Token
|
||||
return self.SInfrasResourceBase.Delete(ctx, userCred)
|
||||
}
|
||||
|
||||
func (self *SFileSystem) ValidateDeleteCondition(ctx context.Context) error {
|
||||
func (self *SFileSystem) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
if self.DisableDelete.IsTrue() {
|
||||
return httperrors.NewInvalidStatusError("FileSystem is locked, cannot delete")
|
||||
}
|
||||
return self.SStatusInfrasResourceBase.ValidateDeleteCondition(ctx)
|
||||
return self.SStatusInfrasResourceBase.ValidateDeleteCondition(ctx, nil)
|
||||
}
|
||||
|
||||
func (self *SFileSystem) SyncAllWithCloudFileSystem(ctx context.Context, userCred mcclient.TokenCredential, fs cloudprovider.ICloudFileSystem) error {
|
||||
|
||||
@@ -58,7 +58,7 @@ func (manager *SGlobalVpcManager) AllowCreateItem(ctx context.Context, userCred
|
||||
return db.IsAdminAllowCreate(userCred, manager)
|
||||
}
|
||||
|
||||
func (self *SGlobalVpc) ValidateDeleteCondition(ctx context.Context) error {
|
||||
func (self *SGlobalVpc) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
vpcs, err := self.GetVpcs()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "self.GetVpcs")
|
||||
@@ -66,7 +66,7 @@ func (self *SGlobalVpc) ValidateDeleteCondition(ctx context.Context) error {
|
||||
if len(vpcs) > 0 {
|
||||
return fmt.Errorf("not an empty globalvpc")
|
||||
}
|
||||
return self.SEnabledStatusInfrasResourceBase.ValidateDeleteCondition(ctx)
|
||||
return self.SEnabledStatusInfrasResourceBase.ValidateDeleteCondition(ctx, nil)
|
||||
}
|
||||
|
||||
func (self *SGlobalVpc) GetVpcQuery() *sqlchemy.SQuery {
|
||||
|
||||
@@ -198,7 +198,7 @@ func (group *SGroup) GetGuestCount() int {
|
||||
return count
|
||||
}
|
||||
|
||||
func (group *SGroup) ValidateDeleteCondition(ctx context.Context) error {
|
||||
func (group *SGroup) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
q := GroupguestManager.Query().Equals("group_id", group.Id)
|
||||
count, err := q.CountWithError()
|
||||
if err != nil {
|
||||
|
||||
@@ -591,7 +591,7 @@ func (gt *SGuestTemplate) genForbiddenError(resourceName, resourceStr, scope str
|
||||
return httperrors.NewForbiddenError(msgFmt, msgArgs...)
|
||||
}
|
||||
|
||||
func (gt *SGuestTemplate) ValidateDeleteCondition(ctx context.Context) error {
|
||||
func (gt *SGuestTemplate) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
// check service catelog
|
||||
q := ServiceCatalogManager.Query("name").Equals("guest_template_id", gt.Id)
|
||||
names := make([]struct{ Name string }, 0, 1)
|
||||
|
||||
@@ -676,14 +676,14 @@ func (guest *SGuest) validateDeleteCondition(ctx context.Context, isPurge bool)
|
||||
if !isPurge && guest.IsNotDeletablePrePaid() {
|
||||
return httperrors.NewForbiddenError("not allow to delete prepaid server in valid status")
|
||||
}
|
||||
return guest.SVirtualResourceBase.ValidateDeleteCondition(ctx)
|
||||
return guest.SVirtualResourceBase.ValidateDeleteCondition(ctx, nil)
|
||||
}
|
||||
|
||||
func (guest *SGuest) ValidatePurgeCondition(ctx context.Context) error {
|
||||
return guest.validateDeleteCondition(ctx, true)
|
||||
}
|
||||
|
||||
func (guest *SGuest) ValidateDeleteCondition(ctx context.Context) error {
|
||||
func (guest *SGuest) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
host, _ := guest.GetHost()
|
||||
if host != nil && guest.GetHypervisor() != api.HYPERVISOR_BAREMETAL {
|
||||
if !host.GetEnabled() {
|
||||
|
||||
@@ -630,7 +630,7 @@ func (self *SHost) AllowDeleteItem(ctx context.Context, userCred mcclient.TokenC
|
||||
return userCred.IsSystemAdmin()
|
||||
}*/
|
||||
|
||||
func (self *SHost) ValidateDeleteCondition(ctx context.Context) error {
|
||||
func (self *SHost) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
return self.validateDeleteCondition(ctx, false)
|
||||
}
|
||||
|
||||
@@ -665,7 +665,7 @@ func (self *SHost) validateDeleteCondition(ctx context.Context, purge bool) erro
|
||||
}
|
||||
|
||||
}
|
||||
return self.SEnabledStatusInfrasResourceBase.ValidateDeleteCondition(ctx)
|
||||
return self.SEnabledStatusInfrasResourceBase.ValidateDeleteCondition(ctx, nil)
|
||||
}
|
||||
|
||||
func (self *SHost) Delete(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
@@ -2147,7 +2147,7 @@ func (self *SHost) SyncHostStorages(ctx context.Context, userCred mcclient.Token
|
||||
|
||||
func (self *SHost) syncRemoveCloudHostStorage(ctx context.Context, userCred mcclient.TokenCredential, localStorage *SStorage) error {
|
||||
hs := self.GetHoststorageOfId(localStorage.Id)
|
||||
err := hs.ValidateDeleteCondition(ctx)
|
||||
err := hs.ValidateDeleteCondition(ctx, nil)
|
||||
if err == nil {
|
||||
log.Errorf("sync remove hoststorage fail: %s", err)
|
||||
err = hs.Detach(ctx, userCred)
|
||||
|
||||
@@ -300,7 +300,7 @@ func (self *SHoststorage) GetGuestDiskCount() (int, error) {
|
||||
return q.CountWithError()
|
||||
}
|
||||
|
||||
func (self *SHoststorage) ValidateDeleteCondition(ctx context.Context) error {
|
||||
func (self *SHoststorage) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
cnt, err := self.GetGuestDiskCount()
|
||||
if err != nil {
|
||||
return httperrors.NewInternalServerError("GetGuestDiskCount fail %s", err)
|
||||
@@ -308,7 +308,7 @@ func (self *SHoststorage) ValidateDeleteCondition(ctx context.Context) error {
|
||||
if cnt > 0 {
|
||||
return errors.Wrap(ErrStorageInUse, "guest on the host are using disks on this storage")
|
||||
}
|
||||
return self.SHostJointsBase.ValidateDeleteCondition(ctx)
|
||||
return self.SHostJointsBase.ValidateDeleteCondition(ctx, nil)
|
||||
}
|
||||
|
||||
func (self *SHoststorage) Delete(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
|
||||
@@ -146,7 +146,7 @@ func (self *SHostwire) GetGuestnicsCount() (int, error) {
|
||||
return q.CountWithError()
|
||||
}
|
||||
|
||||
func (self *SHostwire) ValidateDeleteCondition(ctx context.Context) error {
|
||||
func (self *SHostwire) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
cnt, err := self.GetGuestnicsCount()
|
||||
if err != nil {
|
||||
return httperrors.NewInternalServerError("GetGuestnicsCount fail %s", err)
|
||||
@@ -158,7 +158,7 @@ func (self *SHostwire) ValidateDeleteCondition(ctx context.Context) error {
|
||||
return httperrors.NewNotEmptyError("guest on the host are using networks on this wire")
|
||||
}
|
||||
}
|
||||
return self.SHostJointsBase.ValidateDeleteCondition(ctx)
|
||||
return self.SHostJointsBase.ValidateDeleteCondition(ctx, nil)
|
||||
}
|
||||
|
||||
func (self *SHostwire) Delete(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
|
||||
@@ -502,7 +502,7 @@ func (self *SInstanceSnapshot) GetInstanceSnapshotJointAt(diskIndex int) (*SInst
|
||||
return ispj, err
|
||||
}
|
||||
|
||||
func (self *SInstanceSnapshot) ValidateDeleteCondition(ctx context.Context) error {
|
||||
func (self *SInstanceSnapshot) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
if self.Status == api.INSTANCE_SNAPSHOT_START_DELETE || self.Status == api.INSTANCE_SNAPSHOT_RESET {
|
||||
return httperrors.NewForbiddenError("can't delete instance snapshot with wrong status")
|
||||
}
|
||||
@@ -565,7 +565,7 @@ func (is *SInstanceSnapshot) syncRemoveCloudInstanceSnapshot(ctx context.Context
|
||||
lockman.LockObject(ctx, is)
|
||||
defer lockman.ReleaseObject(ctx, is)
|
||||
|
||||
err := is.ValidateDeleteCondition(ctx)
|
||||
err := is.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil {
|
||||
err = is.SetStatus(userCred, api.INSTANCE_SNAPSHOT_UNKNOWN, "sync to delete")
|
||||
} else {
|
||||
|
||||
@@ -122,7 +122,7 @@ func (self *SInterVpcNetworkRouteSet) syncRemoveRouteSet(ctx context.Context, us
|
||||
lockman.LockObject(ctx, self)
|
||||
defer lockman.ReleaseObject(ctx, self)
|
||||
|
||||
err := self.ValidateDeleteCondition(ctx)
|
||||
err := self.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -302,11 +302,11 @@ func (manager *SIsolatedDeviceManager) GetExportExtraKeys(ctx context.Context, k
|
||||
return res
|
||||
}
|
||||
|
||||
func (self *SIsolatedDevice) ValidateDeleteCondition(ctx context.Context) error {
|
||||
func (self *SIsolatedDevice) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
if len(self.GuestId) > 0 {
|
||||
return httperrors.NewNotEmptyError("Isolated device used by server")
|
||||
}
|
||||
return self.SStandaloneResourceBase.ValidateDeleteCondition(ctx)
|
||||
return self.SStandaloneResourceBase.ValidateDeleteCondition(ctx, nil)
|
||||
}
|
||||
|
||||
func (self *SIsolatedDevice) getDetailedString() string {
|
||||
|
||||
@@ -336,11 +336,11 @@ func (man *SKafkaManager) TotalCount(
|
||||
}
|
||||
|
||||
// 判断资源是否可以删除
|
||||
func (self *SKafka) ValidateDeleteCondition(ctx context.Context) error {
|
||||
func (self *SKafka) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
if self.DisableDelete.IsTrue() {
|
||||
return httperrors.NewInvalidStatusError("Kafka is locked, cannot delete")
|
||||
}
|
||||
return self.SStatusStandaloneResourceBase.ValidateDeleteCondition(ctx)
|
||||
return self.SStatusStandaloneResourceBase.ValidateDeleteCondition(ctx, nil)
|
||||
}
|
||||
|
||||
func (self *SKafka) Delete(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
|
||||
@@ -178,7 +178,7 @@ func (manager *SKeypairManager) ValidateCreateData(ctx context.Context, userCred
|
||||
return input, nil
|
||||
}
|
||||
|
||||
func (self *SKeypair) ValidateDeleteCondition(ctx context.Context) error {
|
||||
func (self *SKeypair) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
guestCnt, err := self.GetLinkedGuestsCount()
|
||||
if err != nil {
|
||||
return httperrors.NewInternalServerError("GetLinkedGuestsCount failed %s", err)
|
||||
@@ -186,7 +186,7 @@ func (self *SKeypair) ValidateDeleteCondition(ctx context.Context) error {
|
||||
if guestCnt > 0 {
|
||||
return httperrors.NewNotEmptyError("Cannot delete keypair used by servers")
|
||||
}
|
||||
return self.SStandaloneResourceBase.ValidateDeleteCondition(ctx)
|
||||
return self.SStandaloneResourceBase.ValidateDeleteCondition(ctx, nil)
|
||||
}
|
||||
|
||||
func totalKeypairCount(userId string) (int, error) {
|
||||
|
||||
@@ -390,7 +390,7 @@ func (lbacl *SLoadbalancerAcl) PerformPatch(ctx context.Context, userCred mcclie
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (lbacl *SLoadbalancerAcl) ValidateDeleteCondition(ctx context.Context) error {
|
||||
func (lbacl *SLoadbalancerAcl) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
men := []db.IModelManager{
|
||||
LoadbalancerListenerManager,
|
||||
}
|
||||
|
||||
@@ -186,7 +186,7 @@ func (lbb *SAwsCachedLb) syncRemoveCloudLoadbalancerBackend(ctx context.Context,
|
||||
lockman.LockObject(ctx, lbb)
|
||||
defer lockman.ReleaseObject(ctx, lbb)
|
||||
|
||||
err := lbb.ValidateDeleteCondition(ctx)
|
||||
err := lbb.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil { // cannot delete
|
||||
err = lbb.SetStatus(userCred, api.LB_STATUS_UNKNOWN, "sync to delete")
|
||||
} else {
|
||||
|
||||
@@ -289,7 +289,7 @@ func (lbbg *SAwsCachedLbbg) syncRemoveCloudLoadbalancerBackendgroup(ctx context.
|
||||
lockman.LockObject(ctx, lbbg)
|
||||
defer lockman.ReleaseObject(ctx, lbbg)
|
||||
|
||||
err := lbbg.ValidateDeleteCondition(ctx)
|
||||
err := lbbg.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil { // cannot delete
|
||||
err = lbbg.SetStatus(userCred, api.LB_STATUS_UNKNOWN, "sync to delete")
|
||||
} else {
|
||||
|
||||
@@ -436,7 +436,7 @@ func (lbbg *SLoadbalancerBackendGroup) isDefault(ctx context.Context) (bool, err
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (lbbg *SLoadbalancerBackendGroup) ValidateDeleteCondition(ctx context.Context) error {
|
||||
func (lbbg *SLoadbalancerBackendGroup) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
if ok, err := lbbg.isDefault(ctx); err != nil {
|
||||
return httperrors.NewInternalServerError("get isDefault fail %s", err.Error())
|
||||
} else {
|
||||
@@ -977,7 +977,7 @@ func (lbbg *SLoadbalancerBackendGroup) syncRemoveCloudLoadbalancerBackendgroup(c
|
||||
lockman.LockObject(ctx, lbbg)
|
||||
defer lockman.ReleaseObject(ctx, lbbg)
|
||||
|
||||
err := lbbg.ValidateDeleteCondition(ctx)
|
||||
err := lbbg.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil { // cannot delete
|
||||
err = lbbg.SetStatus(userCred, api.LB_STATUS_UNKNOWN, "sync to delete")
|
||||
} else {
|
||||
|
||||
@@ -463,8 +463,8 @@ func (man *SLoadbalancerBackendManager) getLoadbalancerBackendsByLoadbalancerBac
|
||||
return loadbalancerBackends, nil
|
||||
}
|
||||
|
||||
func (lbb *SLoadbalancerBackend) ValidateDeleteCondition(ctx context.Context) error {
|
||||
return lbb.SVirtualResourceBase.ValidateDeleteCondition(ctx)
|
||||
func (lbb *SLoadbalancerBackend) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
return lbb.SVirtualResourceBase.ValidateDeleteCondition(ctx, nil)
|
||||
}
|
||||
|
||||
func (man *SLoadbalancerBackendManager) SyncLoadbalancerBackends(ctx context.Context, userCred mcclient.TokenCredential, provider *SCloudprovider, loadbalancerBackendgroup *SLoadbalancerBackendGroup, lbbs []cloudprovider.ICloudLoadbalancerBackend, syncRange *SSyncRange) compare.SyncResult {
|
||||
@@ -559,7 +559,7 @@ func (lbb *SLoadbalancerBackend) syncRemoveCloudLoadbalancerBackend(ctx context.
|
||||
lockman.LockObject(ctx, lbb)
|
||||
defer lockman.ReleaseObject(ctx, lbb)
|
||||
|
||||
err := lbb.ValidateDeleteCondition(ctx)
|
||||
err := lbb.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil { // cannot delete
|
||||
err = lbb.SetStatus(userCred, api.LB_STATUS_UNKNOWN, "sync to delete")
|
||||
} else {
|
||||
|
||||
@@ -253,7 +253,7 @@ func (lbacl *SCachedLoadbalancerAcl) AllowPerformPatch(ctx context.Context, user
|
||||
return lbacl.IsOwner(userCred) || db.IsAdminAllowPerform(userCred, lbacl, "patch")
|
||||
}
|
||||
|
||||
func (lbacl *SCachedLoadbalancerAcl) ValidateDeleteCondition(ctx context.Context) error {
|
||||
func (lbacl *SCachedLoadbalancerAcl) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
man := LoadbalancerListenerManager
|
||||
t := man.TableSpec().Instance()
|
||||
pdF := t.Field("pending_deleted")
|
||||
@@ -307,7 +307,7 @@ func (self *SCachedLoadbalancerAcl) syncRemoveCloudLoadbalanceAcl(ctx context.Co
|
||||
lockman.LockObject(ctx, self)
|
||||
defer lockman.ReleaseObject(ctx, self)
|
||||
|
||||
err := self.ValidateDeleteCondition(ctx)
|
||||
err := self.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil { // cannot delete
|
||||
err = self.SetStatus(userCred, api.LB_STATUS_UNKNOWN, "sync to delete")
|
||||
} else {
|
||||
|
||||
@@ -96,7 +96,7 @@ func (self *SCachedLoadbalancerCertificate) AllowDeleteItem(ctx context.Context,
|
||||
return db.IsAdminAllowDelete(userCred, self)
|
||||
}
|
||||
|
||||
func (self *SCachedLoadbalancerCertificate) ValidateDeleteCondition(ctx context.Context) error {
|
||||
func (self *SCachedLoadbalancerCertificate) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
men := []db.IModelManager{
|
||||
LoadbalancerListenerManager,
|
||||
}
|
||||
@@ -385,7 +385,7 @@ func (lbcert *SCachedLoadbalancerCertificate) syncRemoveCloudLoadbalancerCertifi
|
||||
lockman.LockObject(ctx, lbcert)
|
||||
defer lockman.ReleaseObject(ctx, lbcert)
|
||||
|
||||
err := lbcert.ValidateDeleteCondition(ctx)
|
||||
err := lbcert.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil { // cannot delete
|
||||
err = lbcert.SetStatus(userCred, api.LB_STATUS_UNKNOWN, "sync to delete")
|
||||
} else {
|
||||
|
||||
@@ -165,7 +165,7 @@ func (manager *SLoadbalancerCertificateManager) FetchCustomizeColumns(
|
||||
return rows
|
||||
}
|
||||
|
||||
func (lbcert *SLoadbalancerCertificate) ValidateDeleteCondition(ctx context.Context) error {
|
||||
func (lbcert *SLoadbalancerCertificate) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
men := []db.IModelManager{
|
||||
LoadbalancerListenerManager,
|
||||
}
|
||||
@@ -193,7 +193,7 @@ func (lbcert *SLoadbalancerCertificate) ValidateDeleteCondition(ctx context.Cont
|
||||
}
|
||||
|
||||
for i := range caches {
|
||||
err := caches[i].ValidateDeleteCondition(ctx)
|
||||
err := caches[i].ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "ValidateDeleteCondition")
|
||||
}
|
||||
|
||||
@@ -202,7 +202,7 @@ func (lbc *SLoadbalancerCluster) ValidateUpdateData(ctx context.Context, userCre
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func (lbc *SLoadbalancerCluster) ValidateDeleteCondition(ctx context.Context) error {
|
||||
func (lbc *SLoadbalancerCluster) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
men := []db.IModelManager{
|
||||
LoadbalancerManager,
|
||||
}
|
||||
@@ -222,7 +222,7 @@ func (lbc *SLoadbalancerCluster) ValidateDeleteCondition(ctx context.Context) er
|
||||
lbcId, lbc.Name, n, man.KeywordPlural())
|
||||
}
|
||||
}
|
||||
return lbc.SStandaloneResourceBase.ValidateDeleteCondition(ctx)
|
||||
return lbc.SStandaloneResourceBase.ValidateDeleteCondition(ctx, nil)
|
||||
}
|
||||
|
||||
func (man *SLoadbalancerClusterManager) FetchCustomizeColumns(
|
||||
@@ -258,7 +258,7 @@ func (lbc *SLoadbalancerCluster) CustomizeDelete(ctx context.Context, userCred m
|
||||
}
|
||||
for i := range lbagents {
|
||||
lbagent := &lbagents[i]
|
||||
if err := lbagent.ValidateDeleteCondition(ctx); err != nil {
|
||||
if err := lbagent.ValidateDeleteCondition(ctx, nil); err != nil {
|
||||
return errors.Wrapf(err, "lbagent %s(%s): validate delete", lbagent.Name, lbagent.Id)
|
||||
}
|
||||
if err := lbagent.CustomizeDelete(ctx, userCred, query, data); err != nil {
|
||||
|
||||
@@ -189,7 +189,7 @@ func (lbb *SHuaweiCachedLb) syncRemoveCloudLoadbalancerBackend(ctx context.Conte
|
||||
lockman.LockObject(ctx, lbb)
|
||||
defer lockman.ReleaseObject(ctx, lbb)
|
||||
|
||||
err := lbb.ValidateDeleteCondition(ctx)
|
||||
err := lbb.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil { // cannot delete
|
||||
err = lbb.SetStatus(userCred, api.LB_STATUS_UNKNOWN, "sync to delete")
|
||||
} else {
|
||||
|
||||
@@ -248,7 +248,7 @@ func (lbbg *SHuaweiCachedLbbg) syncRemoveCloudLoadbalancerBackendgroup(ctx conte
|
||||
lockman.LockObject(ctx, lbbg)
|
||||
defer lockman.ReleaseObject(ctx, lbbg)
|
||||
|
||||
err := lbbg.ValidateDeleteCondition(ctx)
|
||||
err := lbbg.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil { // cannot delete
|
||||
err = lbbg.SetStatus(userCred, api.LB_STATUS_UNKNOWN, "sync to delete")
|
||||
} else {
|
||||
|
||||
@@ -896,7 +896,7 @@ func (lbr *SLoadbalancerListenerRule) syncRemoveCloudLoadbalancerListenerRule(ct
|
||||
lockman.LockObject(ctx, lbr)
|
||||
defer lockman.ReleaseObject(ctx, lbr)
|
||||
|
||||
err := lbr.ValidateDeleteCondition(ctx)
|
||||
err := lbr.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil { // cannot delete
|
||||
err = lbr.SetStatus(userCred, api.LB_STATUS_UNKNOWN, "sync to delete")
|
||||
} else {
|
||||
|
||||
@@ -1237,7 +1237,7 @@ func (lblis *SLoadbalancerListener) syncRemoveCloudLoadbalancerListener(ctx cont
|
||||
lockman.LockObject(ctx, lblis)
|
||||
defer lockman.ReleaseObject(ctx, lblis)
|
||||
|
||||
err := lblis.ValidateDeleteCondition(ctx)
|
||||
err := lblis.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil { // cannot delete
|
||||
err = lblis.SetStatus(userCred, api.LB_STATUS_UNKNOWN, "sync to delete")
|
||||
} else {
|
||||
|
||||
@@ -187,7 +187,7 @@ func (lbb *SOpenstackCachedLb) syncRemoveCloudLoadbalancerBackend(ctx context.Co
|
||||
lockman.LockObject(ctx, lbb)
|
||||
defer lockman.ReleaseObject(ctx, lbb)
|
||||
|
||||
err := lbb.ValidateDeleteCondition(ctx)
|
||||
err := lbb.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil { // cannot delete
|
||||
lbb.SetStatus(userCred, api.LB_STATUS_UNKNOWN, "sync to delete")
|
||||
return errors.Wrap(err, "lbb.ValidateDeleteCondition(ctx)")
|
||||
|
||||
@@ -273,7 +273,7 @@ func (lbbg *SOpenstackCachedLbbg) syncRemoveCloudLoadbalancerBackendgroup(ctx co
|
||||
lockman.LockObject(ctx, lbbg)
|
||||
defer lockman.ReleaseObject(ctx, lbbg)
|
||||
|
||||
err := lbbg.ValidateDeleteCondition(ctx)
|
||||
err := lbbg.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil { // cannot delete
|
||||
lbbg.SetStatus(userCred, api.LB_STATUS_UNKNOWN, "sync to delete")
|
||||
return errors.Wrap(err, "lbbg.ValidateDeleteCondition(ctx)")
|
||||
|
||||
@@ -84,7 +84,7 @@ func (lbb *SQcloudCachedLb) syncRemoveCloudLoadbalancerBackend(ctx context.Conte
|
||||
lockman.LockObject(ctx, lbb)
|
||||
defer lockman.ReleaseObject(ctx, lbb)
|
||||
|
||||
err := lbb.ValidateDeleteCondition(ctx)
|
||||
err := lbb.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil { // cannot delete
|
||||
err = lbb.SetStatus(userCred, api.LB_STATUS_UNKNOWN, "sync to delete")
|
||||
} else {
|
||||
|
||||
@@ -140,7 +140,7 @@ func (lbbg *SQcloudCachedLbbg) syncRemoveCloudLoadbalancerBackendgroup(ctx conte
|
||||
lockman.LockObject(ctx, lbbg)
|
||||
defer lockman.ReleaseObject(ctx, lbbg)
|
||||
|
||||
err := lbbg.ValidateDeleteCondition(ctx)
|
||||
err := lbbg.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil { // cannot delete
|
||||
err = lbbg.SetStatus(userCred, api.LB_STATUS_UNKNOWN, "sync to delete")
|
||||
} else {
|
||||
|
||||
@@ -721,7 +721,7 @@ func (lb *SLoadbalancer) getMoreDetails(out api.LoadbalancerDetails) (api.Loadba
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (lb *SLoadbalancer) ValidateDeleteCondition(ctx context.Context) error {
|
||||
func (lb *SLoadbalancer) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
err := lb.validatePurgeCondition(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -742,7 +742,7 @@ func (lb *SLoadbalancer) validatePurgeCondition(ctx context.Context) error {
|
||||
}
|
||||
}
|
||||
|
||||
return lb.SModelBase.ValidateDeleteCondition(ctx)
|
||||
return lb.SModelBase.ValidateDeleteCondition(ctx, nil)
|
||||
}
|
||||
|
||||
func (lb *SLoadbalancer) CustomizeDelete(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) error {
|
||||
|
||||
@@ -460,11 +460,11 @@ func (self *SMongoDB) syncRemoveCloudMongoDB(ctx context.Context, userCred mccli
|
||||
return self.RealDelete(ctx, userCred)
|
||||
}
|
||||
|
||||
func (self *SMongoDB) ValidateDeleteCondition(ctx context.Context) error {
|
||||
func (self *SMongoDB) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
if self.DisableDelete.IsTrue() {
|
||||
return httperrors.NewInvalidStatusError("MongoDB is locked, cannot delete")
|
||||
}
|
||||
return self.SStatusStandaloneResourceBase.ValidateDeleteCondition(ctx)
|
||||
return self.SStatusStandaloneResourceBase.ValidateDeleteCondition(ctx, nil)
|
||||
}
|
||||
|
||||
func (self *SMongoDB) SyncAllWithCloudMongoDB(ctx context.Context, userCred mcclient.TokenCredential, provider *SCloudprovider, ext cloudprovider.ICloudMongoDB) error {
|
||||
|
||||
@@ -353,7 +353,7 @@ func (manager *SMountTargetManager) ListItemExportKeys(ctx context.Context,
|
||||
return q, nil
|
||||
}
|
||||
|
||||
func (self *SMountTarget) ValidateDeleteCondition(ctx context.Context) error {
|
||||
func (self *SMountTarget) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
fs, err := self.GetFileSystem()
|
||||
if err != nil {
|
||||
return httperrors.NewGeneralError(errors.Wrapf(err, "GetFileSystem"))
|
||||
@@ -365,7 +365,7 @@ func (self *SMountTarget) ValidateDeleteCondition(ctx context.Context) error {
|
||||
if utils.IsInStringArray(region.Provider, []string{api.CLOUD_PROVIDER_HUAWEI, api.CLOUD_PROVIDER_HCSO}) {
|
||||
return httperrors.NewNotSupportedError("not allow to delete")
|
||||
}
|
||||
return self.SStatusStandaloneResourceBase.ValidateDeleteCondition(ctx)
|
||||
return self.SStatusStandaloneResourceBase.ValidateDeleteCondition(ctx, nil)
|
||||
}
|
||||
|
||||
func (self *SMountTarget) Delete(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
|
||||
@@ -241,7 +241,7 @@ func (self *SNatDEntry) syncRemoveCloudNatDTable(ctx context.Context, userCred m
|
||||
lockman.LockObject(ctx, self)
|
||||
defer lockman.ReleaseObject(ctx, self)
|
||||
|
||||
err := self.ValidateDeleteCondition(ctx)
|
||||
err := self.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil { // cannot delete
|
||||
return self.SetStatus(userCred, api.VPC_STATUS_UNKNOWN, "sync to delete")
|
||||
}
|
||||
|
||||
@@ -452,18 +452,18 @@ func (self *SNatGateway) syncRemoveCloudNatGateway(ctx context.Context, userCred
|
||||
|
||||
self.DeletePreventionOff(self, userCred)
|
||||
|
||||
err := self.ValidateDeleteCondition(ctx)
|
||||
err := self.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil { // cannot delete
|
||||
return self.SetStatus(userCred, api.NAT_STATUS_UNKNOWN, "sync to delete")
|
||||
}
|
||||
return self.purge(ctx, userCred)
|
||||
}
|
||||
|
||||
func (self *SNatGateway) ValidateDeleteCondition(ctx context.Context) error {
|
||||
func (self *SNatGateway) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
if self.DisableDelete.IsTrue() {
|
||||
return httperrors.NewInvalidStatusError("Nat is locked, cannot delete")
|
||||
}
|
||||
return self.SStatusInfrasResourceBase.ValidateDeleteCondition(ctx)
|
||||
return self.SStatusInfrasResourceBase.ValidateDeleteCondition(ctx, nil)
|
||||
}
|
||||
|
||||
func (self *SNatGateway) SyncWithCloudNatGateway(ctx context.Context, userCred mcclient.TokenCredential, provider *SCloudprovider, extNat cloudprovider.ICloudNatGateway) error {
|
||||
|
||||
@@ -287,7 +287,7 @@ func (self *SNatSEntry) syncRemoveCloudNatSTable(ctx context.Context, userCred m
|
||||
lockman.LockObject(ctx, self)
|
||||
defer lockman.ReleaseObject(ctx, self)
|
||||
|
||||
err := self.ValidateDeleteCondition(ctx)
|
||||
err := self.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil { // cannot delete
|
||||
return self.SetStatus(userCred, api.VPC_STATUS_UNKNOWN, "sync to delete")
|
||||
}
|
||||
|
||||
@@ -276,7 +276,7 @@ func (self *SNetworkInterface) syncRemoveCloudNetworkInterface(ctx context.Conte
|
||||
lockman.LockObject(ctx, self)
|
||||
defer lockman.ReleaseObject(ctx, self)
|
||||
|
||||
err := self.ValidateDeleteCondition(ctx)
|
||||
err := self.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil {
|
||||
self.SetStatus(userCred, api.NETWORK_INTERFACE_STATUS_UNKNOWN, "sync to delete")
|
||||
return errors.Wrapf(err, "ValidateDeleteCondition")
|
||||
|
||||
@@ -185,15 +185,22 @@ func (self *SNetwork) GetNetworkInterfaces() ([]SNetworkInterface, error) {
|
||||
return networkinterfaces, nil
|
||||
}
|
||||
|
||||
func (self *SNetwork) ValidateDeleteCondition(ctx context.Context) error {
|
||||
vnics, err := NetworkManager.TotalNicCount([]string{self.Id})
|
||||
if err != nil {
|
||||
return httperrors.NewInternalServerError("TotalNicCount fail %s", err)
|
||||
func (self *SNetwork) ValidateDeleteCondition(ctx context.Context, data *api.NetworkDetails) error {
|
||||
if data == nil {
|
||||
data = &api.NetworkDetails{}
|
||||
nics, err := NetworkManager.TotalNicCount([]string{self.Id})
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "TotalNicCount")
|
||||
}
|
||||
if cnt, ok := nics[self.Id]; ok {
|
||||
data.SNetworkNics = cnt
|
||||
}
|
||||
}
|
||||
if nics, ok := vnics[self.Id]; ok && nics.Total > 0 {
|
||||
return httperrors.NewNotEmptyError("not an empty network %s", jsonutils.Marshal(nics).String())
|
||||
if data.Total > 0 {
|
||||
return httperrors.NewNotEmptyError("not an empty network %s", jsonutils.Marshal(data.SNetworkNics).String())
|
||||
}
|
||||
return self.SSharableVirtualResourceBase.ValidateDeleteCondition(ctx)
|
||||
|
||||
return self.SSharableVirtualResourceBase.ValidateDeleteCondition(ctx, nil)
|
||||
}
|
||||
|
||||
/*验证elb network可用,并返回关联的region, zone,vpc, wire*/
|
||||
@@ -643,7 +650,7 @@ func (self *SNetwork) syncRemoveCloudNetwork(ctx context.Context, userCred mccli
|
||||
return nil
|
||||
}
|
||||
|
||||
err := self.ValidateDeleteCondition(ctx)
|
||||
err := self.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil { // cannot delete
|
||||
err = self.SetStatus(userCred, api.NETWORK_STATUS_UNKNOWN, "Sync to remove")
|
||||
} else {
|
||||
@@ -2309,7 +2316,7 @@ func (self *SNetwork) AllowPerformPurge(ctx context.Context, userCred mcclient.T
|
||||
// 清除IP子网数据
|
||||
// 要求IP子网内没有被分配IP,若清除接入云,要求接入云账号处于禁用状态
|
||||
func (self *SNetwork) PerformPurge(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input *api.NetworkPurgeInput) (jsonutils.JSONObject, error) {
|
||||
err := self.ValidateDeleteCondition(ctx)
|
||||
err := self.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -270,7 +270,7 @@ func (self *SProjectMapping) Delete(ctx context.Context, userCred mcclient.Token
|
||||
return self.SEnabledStatusInfrasResourceBase.Delete(ctx, userCred)
|
||||
}
|
||||
|
||||
func (self *SProjectMapping) ValidateDeleteCondition(ctx context.Context) error {
|
||||
func (self *SProjectMapping) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
accounts, err := self.GetCloudaccounts()
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "GetCloudaccounts")
|
||||
@@ -285,7 +285,7 @@ func (self *SProjectMapping) ValidateDeleteCondition(ctx context.Context) error
|
||||
if len(providers) > 0 {
|
||||
return httperrors.NewNotEmptyError("project mapping has associate %d cloudproviders", len(providers))
|
||||
}
|
||||
return self.SEnabledStatusInfrasResourceBase.ValidateDeleteCondition(ctx)
|
||||
return self.SEnabledStatusInfrasResourceBase.ValidateDeleteCondition(ctx, nil)
|
||||
}
|
||||
|
||||
func (self *SProjectMapping) PostUpdate(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) {
|
||||
|
||||
+33
-33
@@ -58,7 +58,7 @@ func (eip *SElasticip) purge(ctx context.Context, userCred mcclient.TokenCredent
|
||||
lockman.LockObject(ctx, eip)
|
||||
defer lockman.ReleaseObject(ctx, eip)
|
||||
|
||||
err := eip.ValidateDeleteCondition(ctx)
|
||||
err := eip.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -293,7 +293,7 @@ func (lbacl *SCachedLoadbalancerAcl) purge(ctx context.Context, userCred mcclien
|
||||
lockman.LockObject(ctx, lbacl)
|
||||
defer lockman.ReleaseObject(ctx, lbacl)
|
||||
|
||||
err := lbacl.ValidateDeleteCondition(ctx)
|
||||
err := lbacl.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -420,7 +420,7 @@ func (lb *SLoadbalancer) purge(ctx context.Context, userCred mcclient.TokenCrede
|
||||
return err
|
||||
}
|
||||
|
||||
err = lb.ValidateDeleteCondition(ctx)
|
||||
err = lb.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -453,7 +453,7 @@ func (lbl *SLoadbalancerListener) purge(ctx context.Context, userCred mcclient.T
|
||||
return err
|
||||
}
|
||||
|
||||
err = lbl.ValidateDeleteCondition(ctx)
|
||||
err = lbl.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -466,7 +466,7 @@ func (lblr *SLoadbalancerListenerRule) purge(ctx context.Context, userCred mccli
|
||||
lockman.LockObject(ctx, lblr)
|
||||
defer lockman.ReleaseObject(ctx, lblr)
|
||||
|
||||
err := lblr.ValidateDeleteCondition(ctx)
|
||||
err := lblr.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -578,7 +578,7 @@ func (lbbg *SAwsCachedLbbg) purge(ctx context.Context, userCred mcclient.TokenCr
|
||||
lockman.LockObject(ctx, lbbg)
|
||||
defer lockman.ReleaseObject(ctx, lbbg)
|
||||
|
||||
err := lbbg.ValidateDeleteCondition(ctx)
|
||||
err := lbbg.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -605,7 +605,7 @@ func (lbbg *SHuaweiCachedLbbg) purge(ctx context.Context, userCred mcclient.Toke
|
||||
lockman.LockObject(ctx, lbbg)
|
||||
defer lockman.ReleaseObject(ctx, lbbg)
|
||||
|
||||
err := lbbg.ValidateDeleteCondition(ctx)
|
||||
err := lbbg.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -622,7 +622,7 @@ func (lbb *SLoadbalancerBackend) purge(ctx context.Context, userCred mcclient.To
|
||||
return err
|
||||
}
|
||||
|
||||
err = lbb.ValidateDeleteCondition(ctx)
|
||||
err = lbb.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -659,7 +659,7 @@ func (lbb *SAwsCachedLb) purge(ctx context.Context, userCred mcclient.TokenCrede
|
||||
lockman.LockObject(ctx, lbb)
|
||||
defer lockman.ReleaseObject(ctx, lbb)
|
||||
|
||||
err := lbb.ValidateDeleteCondition(ctx)
|
||||
err := lbb.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -686,7 +686,7 @@ func (lbb *SHuaweiCachedLb) purge(ctx context.Context, userCred mcclient.TokenCr
|
||||
lockman.LockObject(ctx, lbb)
|
||||
defer lockman.ReleaseObject(ctx, lbb)
|
||||
|
||||
err := lbb.ValidateDeleteCondition(ctx)
|
||||
err := lbb.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -740,7 +740,7 @@ func (manager *SSnapshotPolicyCacheManager) purgeAll(ctx context.Context, userCr
|
||||
func (spc *SSnapshotPolicyCache) purge(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
lockman.LockObject(ctx, spc)
|
||||
defer lockman.ReleaseObject(ctx, spc)
|
||||
err := spc.ValidateDeleteCondition(ctx)
|
||||
err := spc.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -790,7 +790,7 @@ func (sc *SStoragecache) purge(ctx context.Context, userCred mcclient.TokenCrede
|
||||
return err
|
||||
}
|
||||
|
||||
err = sc.ValidateDeleteCondition(ctx)
|
||||
err = sc.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -821,7 +821,7 @@ func (storage *SStorage) purge(ctx context.Context, userCred mcclient.TokenCrede
|
||||
return err
|
||||
}
|
||||
|
||||
err = storage.ValidateDeleteCondition(ctx)
|
||||
err = storage.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -964,7 +964,7 @@ func (nic *SNetworkInterface) purge(ctx context.Context, userCred mcclient.Token
|
||||
return err
|
||||
}
|
||||
|
||||
err = nic.ValidateDeleteCondition(ctx)
|
||||
err = nic.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -1041,7 +1041,7 @@ func (net *SNetwork) purge(ctx context.Context, userCred mcclient.TokenCredentia
|
||||
return errors.Wrapf(err, "purgeDBInstanceNetworks")
|
||||
}
|
||||
|
||||
err = net.ValidateDeleteCondition(ctx)
|
||||
err = net.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "ValidateDeleteCondition")
|
||||
}
|
||||
@@ -1085,7 +1085,7 @@ func (wire *SWire) purge(ctx context.Context, userCred mcclient.TokenCredential)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = wire.ValidateDeleteCondition(ctx)
|
||||
err = wire.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -1130,7 +1130,7 @@ func (vpc *SVpc) Purge(ctx context.Context, userCred mcclient.TokenCredential) e
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = vpc.ValidateDeleteCondition(ctx)
|
||||
err = vpc.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -1138,7 +1138,7 @@ func (vpc *SVpc) Purge(ctx context.Context, userCred mcclient.TokenCredential) e
|
||||
}
|
||||
|
||||
func (dn *SNatDEntry) Purge(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
err := dn.ValidateDeleteCondition(ctx)
|
||||
err := dn.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -1146,7 +1146,7 @@ func (dn *SNatDEntry) Purge(ctx context.Context, userCred mcclient.TokenCredenti
|
||||
}
|
||||
|
||||
func (sn *SNatSEntry) Purge(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
err := sn.ValidateDeleteCondition(ctx)
|
||||
err := sn.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -1171,7 +1171,7 @@ func (zone *SZone) Purge(ctx context.Context, userCred mcclient.TokenCredential)
|
||||
lockman.LockObject(ctx, zone)
|
||||
defer lockman.ReleaseObject(ctx, zone)
|
||||
|
||||
err := zone.ValidateDeleteCondition(ctx)
|
||||
err := zone.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -1221,7 +1221,7 @@ func (region *SCloudregion) purge(ctx context.Context, userCred mcclient.TokenCr
|
||||
return err
|
||||
}
|
||||
|
||||
err = region.ValidateDeleteCondition(ctx)
|
||||
err = region.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -1257,7 +1257,7 @@ func (table *SNatSEntry) purge(ctx context.Context, userCred mcclient.TokenCrede
|
||||
lockman.LockObject(ctx, table)
|
||||
defer lockman.ReleaseObject(ctx, table)
|
||||
|
||||
err := table.ValidateDeleteCondition(ctx)
|
||||
err := table.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -1284,7 +1284,7 @@ func (table *SNatDEntry) purge(ctx context.Context, userCred mcclient.TokenCrede
|
||||
lockman.LockObject(ctx, table)
|
||||
defer lockman.ReleaseObject(ctx, table)
|
||||
|
||||
err := table.ValidateDeleteCondition(ctx)
|
||||
err := table.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -1323,7 +1323,7 @@ func (nat *SNatGateway) purge(ctx context.Context, userCred mcclient.TokenCreden
|
||||
|
||||
nat.DeletePreventionOff(nat, userCred)
|
||||
|
||||
err = nat.ValidateDeleteCondition(ctx)
|
||||
err = nat.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -1401,7 +1401,7 @@ func (account *SDBInstanceAccount) Purge(ctx context.Context, userCred mcclient.
|
||||
}
|
||||
}
|
||||
|
||||
err = account.ValidateDeleteCondition(ctx)
|
||||
err = account.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -1439,7 +1439,7 @@ func (database *SDBInstanceDatabase) Purge(ctx context.Context, userCred mcclien
|
||||
}
|
||||
}
|
||||
|
||||
err = database.ValidateDeleteCondition(ctx)
|
||||
err = database.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -1465,7 +1465,7 @@ func (parameter *SDBInstanceParameter) purge(ctx context.Context, userCred mccli
|
||||
lockman.LockObject(ctx, parameter)
|
||||
defer lockman.ReleaseObject(ctx, parameter)
|
||||
|
||||
err := parameter.ValidateDeleteCondition(ctx)
|
||||
err := parameter.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -1491,7 +1491,7 @@ func (network *SDBInstanceNetwork) purge(ctx context.Context, userCred mcclient.
|
||||
lockman.LockObject(ctx, network)
|
||||
defer lockman.ReleaseObject(ctx, network)
|
||||
|
||||
err := network.ValidateDeleteCondition(ctx)
|
||||
err := network.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "ValidateDeleteCondition")
|
||||
}
|
||||
@@ -1583,7 +1583,7 @@ func (instance *SDBInstance) Purge(ctx context.Context, userCred mcclient.TokenC
|
||||
return errors.Wrap(err, "instance.purgeBackups")
|
||||
}
|
||||
|
||||
err = instance.ValidateDeleteCondition(ctx)
|
||||
err = instance.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "ValidateDeleteCondition")
|
||||
}
|
||||
@@ -1609,7 +1609,7 @@ func (backup *SDBInstanceBackup) purge(ctx context.Context, userCred mcclient.To
|
||||
lockman.LockObject(ctx, backup)
|
||||
defer lockman.ReleaseObject(ctx, backup)
|
||||
|
||||
err := backup.ValidateDeleteCondition(ctx)
|
||||
err := backup.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -1808,7 +1808,7 @@ func (quota *SCloudproviderQuota) purge(ctx context.Context, userCred mcclient.T
|
||||
lockman.LockObject(ctx, quota)
|
||||
defer lockman.ReleaseObject(ctx, quota)
|
||||
|
||||
err := quota.ValidateDeleteCondition(ctx)
|
||||
err := quota.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -1835,7 +1835,7 @@ func (assignment *SPolicyAssignment) purge(ctx context.Context, userCred mcclien
|
||||
lockman.LockObject(ctx, assignment)
|
||||
defer lockman.ReleaseObject(ctx, assignment)
|
||||
|
||||
err := assignment.ValidateDeleteCondition(ctx)
|
||||
err := assignment.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "assignment.ValidateDeleteCondition(%s(%s))", assignment.Name, assignment.Id)
|
||||
}
|
||||
@@ -1859,7 +1859,7 @@ func (definition *SPolicyDefinition) purge(ctx context.Context, userCred mcclien
|
||||
}
|
||||
}
|
||||
|
||||
err = definition.ValidateDeleteCondition(ctx)
|
||||
err = definition.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ func (self *SRouteTableAssociation) syncRemoveAssociation(ctx context.Context, u
|
||||
lockman.LockObject(ctx, self)
|
||||
defer lockman.ReleaseObject(ctx, self)
|
||||
|
||||
err := self.ValidateDeleteCondition(ctx)
|
||||
err := self.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -271,7 +271,7 @@ func (self *SRouteTableRouteSet) PostUpdate(ctx context.Context, userCred mcclie
|
||||
routeTable.StartRouteTableUpdateTask(ctx, userCred, self, "update")
|
||||
}
|
||||
|
||||
func (self *SRouteTableRouteSet) ValidateDeleteCondition(ctx context.Context) error {
|
||||
func (self *SRouteTableRouteSet) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
vpc, err := self.GetVpc()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "self.GetVpc()")
|
||||
@@ -319,7 +319,7 @@ func (self *SRouteTableRouteSet) syncRemoveRouteSet(ctx context.Context, userCre
|
||||
lockman.LockObject(ctx, self)
|
||||
defer lockman.ReleaseObject(ctx, self)
|
||||
|
||||
err := self.ValidateDeleteCondition(ctx)
|
||||
err := self.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -171,7 +171,7 @@ func (rt *SRouteTable) AllowPerformPurge(ctx context.Context, userCred mcclient.
|
||||
}
|
||||
|
||||
func (rt *SRouteTable) PerformPurge(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
err := rt.ValidateDeleteCondition(ctx)
|
||||
err := rt.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -505,7 +505,7 @@ func (self *SRouteTable) syncRemoveCloudRouteTable(ctx context.Context, userCred
|
||||
lockman.LockObject(ctx, self)
|
||||
defer lockman.ReleaseObject(ctx, self)
|
||||
|
||||
err := self.ValidateDeleteCondition(ctx)
|
||||
err := self.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -235,7 +235,7 @@ func (sgm *SScalingGroupManager) ValidateCreateData(ctx context.Context, userCre
|
||||
return input, nil
|
||||
}
|
||||
|
||||
func (sg *SScalingGroup) ValidateDeleteCondition(ctx context.Context) error {
|
||||
func (sg *SScalingGroup) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
// check enabled
|
||||
if sg.Enabled.IsTrue() {
|
||||
return httperrors.NewForbiddenError("Please disable this ScalingGroup firstly")
|
||||
|
||||
@@ -380,7 +380,7 @@ func (self *SSchedtag) ValidateUpdateData(ctx context.Context, userCred mcclient
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func (self *SSchedtag) ValidateDeleteCondition(ctx context.Context) error {
|
||||
func (self *SSchedtag) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
cnt, err := self.GetObjectCount()
|
||||
if err != nil {
|
||||
return httperrors.NewInternalServerError("GetObjectCount fail %s", err)
|
||||
@@ -402,7 +402,7 @@ func (self *SSchedtag) ValidateDeleteCondition(ctx context.Context) error {
|
||||
if cnt > 0 {
|
||||
return httperrors.NewNotEmptyError("tag is associate with sched policies")
|
||||
}
|
||||
return self.SStandaloneResourceBase.ValidateDeleteCondition(ctx)
|
||||
return self.SStandaloneResourceBase.ValidateDeleteCondition(ctx, nil)
|
||||
}
|
||||
|
||||
// GetObjectPtr wraps the given value with pointer: V => *V, *V => **V, etc.
|
||||
|
||||
@@ -263,8 +263,8 @@ func (st *SScheduledTask) PostCreate(ctx context.Context, userCred mcclient.Toke
|
||||
logclient.AddActionLogWithContext(ctx, st, logclient.ACT_CREATE, "", userCred, true)
|
||||
}
|
||||
|
||||
func (st *SScheduledTask) ValidateDeleteCondition(ctx context.Context) error {
|
||||
err := st.SVirtualResourceBase.ValidateDeleteCondition(ctx)
|
||||
func (st *SScheduledTask) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
err := st.SVirtualResourceBase.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -574,12 +574,12 @@ func (self *SSecurityGroupCache) StartSyncstatusTask(ctx context.Context, userCr
|
||||
return StartResourceSyncStatusTask(ctx, userCred, self, "SecurityGroupCacheSyncstatusTask", "")
|
||||
}
|
||||
|
||||
func (self *SSecurityGroupCache) ValidateDeleteCondition(ctx context.Context) error {
|
||||
func (self *SSecurityGroupCache) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
if self.ReferenceCount > 0 && self.Status == api.SECGROUP_CACHE_STATUS_READY {
|
||||
return httperrors.NewNotEmptyError("security group has been reference in %d security group", self.ReferenceCount)
|
||||
}
|
||||
|
||||
return self.SStatusStandaloneResourceBase.ValidateDeleteCondition(ctx)
|
||||
return self.SStatusStandaloneResourceBase.ValidateDeleteCondition(ctx, nil)
|
||||
}
|
||||
|
||||
func (self *SSecurityGroupCache) Delete(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
|
||||
@@ -716,7 +716,7 @@ func (self *SSecurityGroup) AllowPerformPurge(ctx context.Context, userCred mccl
|
||||
}
|
||||
|
||||
func (self *SSecurityGroup) PerformPurge(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
err := self.ValidateDeleteCondition(ctx)
|
||||
err := self.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -1280,7 +1280,7 @@ func (self *SSecurityGroup) GetSecurityGroupReferences() ([]SSecurityGroup, erro
|
||||
return groups, nil
|
||||
}
|
||||
|
||||
func (self *SSecurityGroup) ValidateDeleteCondition(ctx context.Context) error {
|
||||
func (self *SSecurityGroup) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
cnt, err := self.GetGuestsCount()
|
||||
if err != nil {
|
||||
return httperrors.NewInternalServerError("GetGuestsCount fail %s", err)
|
||||
@@ -1298,7 +1298,7 @@ func (self *SSecurityGroup) ValidateDeleteCondition(ctx context.Context) error {
|
||||
if len(references) > 0 {
|
||||
return httperrors.NewNotEmptyError("the other security group is in use")
|
||||
}
|
||||
return self.SSharableVirtualResourceBase.ValidateDeleteCondition(ctx)
|
||||
return self.SSharableVirtualResourceBase.ValidateDeleteCondition(ctx, nil)
|
||||
}
|
||||
|
||||
func (self *SSecurityGroup) GetSecurityGroupCaches() ([]SSecurityGroupCache, error) {
|
||||
|
||||
@@ -642,7 +642,7 @@ func (self *SServerSku) StartServerSkuDeleteTask(ctx context.Context, userCred m
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SServerSku) ValidateDeleteCondition(ctx context.Context) error {
|
||||
func (self *SServerSku) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
serverCount, err := skuRelatedGuestCount(self)
|
||||
if err != nil {
|
||||
return httperrors.NewInternalServerError("check instance")
|
||||
|
||||
@@ -602,7 +602,7 @@ func (self *SSnapshot) StartSnapshotDeleteTask(ctx context.Context, userCred mcc
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SSnapshot) ValidateDeleteCondition(ctx context.Context) error {
|
||||
func (self *SSnapshot) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
if self.Status == api.SNAPSHOT_DELETING {
|
||||
return httperrors.NewBadRequestError("Cannot delete snapshot in status %s", self.Status)
|
||||
}
|
||||
@@ -849,7 +849,7 @@ func (self *SSnapshot) syncRemoveCloudSnapshot(ctx context.Context, userCred mcc
|
||||
lockman.LockObject(ctx, self)
|
||||
defer lockman.ReleaseObject(ctx, self)
|
||||
|
||||
err := self.ValidateDeleteCondition(ctx)
|
||||
err := self.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil {
|
||||
err = self.SetStatus(userCred, api.SNAPSHOT_UNKNOWN, "sync to delete")
|
||||
} else {
|
||||
|
||||
@@ -272,7 +272,7 @@ func (self *SStoragecachedimage) Detach(ctx context.Context, userCred mcclient.T
|
||||
return db.DetachJoint(ctx, userCred, self)
|
||||
}
|
||||
|
||||
func (self *SStoragecachedimage) ValidateDeleteCondition(ctx context.Context) error {
|
||||
func (self *SStoragecachedimage) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
if self.Status != api.CACHED_IMAGE_STATUS_CACHE_FAILED {
|
||||
cnt, err := self.getReferenceCount()
|
||||
if err != nil {
|
||||
@@ -282,7 +282,7 @@ func (self *SStoragecachedimage) ValidateDeleteCondition(ctx context.Context) er
|
||||
return httperrors.NewNotEmptyError("Image is in use")
|
||||
}
|
||||
}
|
||||
return self.SJointResourceBase.ValidateDeleteCondition(ctx)
|
||||
return self.SJointResourceBase.ValidateDeleteCondition(ctx, nil)
|
||||
}
|
||||
|
||||
func (self *SStoragecachedimage) isCachedImageInUse() error {
|
||||
@@ -305,7 +305,7 @@ func (self *SStoragecachedimage) isDownloadSessionExpire() bool {
|
||||
}
|
||||
|
||||
func (self *SStoragecachedimage) markDeleting(ctx context.Context, userCred mcclient.TokenCredential, isForce bool) error {
|
||||
err := self.ValidateDeleteCondition(ctx)
|
||||
err := self.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -535,7 +535,7 @@ func (manager *SStoragecacheManager) GetCachePathById(storageCacheId string) str
|
||||
return sc.Path
|
||||
}
|
||||
|
||||
func (self *SStoragecache) ValidateDeleteCondition(ctx context.Context) error {
|
||||
func (self *SStoragecache) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
if self.getCachedImageCount() > 0 {
|
||||
return httperrors.NewNotEmptyError("storage cache not empty")
|
||||
}
|
||||
@@ -543,7 +543,7 @@ func (self *SStoragecache) ValidateDeleteCondition(ctx context.Context) error {
|
||||
if len(storages) > 0 {
|
||||
return httperrors.NewNotEmptyError("referered by storages")
|
||||
}
|
||||
return self.SStandaloneResourceBase.ValidateDeleteCondition(ctx)
|
||||
return self.SStandaloneResourceBase.ValidateDeleteCondition(ctx, nil)
|
||||
}
|
||||
|
||||
func (self *SStoragecache) AllowPerformUncacheImage(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool {
|
||||
|
||||
@@ -250,7 +250,7 @@ func (self *SStorage) CustomizeCreate(ctx context.Context, userCred mcclient.Tok
|
||||
return self.SEnabledStatusInfrasResourceBase.CustomizeCreate(ctx, userCred, ownerId, query, data)
|
||||
}
|
||||
|
||||
func (self *SStorage) ValidateDeleteCondition(ctx context.Context) error {
|
||||
func (self *SStorage) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
cnt, err := self.GetHostCount()
|
||||
if err != nil {
|
||||
return httperrors.NewInternalServerError("GetHostCount fail %s", err)
|
||||
@@ -272,7 +272,7 @@ func (self *SStorage) ValidateDeleteCondition(ctx context.Context) error {
|
||||
if cnt > 0 {
|
||||
return httperrors.NewNotEmptyError("storage has snapshots")
|
||||
}
|
||||
return self.SEnabledStatusInfrasResourceBase.ValidateDeleteCondition(ctx)
|
||||
return self.SEnabledStatusInfrasResourceBase.ValidateDeleteCondition(ctx, nil)
|
||||
}
|
||||
|
||||
func (self *SStorage) PostCreate(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, data jsonutils.JSONObject) {
|
||||
@@ -766,7 +766,7 @@ func (self *SStorage) syncRemoveCloudStorage(ctx context.Context, userCred mccli
|
||||
lockman.LockObject(ctx, self)
|
||||
defer lockman.ReleaseObject(ctx, self)
|
||||
|
||||
err := self.ValidateDeleteCondition(ctx)
|
||||
err := self.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil { // cannot delete
|
||||
err = self.SetStatus(userCred, api.STORAGE_OFFLINE, "sync to delete")
|
||||
if err == nil {
|
||||
|
||||
@@ -212,7 +212,7 @@ func (self *SVpc) ValidateUpdateData(ctx context.Context, userCred mcclient.Toke
|
||||
return input, nil
|
||||
}
|
||||
|
||||
func (self *SVpc) ValidateDeleteCondition(ctx context.Context) error {
|
||||
func (self *SVpc) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
if self.Id == api.DEFAULT_VPC_ID {
|
||||
return httperrors.NewProtectedResourceError("not allow to delete default vpc")
|
||||
}
|
||||
@@ -239,7 +239,7 @@ func (self *SVpc) ValidateDeleteCondition(ctx context.Context) error {
|
||||
return httperrors.NewNotEmptyError("VPC peering not empty, please delete vpc peering first")
|
||||
}
|
||||
|
||||
return self.SEnabledStatusInfrasResourceBase.ValidateDeleteCondition(ctx)
|
||||
return self.SEnabledStatusInfrasResourceBase.ValidateDeleteCondition(ctx, nil)
|
||||
}
|
||||
|
||||
func (self *SVpc) getWireQuery() *sqlchemy.SQuery {
|
||||
@@ -511,7 +511,7 @@ func (self *SVpc) syncRemoveCloudVpc(ctx context.Context, userCred mcclient.Toke
|
||||
return nil
|
||||
}
|
||||
|
||||
err := self.ValidateDeleteCondition(ctx)
|
||||
err := self.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil { // cannot delete
|
||||
self.markAllNetworksUnknown(userCred)
|
||||
_, err = self.PerformDisable(ctx, userCred, nil, apis.PerformDisableInput{})
|
||||
@@ -1036,7 +1036,7 @@ func (self *SVpc) AllowPerformPurge(ctx context.Context, userCred mcclient.Token
|
||||
}
|
||||
|
||||
func (self *SVpc) PerformPurge(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
err := self.ValidateDeleteCondition(ctx)
|
||||
err := self.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -170,7 +170,7 @@ func (wire *SWire) ValidateUpdateData(ctx context.Context, userCred mcclient.Tok
|
||||
return input, nil
|
||||
}
|
||||
|
||||
func (wire *SWire) ValidateDeleteCondition(ctx context.Context) error {
|
||||
func (wire *SWire) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
cnt, err := wire.HostCount()
|
||||
if err != nil {
|
||||
return httperrors.NewInternalServerError("HostCount fail %s", err)
|
||||
@@ -185,7 +185,7 @@ func (wire *SWire) ValidateDeleteCondition(ctx context.Context) error {
|
||||
if cnt > 0 {
|
||||
return httperrors.NewNotEmptyError("wire contains networks")
|
||||
}
|
||||
return wire.SInfrasResourceBase.ValidateDeleteCondition(ctx)
|
||||
return wire.SInfrasResourceBase.ValidateDeleteCondition(ctx, nil)
|
||||
}
|
||||
|
||||
func (manager *SWireManager) getWireExternalIdForClassicNetwork(provider string, vpcId string, zoneId string) string {
|
||||
@@ -356,7 +356,7 @@ func (self *SWire) syncRemoveCloudWire(ctx context.Context, userCred mcclient.To
|
||||
return nil
|
||||
}
|
||||
|
||||
err := self.ValidateDeleteCondition(ctx)
|
||||
err := self.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil { // cannot delete
|
||||
err = self.markNetworkUnknown(userCred)
|
||||
} else {
|
||||
|
||||
@@ -83,12 +83,12 @@ func (manager *SZoneManager) AllowListItems(ctx context.Context, userCred mcclie
|
||||
return true
|
||||
}
|
||||
|
||||
func (zone *SZone) ValidateDeleteCondition(ctx context.Context) error {
|
||||
func (zone *SZone) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
usage := zone.GeneralUsage()
|
||||
if !usage.IsEmpty() {
|
||||
return httperrors.NewNotEmptyError("not empty zone: %s", zone.Id)
|
||||
}
|
||||
return zone.SStandaloneResourceBase.ValidateDeleteCondition(ctx)
|
||||
return zone.SStandaloneResourceBase.ValidateDeleteCondition(ctx, nil)
|
||||
}
|
||||
|
||||
func (manager *SZoneManager) Count() (int, error) {
|
||||
@@ -255,7 +255,7 @@ func (self *SZone) syncRemoveCloudZone(ctx context.Context, userCred mcclient.To
|
||||
return err
|
||||
}
|
||||
|
||||
err = self.ValidateDeleteCondition(ctx)
|
||||
err = self.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil { // cannot delete
|
||||
err = self.SetStatus(userCred, api.ZONE_DISABLE, "sync to delete")
|
||||
} else {
|
||||
|
||||
@@ -151,7 +151,7 @@ func (self *SGoogleRegionDriver) RequestDeleteVpc(ctx context.Context, userCred
|
||||
|
||||
for i := range vpcs {
|
||||
if vpcs[i].Status == api.VPC_STATUS_AVAILABLE && vpcs[i].ManagerId == vpc.ManagerId {
|
||||
err = vpc.ValidateDeleteCondition(ctx)
|
||||
err = vpc.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "vpc %s(%s) not empty", vpc.Name, vpc.Id)
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ func (obj *SDevtoolTemplate) PostUpdate(ctx context.Context, userCred mcclient.T
|
||||
task.ScheduleRun(nil)
|
||||
}
|
||||
|
||||
func (obj *SDevtoolTemplate) ValidateDeleteCondition(ctx context.Context) error {
|
||||
func (obj *SDevtoolTemplate) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
|
||||
template := obj
|
||||
items := make([]SCronjob, 0)
|
||||
|
||||
@@ -168,7 +168,7 @@ func (gi *SGuestImage) PostCreate(ctx context.Context, userCred mcclient.TokenCr
|
||||
gi.SetStatus(userCred, api.IMAGE_STATUS_SAVING, "")
|
||||
}
|
||||
|
||||
func (gi *SGuestImage) ValidateDeleteCondition(ctx context.Context) error {
|
||||
func (gi *SGuestImage) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
if gi.Protected.IsTrue() {
|
||||
return httperrors.NewForbiddenError("image is protected")
|
||||
}
|
||||
|
||||
@@ -707,7 +707,7 @@ func (self *SImage) AllowDeleteItem(ctx context.Context, userCred mcclient.Token
|
||||
return self.IsOwner(userCred) || db.IsAdminAllowDelete(userCred, self)
|
||||
}
|
||||
|
||||
func (self *SImage) ValidateDeleteCondition(ctx context.Context) error {
|
||||
func (self *SImage) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
if self.Protected.IsTrue() {
|
||||
return httperrors.NewForbiddenError("image is protected")
|
||||
}
|
||||
@@ -720,7 +720,7 @@ func (self *SImage) ValidateDeleteCondition(ctx context.Context) error {
|
||||
// if self.IsShared() {
|
||||
// return httperrors.NewForbiddenError("image is shared")
|
||||
// }
|
||||
return self.SSharableVirtualResourceBase.ValidateDeleteCondition(ctx)
|
||||
return self.SSharableVirtualResourceBase.ValidateDeleteCondition(ctx, nil)
|
||||
}
|
||||
|
||||
func (self *SImage) Delete(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
|
||||
@@ -148,7 +148,7 @@ func (self *SLDAPDriver) syncDomains(ctx context.Context, cli *ldaputils.SLDAPCl
|
||||
log.Errorf("domain.DeleteUserGroups error %s", err)
|
||||
continue
|
||||
}
|
||||
err = obsoleteDomain.ValidateDeleteCondition(ctx)
|
||||
err = obsoleteDomain.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil {
|
||||
log.Errorf("obsoleteDomain.ValidateDeleteCondition error %s", err)
|
||||
continue
|
||||
@@ -215,7 +215,7 @@ func (self *SLDAPDriver) syncUsers(ctx context.Context, cli *ldaputils.SLDAPClie
|
||||
log.Errorf("deleteUser.UnlinkIdp error %s", err)
|
||||
continue
|
||||
}
|
||||
err = deleteUsers[i].ValidateDeleteCondition(ctx)
|
||||
err = deleteUsers[i].ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil {
|
||||
log.Errorf("deleteUser.ValidateDeleteCondition error %s", err)
|
||||
continue
|
||||
@@ -296,7 +296,7 @@ func (self *SLDAPDriver) syncGroups(ctx context.Context, cli *ldaputils.SLDAPCli
|
||||
log.Errorf("deleteGroup.UnlinkIdp error %s", err)
|
||||
continue
|
||||
}
|
||||
err = deleteGroups[i].ValidateDeleteCondition(ctx)
|
||||
err = deleteGroups[i].ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil {
|
||||
log.Errorf("deleteGroup.ValidateDeleteCondition error %s", err)
|
||||
continue
|
||||
|
||||
@@ -163,8 +163,8 @@ func (manager *SCredentialManager) ValidateCreateData(ctx context.Context, userC
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func (self *SCredential) ValidateDeleteCondition(ctx context.Context) error {
|
||||
return self.SStandaloneResourceBase.ValidateDeleteCondition(ctx)
|
||||
func (self *SCredential) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
return self.SStandaloneResourceBase.ValidateDeleteCondition(ctx, nil)
|
||||
}
|
||||
|
||||
func (self *SCredential) ValidateUpdateData(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input api.CredentialUpdateInput) (api.CredentialUpdateInput, error) {
|
||||
|
||||
@@ -310,7 +310,7 @@ func (domain *SDomain) ValidatePurgeCondition(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (domain *SDomain) ValidateDeleteCondition(ctx context.Context) error {
|
||||
func (domain *SDomain) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
if domain.IsReadOnly() {
|
||||
return httperrors.NewForbiddenError("readonly")
|
||||
}
|
||||
@@ -318,7 +318,7 @@ func (domain *SDomain) ValidateDeleteCondition(ctx context.Context) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return domain.SStandaloneResourceBase.ValidateDeleteCondition(ctx)
|
||||
return domain.SStandaloneResourceBase.ValidateDeleteCondition(ctx, nil)
|
||||
}
|
||||
|
||||
func (domain *SDomain) ValidateUpdateCondition(ctx context.Context) error {
|
||||
@@ -419,7 +419,7 @@ func (domain *SDomain) DeleteUserGroups(ctx context.Context, userCred mcclient.T
|
||||
return errors.Wrap(err, "domain.getUsers")
|
||||
}
|
||||
for i := range usrs {
|
||||
err = usrs[i].ValidateDeleteCondition(ctx)
|
||||
err = usrs[i].ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "usr.ValidateDeleteCondition")
|
||||
}
|
||||
@@ -433,7 +433,7 @@ func (domain *SDomain) DeleteUserGroups(ctx context.Context, userCred mcclient.T
|
||||
return errors.Wrap(err, "domain.getGroups")
|
||||
}
|
||||
for i := range grps {
|
||||
err = grps[i].ValidateDeleteCondition(ctx)
|
||||
err = grps[i].ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "grp.ValidateDeleteCondition")
|
||||
}
|
||||
|
||||
@@ -466,11 +466,11 @@ func fetchServices(srvIds []string) map[string]SService {
|
||||
return ret
|
||||
}
|
||||
|
||||
func (endpoint *SEndpoint) ValidateDeleteCondition(ctx context.Context) error {
|
||||
func (endpoint *SEndpoint) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
if endpoint.Enabled.IsTrue() {
|
||||
return httperrors.NewInvalidStatusError("endpoint is enabled")
|
||||
}
|
||||
return endpoint.SStandaloneResourceBase.ValidateDeleteCondition(ctx)
|
||||
return endpoint.SStandaloneResourceBase.ValidateDeleteCondition(ctx, nil)
|
||||
}
|
||||
|
||||
func (manager *SEndpointManager) ValidateCreateData(
|
||||
|
||||
@@ -173,11 +173,11 @@ func (group *SGroup) GetProjectCount() (int, error) {
|
||||
return q.CountWithError()
|
||||
}
|
||||
|
||||
func (group *SGroup) ValidateDeleteCondition(ctx context.Context) error {
|
||||
func (group *SGroup) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
if group.IsReadOnly() {
|
||||
return httperrors.NewForbiddenError("readonly")
|
||||
}
|
||||
return group.SIdentityBaseResource.ValidateDeleteCondition(ctx)
|
||||
return group.SIdentityBaseResource.ValidateDeleteCondition(ctx, nil)
|
||||
}
|
||||
|
||||
func (group *SGroup) Delete(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user