diff --git a/pkg/compute/models/storages.go b/pkg/compute/models/storages.go index 0093f4de8b..75f220c324 100644 --- a/pkg/compute/models/storages.go +++ b/pkg/compute/models/storages.go @@ -105,6 +105,30 @@ func (manager *SStorageManager) AllowListItems(ctx context.Context, userCred mcc return true } +func (self *SStorage) getMoreDetails(extra *jsonutils.JSONDict) *jsonutils.JSONDict { + used := self.GetUsedCapacity(tristate.True) + waste := self.GetUsedCapacity(tristate.False) + vcapa := float32(self.GetCapacity()) * self.GetOvercommitBound() + extra.Add(jsonutils.NewInt(int64(used)), "used_capacity") + extra.Add(jsonutils.NewInt(int64(waste)), "waste_capacity") + extra.Add(jsonutils.NewFloat(float64(vcapa)), "virtual_capacity") + extra.Add(jsonutils.NewFloat(float64(vcapa-float32(used)-float32(waste))), "free_capacity") + if self.GetCapacity() > 0 { + value := float64(used * 1.0 / self.GetCapacity()) + value = float64(int(value*100+0.5) / 100.0) + extra.Add(jsonutils.NewFloat(value), "commit_rate") + } else { + extra.Add(jsonutils.NewFloat(0.0), "commit_rate") + } + extra.Add(jsonutils.NewFloat(float64(self.GetOvercommitBound())), "commit_bound") + return extra +} + +func (self *SStorage) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { + extra := self.SEnabledStatusStandaloneResourceBase.GetCustomizeColumns(ctx, userCred, query) + return self.getMoreDetails(extra) +} + func (self *SStorage) GetUsedCapacity(isReady tristate.TriState) int { disks := DiskManager.Query().SubQuery() q := disks.Query(sqlchemy.SUM("sum", disks.Field("disk_size"))).Equals("storage_id", self.Id)