From c076ae875ab85ae20a203db04131925886f5e0cc Mon Sep 17 00:00:00 2001 From: Koushik Das Date: Thu, 11 Jul 2013 17:25:42 +0530 Subject: [PATCH] CLOUDSTACK-3248: XenServer Host got removed successfully inspite of running VMs on the host In UI there is a restriction to first put a host in maintenance and only then deletion is allowed. But there is no such restriction in the deleteHost API. Added a validation in deleteHost API to prevent deletion if the host is not in maintenance. In case of a forced deletion the restriction doesn't apply. --- server/src/com/cloud/resource/ResourceManagerImpl.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/server/src/com/cloud/resource/ResourceManagerImpl.java b/server/src/com/cloud/resource/ResourceManagerImpl.java index a0ea54e1e60..34e5b21b001 100755 --- a/server/src/com/cloud/resource/ResourceManagerImpl.java +++ b/server/src/com/cloud/resource/ResourceManagerImpl.java @@ -857,6 +857,9 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, } _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCaller(), host.getDataCenterId()); + if (!isForced && host.getResourceState() != ResourceState.Maintenance) { + throw new CloudRuntimeException("Host " + host.getUuid() + " cannot be deleted as it is not in maintenance mode. Either put the host into maintenance or perform a forced deletion."); + } /* * TODO: check current agent status and updateAgentStatus to removed. If * it was already removed, that means someone is deleting host