Skip to content

Commit

Permalink
fix(region): cloud account sync log (#17772)
Browse files Browse the repository at this point in the history
  • Loading branch information
ioito authored Aug 21, 2023
1 parent b4dd994 commit 3b14709
Show file tree
Hide file tree
Showing 3 changed files with 150 additions and 47 deletions.
16 changes: 8 additions & 8 deletions pkg/compute/models/cloudprovider_quotas.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ type SCloudproviderQuota struct {

// 已使用的配额
// -1代表未从云平台拿到已使用配额信息
UsedCount int `nullable:"false" default:"0" list:"user"`
UsedCount int64 `nullable:"false" default:"0" list:"user"`

// 最大配额限制
MaxCount int `nullable:"false" default:"0" list:"user"`
MaxCount int64 `nullable:"false" default:"0" list:"user"`

// 配额类型
QuotaType string `width:"64" charset:"ascii" list:"user"`
Expand Down Expand Up @@ -207,7 +207,7 @@ func (manager *SCloudproviderQuotaManager) SyncQuotas(ctx context.Context, userC

dbQuotas, err := manager.GetQuotas(provider, region, quotaRange)
if err != nil {
result.Error(err)
result.Error(errors.Wrapf(err, "GetQuotas"))
return result
}

Expand All @@ -217,7 +217,7 @@ func (manager *SCloudproviderQuotaManager) SyncQuotas(ctx context.Context, userC
added := make([]cloudprovider.ICloudQuota, 0)
err = compare.CompareSets(dbQuotas, iQuotas, &removed, &commondb, &commonext, &added)
if err != nil {
result.Error(err)
result.Error(errors.Wrapf(err, "CompareSets"))
return result
}

Expand Down Expand Up @@ -255,8 +255,8 @@ func (manager *SCloudproviderQuotaManager) SyncQuotas(ctx context.Context, userC

func (self *SCloudproviderQuota) SyncWithCloudQuota(ctx context.Context, userCred mcclient.TokenCredential, iQuota cloudprovider.ICloudQuota) error {
_, err := db.UpdateWithLock(ctx, self, func() error {
self.UsedCount = iQuota.GetCurrentQuotaUsedCount()
self.MaxCount = iQuota.GetMaxQuotaCount()
self.UsedCount = int64(iQuota.GetCurrentQuotaUsedCount())
self.MaxCount = int64(iQuota.GetMaxQuotaCount())
return nil
})
return err
Expand All @@ -272,8 +272,8 @@ func (manager *SCloudproviderQuotaManager) newFromCloudQuota(ctx context.Context
quota.ManagerId = provider.Id
quota.QuotaType = iQuota.GetQuotaType()
quota.QuotaRange = quotaRange
quota.UsedCount = iQuota.GetCurrentQuotaUsedCount()
quota.MaxCount = iQuota.GetMaxQuotaCount()
quota.UsedCount = int64(iQuota.GetCurrentQuotaUsedCount())
quota.MaxCount = int64(iQuota.GetMaxQuotaCount())
if region != nil {
quota.CloudregionId = region.Id
}
Expand Down
19 changes: 19 additions & 0 deletions pkg/compute/models/cloudproviders.go
Original file line number Diff line number Diff line change
Expand Up @@ -2166,3 +2166,22 @@ func (self *SCloudprovider) PerformSetSyncing(ctx context.Context, userCred mccl
}
return nil, nil
}

func (self *SCloudprovider) SyncError(result compare.SyncResult, iNotes interface{}, userCred mcclient.TokenCredential) {
if result.IsError() {
account := &SCloudaccount{}
account.Id = self.CloudaccountId
account.Name = self.Account
if len(account.Name) == 0 {
account.Name = self.Name
}
account.SetModelManager(CloudaccountManager, account)
logclient.AddSimpleActionLog(account, logclient.ACT_CLOUD_SYNC, iNotes, userCred, false)
}
}

func (self *SCloudaccount) SyncError(result compare.SyncResult, iNotes interface{}, userCred mcclient.TokenCredential) {
if result.IsError() {
logclient.AddSimpleActionLog(self, logclient.ACT_CLOUD_SYNC, iNotes, userCred, false)
}
}
Loading

0 comments on commit 3b14709

Please sign in to comment.