From d854031021128e2775e03138c7e29b35d5c4f23f Mon Sep 17 00:00:00 2001 From: Zexi Li Date: Wed, 26 Dec 2018 11:28:14 +0800 Subject: [PATCH] =?UTF-8?q?region=20=E4=BF=AE=E5=A4=8D:=20=E5=AE=BF?= =?UTF-8?q?=E4=B8=BB=E6=9C=BA=E4=BB=AA=E8=A1=A8=E7=9B=98=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E7=BC=BA=E5=A4=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/compute/models/hosts.go | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/pkg/compute/models/hosts.go b/pkg/compute/models/hosts.go index 4ec9832175..620331dbb9 100644 --- a/pkg/compute/models/hosts.go +++ b/pkg/compute/models/hosts.go @@ -922,16 +922,18 @@ type SStorageCapacity struct { VCapacity int } +func (capa SStorageCapacity) GetFree() int { + return capa.VCapacity - capa.Used - capa.Wasted +} + func (self *SHost) GetAttachedStorageCapacity() SStorageCapacity { ret := SStorageCapacity{} storages := self.GetAttachedStorages("") - if storages != nil { - for _, s := range storages { - ret.Capacity += s.GetCapacity() - ret.Used += s.GetUsedCapacity(tristate.True) - ret.Wasted += s.GetUsedCapacity(tristate.False) - ret.VCapacity += int(float32(s.GetCapacity()) * s.GetOvercommitBound()) - } + for _, s := range storages { + ret.Capacity += s.GetCapacity() + ret.Used += s.GetUsedCapacity(tristate.True) + ret.Wasted += s.GetUsedCapacity(tristate.False) + ret.VCapacity += int(float32(s.GetCapacity()) * s.GetOvercommitBound()) } return ret } @@ -2086,6 +2088,7 @@ func (self *SHost) getMoreDetails(ctx context.Context, extra *jsonutils.JSONDict } extra.Add(jsonutils.NewInt(int64(self.GetGuestCount())), "guests") extra.Add(jsonutils.NewInt(int64(self.GetNonsystemGuestCount())), "nonsystem_guests") + extra.Add(jsonutils.NewInt(int64(self.GetRunningGuestCount())), "running_guests") totalCpu := self.GetCpuCount() cpuCommitRate := 0.0 if totalCpu > 0 && usage.GuestVcpuCount > 0 { @@ -2098,6 +2101,12 @@ func (self *SHost) getMoreDetails(ctx context.Context, extra *jsonutils.JSONDict memCommitRate = float64(usage.GuestVmemSize) * 1.0 / float64(totalMem) } extra.Add(jsonutils.NewFloat(memCommitRate), "mem_commit_rate") + capa := self.GetAttachedStorageCapacity() + extra.Add(jsonutils.NewInt(int64(capa.Capacity)), "storage") + extra.Add(jsonutils.NewInt(int64(capa.Used)), "storage_used") + extra.Add(jsonutils.NewInt(int64(capa.Wasted)), "storage_waste") + extra.Add(jsonutils.NewInt(int64(capa.VCapacity)), "storage_virtual") + extra.Add(jsonutils.NewInt(int64(capa.GetFree())), "storage_free") extra.Add(self.GetHardwareSpecification(), "spec") // extra = self.SManagedResourceBase.getExtraDetails(ctx, extra)