From 04e79b5140afee87353944c1567a82f3d5601773 Mon Sep 17 00:00:00 2001 From: Qiu Jian Date: Sat, 14 Mar 2020 21:55:12 +0800 Subject: [PATCH] fix: storage details missing capacity fields since 3.1 --- pkg/apis/compute/storage.go | 19 ++++++++++++------- pkg/compute/models/hosts.go | 14 +++++++++----- pkg/compute/models/storages.go | 8 +------- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/pkg/apis/compute/storage.go b/pkg/apis/compute/storage.go index 3c8da6f9c7..d05a276a4d 100644 --- a/pkg/apis/compute/storage.go +++ b/pkg/apis/compute/storage.go @@ -112,22 +112,27 @@ type StorageCreateInput struct { NfsSharedDir string `json:"nfs_shared_dir"` } -type StorageDetails struct { - apis.StandaloneResourceDetails - SStorage - +type SStorageCapacityInfo struct { // 容量大小, 单位Mb Capacity int64 `json:"capacity"` // 已使用容量大小 - Used int64 `json:"used"` + UsedCapacity int64 `json:"used_capacity"` // 浪费容量大小(异常磁盘大小总和) - Wasted int64 `json:"wasted"` + WasteCapacity int64 `json:"waste_capacity"` // 虚拟容量大小 - VCapacity int64 `json:"vcapacity"` + VirtualCapacity int64 `json:"virtual_capacity"` // 超分率 CommitRate float64 `json:"commit_rate"` // 可使用容量 FreeCapacity int64 `json:"free_capacity"` +} + +type StorageDetails struct { + apis.StandaloneResourceDetails + + SStorageCapacityInfo + + SStorage CloudproviderInfo Schedtags []SchedtagShortDescDetails `json:"schedtags"` diff --git a/pkg/compute/models/hosts.go b/pkg/compute/models/hosts.go index d74cca1552..5377cf04a2 100644 --- a/pkg/compute/models/hosts.go +++ b/pkg/compute/models/hosts.go @@ -1066,11 +1066,15 @@ func (cap *SStorageCapacity) Add(cap2 SStorageCapacity) { cap.VCapacity += cap2.VCapacity } -func (cap *SStorageCapacity) ToJson() *jsonutils.JSONDict { - ret := jsonutils.Marshal(cap).(*jsonutils.JSONDict) - ret.Add(jsonutils.NewFloat(cap.GetCommitRate()), "commit_rate") - ret.Add(jsonutils.NewInt(int64(cap.GetFree())), "free_capacity") - return ret +func (cap *SStorageCapacity) toCapacityInfo() api.SStorageCapacityInfo { + info := api.SStorageCapacityInfo{} + info.Capacity = cap.Capacity + info.UsedCapacity = cap.Used + info.WasteCapacity = cap.Wasted + info.VirtualCapacity = cap.VCapacity + info.CommitRate = cap.GetCommitRate() + info.FreeCapacity = cap.GetFree() + return info } func (self *SHost) GetAttachedLocalStorageCapacity() SStorageCapacity { diff --git a/pkg/compute/models/storages.go b/pkg/compute/models/storages.go index 4a7bdcfeaf..2020b4614d 100644 --- a/pkg/compute/models/storages.go +++ b/pkg/compute/models/storages.go @@ -401,13 +401,7 @@ func (self *SStorage) getStorageCapacity() SStorageCapacity { func (self *SStorage) getMoreDetails(ctx context.Context, out api.StorageDetails) api.StorageDetails { capa := self.getStorageCapacity() - out.Capacity = capa.Capacity - out.Used = capa.Used - out.Wasted = capa.Wasted - out.VCapacity = capa.VCapacity - out.CommitRate = capa.GetCommitRate() - out.FreeCapacity = capa.GetFree() - + out.SStorageCapacityInfo = capa.toCapacityInfo() out.CommitBound = self.GetOvercommitBound() out.CloudproviderInfo = self.getCloudProviderInfo() out.Schedtags = GetSchedtagsDetailsToResourceV2(self, ctx)