mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
修正:qutoa的images使用量不准确
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user