mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-08-31 01:35:56 +08:00
fix: not clean pending domain usage
This commit is contained in:
@@ -364,7 +364,7 @@ func (scm *SCloudaccountManager) PerformPrepareNets(ctx context.Context, userCre
|
||||
if ownerId == nil {
|
||||
ownerId = userCred
|
||||
}
|
||||
input.CloudaccountCreateInput, err = scm.ValidateCreateData(ctx, userCred, ownerId, query, input.CloudaccountCreateInput)
|
||||
input.CloudaccountCreateInput, err = scm.validateCreateData(ctx, userCred, ownerId, query, input.CloudaccountCreateInput)
|
||||
if err != nil {
|
||||
return output, err
|
||||
}
|
||||
@@ -891,11 +891,42 @@ func (manager *SCloudaccountManager) ValidateCreateData(
|
||||
ownerId mcclient.IIdentityProvider,
|
||||
query jsonutils.JSONObject,
|
||||
input api.CloudaccountCreateInput,
|
||||
) (api.CloudaccountCreateInput, error) {
|
||||
input, err := manager.validateCreateData(ctx, userCred, ownerId, query, input)
|
||||
if err != nil {
|
||||
return input, errors.Wrap(err, "validateCreateData")
|
||||
}
|
||||
|
||||
input.EnabledStatusInfrasResourceBaseCreateInput, err = manager.SEnabledStatusInfrasResourceBaseManager.ValidateCreateData(ctx, userCred, ownerId, query, input.EnabledStatusInfrasResourceBaseCreateInput)
|
||||
if err != nil {
|
||||
return input, errors.Wrap(err, "SEnabledStatusInfrasResourceBaseManager.ValidateCreateData")
|
||||
}
|
||||
|
||||
quota := &SDomainQuota{
|
||||
SBaseDomainQuotaKeys: quotas.SBaseDomainQuotaKeys{
|
||||
DomainId: ownerId.GetProjectDomainId(),
|
||||
},
|
||||
Cloudaccount: 1,
|
||||
}
|
||||
err = quotas.CheckSetPendingQuota(ctx, userCred, quota)
|
||||
if err != nil {
|
||||
return input, errors.Wrapf(err, "CheckSetPendingQuota")
|
||||
}
|
||||
|
||||
return input, nil
|
||||
}
|
||||
|
||||
func (manager *SCloudaccountManager) validateCreateData(
|
||||
ctx context.Context,
|
||||
userCred mcclient.TokenCredential,
|
||||
ownerId mcclient.IIdentityProvider,
|
||||
query jsonutils.JSONObject,
|
||||
input api.CloudaccountCreateInput,
|
||||
) (api.CloudaccountCreateInput, error) {
|
||||
// check domainId
|
||||
err := db.ValidateCreateDomainId(ownerId.GetProjectDomainId())
|
||||
if err != nil {
|
||||
return input, err
|
||||
return input, errors.Wrap(err, "db.ValidateCreateDomainId")
|
||||
}
|
||||
|
||||
if !cloudprovider.IsSupported(input.Provider) {
|
||||
@@ -1006,22 +1037,6 @@ func (manager *SCloudaccountManager) ValidateCreateData(
|
||||
input.SyncIntervalSeconds = options.Options.MinimalSyncIntervalSeconds
|
||||
}
|
||||
|
||||
input.EnabledStatusInfrasResourceBaseCreateInput, err = manager.SEnabledStatusInfrasResourceBaseManager.ValidateCreateData(ctx, userCred, ownerId, query, input.EnabledStatusInfrasResourceBaseCreateInput)
|
||||
if err != nil {
|
||||
return input, err
|
||||
}
|
||||
|
||||
quota := &SDomainQuota{
|
||||
SBaseDomainQuotaKeys: quotas.SBaseDomainQuotaKeys{
|
||||
DomainId: ownerId.GetProjectDomainId(),
|
||||
},
|
||||
Cloudaccount: 1,
|
||||
}
|
||||
err = quotas.CheckSetPendingQuota(ctx, userCred, quota)
|
||||
if err != nil {
|
||||
return input, errors.Wrapf(err, "CheckSetPendingQuota")
|
||||
}
|
||||
|
||||
return input, nil
|
||||
}
|
||||
|
||||
@@ -1053,9 +1068,6 @@ func (self *SCloudaccount) CustomizeCreate(ctx context.Context, userCred mcclien
|
||||
}
|
||||
|
||||
func (self *SCloudaccount) PostCreate(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, data jsonutils.JSONObject) {
|
||||
self.SEnabledStatusInfrasResourceBase.PostCreate(ctx, userCred, ownerId, query, data)
|
||||
self.savePassword(self.Secret)
|
||||
|
||||
quota := &SDomainQuota{
|
||||
SBaseDomainQuotaKeys: quotas.SBaseDomainQuotaKeys{
|
||||
DomainId: ownerId.GetProjectDomainId(),
|
||||
@@ -1066,6 +1078,10 @@ func (self *SCloudaccount) PostCreate(ctx context.Context, userCred mcclient.Tok
|
||||
if err != nil {
|
||||
log.Errorf("CancelPendingUsage fail %s", err)
|
||||
}
|
||||
|
||||
self.SEnabledStatusInfrasResourceBase.PostCreate(ctx, userCred, ownerId, query, data)
|
||||
self.savePassword(self.Secret)
|
||||
|
||||
if self.Enabled.IsTrue() {
|
||||
self.StartSyncCloudProviderInfoTask(ctx, userCred, nil, "")
|
||||
}
|
||||
|
||||
@@ -149,6 +149,18 @@ func (manager *SDnsZoneManager) ValidateCreateData(ctx context.Context, userCred
|
||||
}
|
||||
|
||||
func (self *SDnsZone) PostCreate(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, data jsonutils.JSONObject) {
|
||||
quota := &SDomainQuota{
|
||||
SBaseDomainQuotaKeys: quotas.SBaseDomainQuotaKeys{
|
||||
DomainId: ownerId.GetProjectDomainId(),
|
||||
},
|
||||
DnsZone: 1,
|
||||
}
|
||||
err := quotas.CancelPendingUsage(ctx, userCred, quota, quota, true)
|
||||
if err != nil {
|
||||
log.Errorf("SDnsZone CancelPendingUsage fail %s", err)
|
||||
}
|
||||
self.SEnabledStatusInfrasResourceBase.PostCreate(ctx, userCred, ownerId, query, data)
|
||||
|
||||
input := &api.DnsZoneCreateInput{}
|
||||
data.Unmarshal(input)
|
||||
switch cloudprovider.TDnsZoneType(input.ZoneType) {
|
||||
@@ -873,3 +885,14 @@ func (manager *SDnsZoneManager) totalCount(scope rbacutils.TRbacScope, ownerId m
|
||||
cnt, _ := q.CountWithError()
|
||||
return cnt
|
||||
}
|
||||
|
||||
func (dzone *SDnsZone) GetUsages() []db.IUsage {
|
||||
if dzone.Deleted {
|
||||
return nil
|
||||
}
|
||||
usage := SDomainQuota{DnsZone: 1}
|
||||
usage.SetKeys(quotas.SBaseDomainQuotaKeys{DomainId: dzone.DomainId})
|
||||
return []db.IUsage{
|
||||
&usage,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user