From ac02074cde9a92b8104a66db0c62536cd8fd9db9 Mon Sep 17 00:00:00 2001 From: Zexi Li Date: Mon, 14 Jan 2019 13:40:35 +0800 Subject: [PATCH] =?UTF-8?q?region:=20host=20list=20=E5=8E=BB=E6=8E=89=20co?= =?UTF-8?q?ntainer=20=E8=AE=A1=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/compute/models/hosts.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/pkg/compute/models/hosts.go b/pkg/compute/models/hosts.go index 82df9d5e49..d6ad9a9d70 100644 --- a/pkg/compute/models/hosts.go +++ b/pkg/compute/models/hosts.go @@ -1081,6 +1081,12 @@ func (self *SHost) GetGuestCount() int { return q.Count() } +func (self *SHost) GetContainerCount() int { + q := self.GetGuestsQuery() + q = q.Filter(sqlchemy.Equals(q.Field("hypervisor"), HYPERVISOR_CONTAINER)) + return q.Count() +} + func (self *SHost) GetNonsystemGuestCount() int { q := self.GetGuestsQuery() q = q.Filter(sqlchemy.OR(sqlchemy.IsNull(q.Field("is_system")), sqlchemy.IsFalse(q.Field("is_system")))) @@ -2089,9 +2095,10 @@ func (self *SHost) getMoreDetails(ctx context.Context, extra *jsonutils.JSONDict extra.Add(jsonutils.NewInt(int64(usage.GuestVcpuCount)), "cpu_commit") extra.Add(jsonutils.NewInt(int64(usage.GuestVmemSize)), "mem_commit") } - 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") + containerCount := self.GetContainerCount() + extra.Add(jsonutils.NewInt(int64(self.GetGuestCount()-containerCount)), "guests") + extra.Add(jsonutils.NewInt(int64(self.GetNonsystemGuestCount()-containerCount)), "nonsystem_guests") + extra.Add(jsonutils.NewInt(int64(self.GetRunningGuestCount()-containerCount)), "running_guests") totalCpu := self.GetCpuCount() cpuCommitRate := 0.0 if totalCpu > 0 && usage.GuestVcpuCount > 0 {