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)