From 33e0269d081ab3a0afe7b2501ec032b502ef95ec Mon Sep 17 00:00:00 2001 From: Qiu Jian Date: Wed, 12 Dec 2018 21:01:02 +0800 Subject: [PATCH] minor fixes --- pkg/compute/models/host_recycle.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pkg/compute/models/host_recycle.go b/pkg/compute/models/host_recycle.go index 4b2284df4a..90060167c2 100644 --- a/pkg/compute/models/host_recycle.go +++ b/pkg/compute/models/host_recycle.go @@ -321,6 +321,10 @@ func (self *SHost) PerformUndoPrepaidRecycle(ctx context.Context, userCred mccli return nil, httperrors.NewInvalidStatusError("a recycle host shoud not allocate more than 1 guest") } + if guests[0].PendingDeleted { + return nil, httperrors.NewInvalidStatusError("cannot undo a recycle host with pending_deleted guest") + } + err := doUndoPrepaidRecycle(ctx, userCred, self, &guests[0]) if err != nil { logclient.AddActionLog(self, logclient.ACT_UNDO_RECYCLE_PREPAID, self.GetShortDesc(), userCred, false) @@ -584,7 +588,11 @@ func (host *SHost) RebuildRecycledGuest(ctx context.Context, userCred mcclient.T q := HostManager.Query() q = q.Equals("external_id", host.ExternalId) - q = q.IsNullOrEmpty("resource_type") + q = q.Filter(sqlchemy.OR( + sqlchemy.IsNullOrEmpty(q.Field("resource_type")), + sqlchemy.Equals(q.Field("resource_type"), HostResourceTypeShared), + )) + err := q.First(&oHost) if err != nil { log.Errorf("query oHost fail %s", err)