From ddb79819226d75c500bae08bb4512a9e6b1c7998 Mon Sep 17 00:00:00 2001 From: wanyaoqi Date: Tue, 1 Sep 2020 01:08:36 +0800 Subject: [PATCH] fix host get guests (#7685) --- pkg/compute/models/hosts.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/pkg/compute/models/hosts.go b/pkg/compute/models/hosts.go index 58f5cc539d..c27917e6a3 100644 --- a/pkg/compute/models/hosts.go +++ b/pkg/compute/models/hosts.go @@ -1381,6 +1381,17 @@ func (self *SHost) GetGuests() []SGuest { return guests } +func (self *SHost) GetKvmGuests() []SGuest { + q := GuestManager.Query().Equals("host_id", self.Id).Equals("hypervisor", api.HYPERVISOR_KVM) + guests := make([]SGuest, 0) + err := db.FetchModelObjects(GuestManager, q, &guests) + if err != nil { + log.Errorf("GetGuests %s", err) + return nil + } + return guests +} + func (self *SHost) GetGuestCount() (int, error) { q := self.GetGuestsQuery() return q.CountWithError() @@ -4809,7 +4820,7 @@ func (host *SHost) PerformHostMaintenance(ctx context.Context, userCred mcclient preferHostId = host.Id } - guests := host.GetGuests() + guests := host.GetKvmGuests() for i := 0; i < len(guests); i++ { lockman.LockObject(ctx, &guests[i]) defer lockman.ReleaseObject(ctx, &guests[i])