Updated Branches: refs/heads/4.2 ef4becfad -> ca7f22062
CLOUDSTACK-4379: Reset VM states when host is removed from cluster If you shut down the agent while VMs are running, the management server assumes that the VMs are continuing to run. You can then delete the host while it is in 'disconnected' state, and those VMs will be unusable, forever in running state. They can't change state because the host no longer exists. This patch checks for any VMs that may have been tied to the removed host and resets their state so that cloudstack can continue to manage them. Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/ca7f2206 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/ca7f2206 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/ca7f2206 Branch: refs/heads/4.2 Commit: ca7f22062bb25dfade1c607d7911e29a1b7310e8 Parents: ef4becf Author: Marcus Sorensen <[email protected]> Authored: Fri Aug 16 23:22:15 2013 -0600 Committer: Marcus Sorensen <[email protected]> Committed: Sat Aug 17 00:24:33 2013 -0600 ---------------------------------------------------------------------- server/src/com/cloud/resource/ResourceManagerImpl.java | 9 +++++++++ 1 file changed, 9 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ca7f2206/server/src/com/cloud/resource/ResourceManagerImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/resource/ResourceManagerImpl.java b/server/src/com/cloud/resource/ResourceManagerImpl.java index d6069a4..2a86ffd 100755 --- a/server/src/com/cloud/resource/ResourceManagerImpl.java +++ b/server/src/com/cloud/resource/ResourceManagerImpl.java @@ -872,6 +872,15 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, // Delete the associated entries in host ref table _storagePoolHostDao.deletePrimaryRecordsForHost(hostId); + // Make sure any VMs that were marked as being on this host are cleaned up + List<VMInstanceVO> vms = _vmDao.listByHostId(hostId); + for (VMInstanceVO vm : vms) { + // this is how VirtualMachineManagerImpl does it when it syncs VM states + vm.setState(State.Stopped); + vm.setHostId(null); + _vmDao.persist(vm); + } + // For pool ids you got, delete local storage host entries in pool table // where for (StoragePoolHostVO pool : pools) {
