diff --git a/pkg/compute/models/quotas.go b/pkg/compute/models/quotas.go index a92cb7c84b..c96f90a6a6 100644 --- a/pkg/compute/models/quotas.go +++ b/pkg/compute/models/quotas.go @@ -8,6 +8,8 @@ import ( "yunion.io/x/onecloud/pkg/cloudcommon/db/quotas" "yunion.io/x/onecloud/pkg/compute/options" "yunion.io/x/pkg/tristate" + "yunion.io/x/onecloud/pkg/mcclient/auth" + "yunion.io/x/onecloud/pkg/mcclient/modules" ) var QuotaManager *quotas.SQuotaManager @@ -85,7 +87,8 @@ func (self *SQuota) FetchUsage(projectId string) error { self.Bw = net.InternalBandwidth self.Ebw = net.ExternalBandwidth self.Keypair = 0 // keypair - self.Image = 0 + s := auth.GetAdminSession("", "") + self.Image, _ = modules.Images.GetPrivateImageCount(s, projectId, true) self.Group = 0 self.Secgroup = totalSecurityGroupCount(projectId) self.IsolatedDevice = guest.TotalIsolatedCount diff --git a/pkg/mcclient/modules/mod_images.go b/pkg/mcclient/modules/mod_images.go index 76356af376..611ce702b7 100644 --- a/pkg/mcclient/modules/mod_images.go +++ b/pkg/mcclient/modules/mod_images.go @@ -128,6 +128,21 @@ func (this *ImageManager) List(session *mcclient.ClientSession, params jsonutils return this._list(session, path, this.KeywordPlural) } +func (this *ImageManager) GetPrivateImageCount(s *mcclient.ClientSession, ownerId string, isAdmin bool) (int, error) { + params := jsonutils.NewDict() + params.Add(jsonutils.NewString("none"), "is_public") + params.Add(jsonutils.NewString(ownerId), "owner") + if isAdmin { + params.Add(jsonutils.JSONTrue, "admin") + } + + result, err := this.List(s, params) + if err != nil { + return 0, err + } + return len(result.Data), nil +} + type ImageUsageCount struct { Count int64 Size int64