From ef1d30397268414babf613ca452a07f9ddbdab1a Mon Sep 17 00:00:00 2001 From: ioito Date: Mon, 2 Sep 2019 15:02:06 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=81=BF=E5=85=8D=E8=A3=B8=E9=87=91?= =?UTF-8?q?=E5=B1=9E=E6=9C=8D=E5=8A=A1=E5=99=A8=E8=BD=AC=E5=AE=BF=E4=B8=BB?= =?UTF-8?q?=E6=9C=BA=E4=BB=BB=E5=8A=A1=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/compute/models/guests.go | 9 +++++++++ pkg/compute/tasks/guest_undeploy_task.go | 9 --------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/pkg/compute/models/guests.go b/pkg/compute/models/guests.go index 880f8a2630..8b1be56fda 100644 --- a/pkg/compute/models/guests.go +++ b/pkg/compute/models/guests.go @@ -527,6 +527,15 @@ func (guest *SGuest) ValidatePurgeCondition(ctx context.Context) error { } func (guest *SGuest) ValidateDeleteCondition(ctx context.Context) error { + host := guest.GetHost() + if host != nil { + if !host.Enabled { + return httperrors.NewInputParameterError("Cannot delete server on disabled host") + } + if host.HostStatus != api.HOST_ONLINE { + return httperrors.NewInputParameterError("Cannot delete server on offline host") + } + } return guest.validateDeleteCondition(ctx, false) } diff --git a/pkg/compute/tasks/guest_undeploy_task.go b/pkg/compute/tasks/guest_undeploy_task.go index 78520d068f..ea954f0fca 100644 --- a/pkg/compute/tasks/guest_undeploy_task.go +++ b/pkg/compute/tasks/guest_undeploy_task.go @@ -16,7 +16,6 @@ package tasks import ( "context" - "fmt" "yunion.io/x/jsonutils" @@ -49,10 +48,6 @@ func (self *GuestUndeployTask) OnInit(ctx context.Context, obj db.IStandaloneMod host = models.HostManager.FetchHostById(targetHostId) } if host != nil { - if !host.Enabled { - self.OnStartDeleteGuestFail(ctx, fmt.Errorf("host %s(%s) is disabled", host.Name, host.Id)) - return - } err := guest.GetDriver().RequestUndeployGuestOnHost(ctx, guest, host, self) if err != nil { self.OnStartDeleteGuestFail(ctx, err) @@ -66,10 +61,6 @@ func (self *GuestUndeployTask) OnMasterHostUndeployGuestComplete(ctx context.Con self.SetStage("OnGuestUndeployComplete", nil) host := models.HostManager.FetchHostById(guest.BackupHostId) if host != nil { - if !host.Enabled { - self.OnStartDeleteGuestFail(ctx, fmt.Errorf("host %s(%s) is disabled", host.Name, host.Id)) - return - } err := guest.GetDriver().RequestUndeployGuestOnHost(ctx, guest, host, self) if err != nil { self.OnStartDeleteGuestFail(ctx, err)