mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix(region): remove useless code (#19567)
This commit is contained in:
@@ -24,6 +24,7 @@ type LoadbalancerBackendGroupDetails struct {
|
||||
|
||||
LbListenerCount int `json:"lb_listener_count"`
|
||||
|
||||
IsDefault bool `json:"is_default"`
|
||||
ProjectId string `json:"tenant_id"`
|
||||
}
|
||||
|
||||
|
||||
@@ -1138,10 +1138,6 @@ func (bucket *SBucket) PerformSync(
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (bucket *SBucket) ValidatePurgeCondition(ctx context.Context) error {
|
||||
return bucket.SSharableVirtualResourceBase.ValidateDeleteCondition(ctx, nil)
|
||||
}
|
||||
|
||||
func (bucket *SBucket) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
if bucket.Status == api.BUCKET_STATUS_UNKNOWN {
|
||||
return bucket.SSharableVirtualResourceBase.ValidateDeleteCondition(ctx, nil)
|
||||
@@ -1149,7 +1145,7 @@ func (bucket *SBucket) ValidateDeleteCondition(ctx context.Context, info jsonuti
|
||||
if bucket.ObjectCnt > 0 {
|
||||
return httperrors.NewNotEmptyError("Buckets that are not empty do not support this operation")
|
||||
}
|
||||
return bucket.ValidatePurgeCondition(ctx)
|
||||
return bucket.SSharableVirtualResourceBase.ValidateDeleteCondition(ctx, info)
|
||||
}
|
||||
|
||||
// 获取对象或bucket的ACL
|
||||
|
||||
@@ -1225,10 +1225,6 @@ func (self *SDisk) ValidateDeleteCondition(ctx context.Context, info api.DiskDet
|
||||
return self.SVirtualResourceBase.ValidateDeleteCondition(ctx, nil)
|
||||
}
|
||||
|
||||
func (self *SDisk) ValidatePurgeCondition(ctx context.Context) error {
|
||||
return self.validateDeleteCondition(ctx, true)
|
||||
}
|
||||
|
||||
func (self *SDisk) validateDeleteCondition(ctx context.Context, isPurge bool) error {
|
||||
if !isPurge {
|
||||
storage, _ := self.GetStorage()
|
||||
@@ -1621,7 +1617,7 @@ func (self *SDisk) syncRemoveCloudDisk(ctx context.Context, userCred mcclient.To
|
||||
return err
|
||||
}
|
||||
|
||||
err = self.ValidatePurgeCondition(ctx)
|
||||
err = self.validateDeleteCondition(ctx, true)
|
||||
if err != nil {
|
||||
self.SetStatus(ctx, userCred, api.DISK_UNKNOWN, "missing original disk after sync")
|
||||
return err
|
||||
@@ -2219,7 +2215,7 @@ func (self *SDisk) PerformSyncstatus(ctx context.Context, userCred mcclient.Toke
|
||||
}
|
||||
|
||||
func (self *SDisk) PerformPurge(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
err := self.ValidatePurgeCondition(ctx)
|
||||
err := self.validateDeleteCondition(ctx, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -508,10 +508,6 @@ func (self *SElasticcacheAccount) GetDetailsLoginInfo(ctx context.Context, userC
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (self *SElasticcacheAccount) ValidatePurgeCondition(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// 弹性缓存账号列表
|
||||
func (manager *SElasticcacheAccountManager) ListItemFilter(
|
||||
ctx context.Context,
|
||||
|
||||
@@ -306,10 +306,6 @@ func (self *SElasticcacheAcl) ValidateDeleteCondition(ctx context.Context, info
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SElasticcacheAcl) ValidatePurgeCondition(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SElasticcacheAcl) CustomizeDelete(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) error {
|
||||
self.SetStatus(ctx, userCred, api.ELASTIC_CACHE_ACL_STATUS_DELETING, "")
|
||||
return self.StartDeleteElasticcacheAclTask(ctx, userCred, jsonutils.NewDict(), "")
|
||||
|
||||
@@ -333,11 +333,7 @@ func (self *SElasticcacheBackup) ValidateDeleteCondition(ctx context.Context, in
|
||||
return httperrors.NewUnsupportOperationError("unsupport delete %s backups", api.CLOUD_PROVIDER_ALIYUN)
|
||||
}
|
||||
|
||||
return self.ValidatePurgeCondition(ctx)
|
||||
}
|
||||
|
||||
func (self *SElasticcacheBackup) ValidatePurgeCondition(ctx context.Context) error {
|
||||
return nil
|
||||
return self.SStatusStandaloneResourceBase.ValidateDeleteCondition(ctx, info)
|
||||
}
|
||||
|
||||
// 弹性缓存备份列表
|
||||
|
||||
@@ -998,10 +998,6 @@ func (self *SElasticcache) ValidateDeleteCondition(ctx context.Context, info jso
|
||||
return httperrors.NewInvalidStatusError("Elastic cache is not expired, cannot delete")
|
||||
}
|
||||
|
||||
return self.ValidatePurgeCondition(ctx)
|
||||
}
|
||||
|
||||
func (self *SElasticcache) ValidatePurgeCondition(ctx context.Context) error {
|
||||
return self.SVirtualResourceBase.ValidateDeleteCondition(ctx, nil)
|
||||
}
|
||||
|
||||
|
||||
@@ -246,10 +246,6 @@ func (self *SElasticcacheParameter) StartUpdateElasticcacheParameterTask(ctx con
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SElasticcacheParameter) ValidatePurgeCondition(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// 列出弹性缓存参数
|
||||
func (manager *SElasticcacheParameterManager) ListItemFilter(
|
||||
ctx context.Context,
|
||||
|
||||
@@ -1548,7 +1548,7 @@ func (self *SGuest) StartDeleteGuestTask(
|
||||
}
|
||||
|
||||
func (self *SGuest) PerformPurge(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
err := self.ValidatePurgeCondition(ctx)
|
||||
err := self.validateDeleteCondition(ctx, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -924,10 +924,6 @@ func (guest *SGuest) validateDeleteCondition(ctx context.Context, isPurge bool)
|
||||
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, info *api.ServerDetails) error {
|
||||
if gotypes.IsNil(info) {
|
||||
info = &api.ServerDetails{}
|
||||
|
||||
@@ -774,10 +774,6 @@ func (hh *SHost) ValidateDeleteCondition(ctx context.Context, info api.HostDetai
|
||||
return hh.SEnabledStatusInfrasResourceBase.ValidateDeleteCondition(ctx, nil)
|
||||
}
|
||||
|
||||
func (hh *SHost) ValidatePurgeCondition(ctx context.Context) error {
|
||||
return hh.validateDeleteCondition(ctx, true)
|
||||
}
|
||||
|
||||
func (hh *SHost) validateDeleteCondition(ctx context.Context, purge bool) error {
|
||||
if !purge && hh.IsBaremetal && hh.HostType != api.HOST_TYPE_BAREMETAL {
|
||||
return httperrors.NewInvalidStatusError("Host is a converted baremetal, should be unconverted before delete")
|
||||
@@ -1890,7 +1886,7 @@ func (hh *SHost) syncRemoveCloudHost(ctx context.Context, userCred mcclient.Toke
|
||||
lockman.LockObject(ctx, hh)
|
||||
defer lockman.ReleaseObject(ctx, hh)
|
||||
|
||||
err := hh.ValidatePurgeCondition(ctx)
|
||||
err := hh.validateDeleteCondition(ctx, true)
|
||||
if err != nil {
|
||||
err = hh.purge(ctx, userCred)
|
||||
if err != nil {
|
||||
|
||||
@@ -22,8 +22,10 @@ import (
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/gotypes"
|
||||
"yunion.io/x/pkg/util/compare"
|
||||
"yunion.io/x/pkg/util/rbacscope"
|
||||
"yunion.io/x/pkg/utils"
|
||||
"yunion.io/x/sqlchemy"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
@@ -405,31 +407,21 @@ func (lbbg *SLoadbalancerBackendGroup) isDefault(ctx context.Context) (bool, err
|
||||
return count > 0, nil
|
||||
}
|
||||
|
||||
func (lbbg *SLoadbalancerBackendGroup) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
ok, err := lbbg.isDefault(ctx)
|
||||
if err != nil {
|
||||
return httperrors.NewInternalServerError("get isDefault fail %s", err.Error())
|
||||
func (lbbg *SLoadbalancerBackendGroup) ValidateDeleteCondition(ctx context.Context, info *api.LoadbalancerBackendGroupDetails) error {
|
||||
if gotypes.IsNil(info) {
|
||||
info = &api.LoadbalancerBackendGroupDetails{}
|
||||
info.IsDefault, _ = lbbg.isDefault(ctx)
|
||||
info.LbListenerCount, _ = lbbg.GetListenerCount()
|
||||
}
|
||||
if ok {
|
||||
if info.IsDefault {
|
||||
return httperrors.NewResourceBusyError("backend group %s is default backend group", lbbg.Id)
|
||||
}
|
||||
return lbbg.ValidatePurgeCondition(ctx)
|
||||
}
|
||||
|
||||
func (lbbg *SLoadbalancerBackendGroup) ValidatePurgeCondition(ctx context.Context) error {
|
||||
mans := lbbg.getRefManagers()
|
||||
for _, m := range mans {
|
||||
n, err := lbbg.refCount(m)
|
||||
if err != nil {
|
||||
return httperrors.NewInternalServerError("get refCount fail %s", err.Error())
|
||||
}
|
||||
if n > 0 {
|
||||
return httperrors.NewResourceBusyError("backend group %s is still referred by %d %s",
|
||||
lbbg.Id, n, m.KeywordPlural())
|
||||
}
|
||||
if info.LbListenerCount > 0 {
|
||||
return httperrors.NewResourceBusyError("backend group %s is still referred by %d %s",
|
||||
lbbg.Id, info.LbListenerCount, LoadbalancerListenerManager.KeywordPlural())
|
||||
}
|
||||
|
||||
return nil
|
||||
return lbbg.SStatusStandaloneResourceBase.ValidateDeleteCondition(ctx, nil)
|
||||
}
|
||||
|
||||
func (man *SLoadbalancerBackendGroupManager) FetchCustomizeColumns(
|
||||
@@ -446,6 +438,7 @@ func (man *SLoadbalancerBackendGroupManager) FetchCustomizeColumns(
|
||||
lbRows := man.SLoadbalancerResourceBaseManager.FetchCustomizeColumns(ctx, userCred, query, objs, fields, isList)
|
||||
|
||||
lbIds := make([]string, len(objs))
|
||||
lbbgIds := make([]string, len(objs))
|
||||
for i := range rows {
|
||||
rows[i] = api.LoadbalancerBackendGroupDetails{
|
||||
StatusStandaloneResourceDetails: stdRows[i],
|
||||
@@ -453,6 +446,7 @@ func (man *SLoadbalancerBackendGroupManager) FetchCustomizeColumns(
|
||||
}
|
||||
lbbg := objs[i].(*SLoadbalancerBackendGroup)
|
||||
lbIds[i] = lbbg.LoadbalancerId
|
||||
lbbgIds[i] = lbbg.Id
|
||||
}
|
||||
|
||||
lbs := map[string]SLoadbalancer{}
|
||||
@@ -461,16 +455,23 @@ func (man *SLoadbalancerBackendGroupManager) FetchCustomizeColumns(
|
||||
return rows
|
||||
}
|
||||
|
||||
defaultLbgIds := []string{}
|
||||
virObjs := make([]interface{}, len(objs))
|
||||
for i := range rows {
|
||||
if lb, ok := lbs[lbIds[i]]; ok {
|
||||
virObjs[i] = &lb
|
||||
rows[i].ProjectId = lb.ProjectId
|
||||
if !utils.IsInStringArray(lb.BackendGroupId, defaultLbgIds) {
|
||||
defaultLbgIds = append(defaultLbgIds, lb.BackendGroupId)
|
||||
}
|
||||
}
|
||||
}
|
||||
for i := range rows {
|
||||
rows[i].IsDefault = utils.IsInStringArray(lbbgIds[i], defaultLbgIds)
|
||||
}
|
||||
|
||||
for i := range objs {
|
||||
q := LoadbalancerListenerManager.Query().Equals("backend_group_id", objs[i].(*SLoadbalancerBackendGroup).GetId())
|
||||
q := LoadbalancerListenerManager.Query().Equals("backend_group_id", lbbgIds[i])
|
||||
ownerId, queryScope, err, _ := db.FetchCheckQueryOwnerScope(ctx, userCred, query, LoadbalancerListenerManager, policy.PolicyActionList, true)
|
||||
if err != nil {
|
||||
log.Errorf("FetchCheckQueryOwnerScope error: %v", err)
|
||||
@@ -566,6 +567,10 @@ func (lbbg *SLoadbalancerBackendGroup) GetListener() *SLoadbalancerListener {
|
||||
return ret
|
||||
}
|
||||
|
||||
func (lbbg *SLoadbalancerBackendGroup) GetListenerCount() (int, error) {
|
||||
return LoadbalancerListenerManager.Query().Equals("backend_group_id", lbbg.Id).CountWithError()
|
||||
}
|
||||
|
||||
func (lbbg *SLoadbalancerBackendGroup) GetBackendsParams() ([]cloudprovider.SLoadbalancerBackend, error) {
|
||||
backends, err := lbbg.GetBackends()
|
||||
if err != nil {
|
||||
|
||||
@@ -896,7 +896,7 @@ func (self *SIdentityProvider) Purge(ctx context.Context, userCred mcclient.Toke
|
||||
err = domains[i].ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil {
|
||||
db.OpsLog.LogEvent(&domains[i], db.ACT_DELETE_FAIL, err, userCred)
|
||||
return errors.Wrap(err, "domain.ValidatePurgeCondition")
|
||||
return errors.Wrap(err, "domain.ValidateDeleteCondition")
|
||||
}
|
||||
err = domains[i].UnlinkIdp(self.Id)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user