mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-19 02:37:24 +08:00
fix: image quota key type mismatch
This commit is contained in:
@@ -39,7 +39,6 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/image/options"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/pkg/util/logclient"
|
||||
"yunion.io/x/onecloud/pkg/util/rbacutils"
|
||||
)
|
||||
|
||||
type SGuestImageManager struct {
|
||||
@@ -75,7 +74,8 @@ func (manager *SGuestImageManager) ValidateCreateData(ctx context.Context, userC
|
||||
imageNum, _ := data.Int("image_number")
|
||||
|
||||
pendingUsage := SQuota{Image: int(imageNum)}
|
||||
keys := quotas.OwnerIdQuotaKeys(rbacutils.ScopeProject, ownerId)
|
||||
data.Set("disk_format", jsonutils.NewString("qcow2"))
|
||||
keys := imageCreateInput2QuotaKeys(data, ownerId)
|
||||
pendingUsage.SetKeys(keys)
|
||||
if err := quotas.CheckSetPendingQuota(ctx, userCred, &pendingUsage); err != nil {
|
||||
|
||||
@@ -148,7 +148,7 @@ func (gi *SGuestImage) PostCreate(ctx context.Context, userCred mcclient.TokenCr
|
||||
|
||||
imageNumber, _ := data.Int("image_number")
|
||||
pendingUsage := SQuota{Image: int(imageNumber)}
|
||||
keys := quotas.OwnerIdQuotaKeys(rbacutils.ScopeProject, ownerId)
|
||||
keys := imageCreateInput2QuotaKeys(data, ownerId)
|
||||
pendingUsage.SetKeys(keys)
|
||||
quotas.CancelPendingUsage(ctx, userCred, &pendingUsage, &pendingUsage)
|
||||
|
||||
|
||||
@@ -373,7 +373,7 @@ func (manager *SImageManager) ValidateCreateData(ctx context.Context, userCred m
|
||||
// because that pending quota has been checked and set in SGuestImage.ValidateCreateData
|
||||
if !data.Contains("guest_image_id") {
|
||||
pendingUsage := SQuota{Image: 1}
|
||||
keys := quotas.OwnerIdQuotaKeys(rbacutils.ScopeProject, ownerId)
|
||||
keys := imageCreateInput2QuotaKeys(data, ownerId)
|
||||
pendingUsage.SetKeys(keys)
|
||||
if err := quotas.CheckSetPendingQuota(ctx, userCred, &pendingUsage); err != nil {
|
||||
return nil, httperrors.NewOutOfQuotaError("%s", err)
|
||||
@@ -503,9 +503,12 @@ func (self *SImage) PostCreate(ctx context.Context, userCred mcclient.TokenCrede
|
||||
// if SImage belong to a guest image, pending quota will not be set.
|
||||
if self.IsGuestImage.IsFalse() {
|
||||
pendingUsage := SQuota{Image: 1}
|
||||
keys := quotas.OwnerIdQuotaKeys(rbacutils.ScopeProject, ownerId)
|
||||
keys := imageCreateInput2QuotaKeys(data, ownerId)
|
||||
pendingUsage.SetKeys(keys)
|
||||
quotas.CancelPendingUsage(ctx, userCred, &pendingUsage, &pendingUsage)
|
||||
cancelUsage := SQuota{Image: 1}
|
||||
keys = self.GetQuotaKeys()
|
||||
cancelUsage.SetKeys(keys)
|
||||
quotas.CancelPendingUsage(ctx, userCred, &pendingUsage, &cancelUsage)
|
||||
}
|
||||
|
||||
if data.Contains("properties") {
|
||||
@@ -1289,6 +1292,18 @@ func (img *SImage) GetQuotaKeys() quotas.IQuotaKeys {
|
||||
return keys
|
||||
}
|
||||
|
||||
func imageCreateInput2QuotaKeys(data jsonutils.JSONObject, ownerId mcclient.IIdentityProvider) quotas.IQuotaKeys {
|
||||
keys := SImageQuotaKeys{}
|
||||
keys.SBaseQuotaKeys = quotas.OwnerIdQuotaKeys(rbacutils.ScopeProject, ownerId)
|
||||
format, _ := data.GetString("disk_format")
|
||||
if format == string(api.ImageTypeISO) {
|
||||
keys.Type = string(api.ImageTypeISO)
|
||||
} else if len(format) > 0 {
|
||||
keys.Type = string(api.ImageTypeTemplate)
|
||||
}
|
||||
return keys
|
||||
}
|
||||
|
||||
func (img *SImage) GetUsages() []db.IUsage {
|
||||
if img.PendingDeleted || img.Deleted {
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user