From 53d4b0c1b7c6d85d8a2752c507815d93e51f7476 Mon Sep 17 00:00:00 2001 From: wanyaoqi Date: Mon, 18 Sep 2023 15:42:51 +0800 Subject: [PATCH 1/2] fix(region): host delete validate backup guests --- pkg/compute/models/hosts.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pkg/compute/models/hosts.go b/pkg/compute/models/hosts.go index f539bd427b..a4498b9dc6 100644 --- a/pkg/compute/models/hosts.go +++ b/pkg/compute/models/hosts.go @@ -772,6 +772,14 @@ func (hh *SHost) validateDeleteCondition(ctx context.Context, purge bool) error if cnt > 0 { return httperrors.NewNotEmptyError("Not an empty host") } + cnt, err = hh.GetBackupGuestCount() + if err != nil { + return httperrors.NewInternalServerError("GetBackupGuestCount fail %s", err) + } + if cnt > 0 { + return httperrors.NewNotEmptyError("Not an empty host") + } + for _, hoststorage := range hh.GetHoststorages() { storage := hoststorage.GetStorage() if storage != nil && storage.IsLocal() { @@ -1612,6 +1620,11 @@ func (hh *SHost) GetGuestsBackupOnThisHost() []SGuest { return guests } +func (hh *SHost) GetBackupGuestCount() (int, error) { + q := GuestManager.Query().Equals("backup_host_id", hh.Id) + return q.CountWithError() +} + func (hh *SHost) GetGuestCount() (int, error) { q := hh.GetGuestsQuery() return q.CountWithError() From 1f4079a8638b2e99f748f0e2d395a2386fb8cb89 Mon Sep 17 00:00:00 2001 From: wanyaoqi Date: Mon, 18 Sep 2023 17:12:32 +0800 Subject: [PATCH 2/2] fix(region): validate is reserve all cpus --- pkg/compute/models/hosts.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/compute/models/hosts.go b/pkg/compute/models/hosts.go index a4498b9dc6..2c22cc50df 100644 --- a/pkg/compute/models/hosts.go +++ b/pkg/compute/models/hosts.go @@ -4274,9 +4274,14 @@ func (hh *SHost) PerformReserveCpus( return nil, err } - if !sets.NewInt(allCores...).HasAll(cs.ToSlice()...) { + hSets := sets.NewInt(allCores...) + cSlice := cs.ToSlice() + if !hSets.HasAll(cSlice...) { return nil, httperrors.NewInputParameterError("Host cores not contains input %v", input.Cpus) } + if hSets.Len() == len(cSlice) { + return nil, httperrors.NewInputParameterError("Can't reserve host all cpus") + } if input.Mems != "" { mems, err := cpuset.Parse(input.Mems)