From 0dc7fb48a18432e2dfbe6bec429219466b259f6d Mon Sep 17 00:00:00 2001 From: prachi Date: Mon, 21 Nov 2011 17:12:08 -0800 Subject: [PATCH] Bug 11962 - MigrateVirtualMachine fails with AgentUnavailableException when the targeted host for migration is under Maintenance Bug 11964 - You are allowed to migrate a virtual machine on to the host that it already exists o Changes: Validations were missing in th MigrateVmCmd API, since from UI the validations are always done while listing hosts for migration as first step. --- server/src/com/cloud/vm/UserVmManagerImpl.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index b4dd9dc7d5b..297e7fbc748 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -149,6 +149,7 @@ import com.cloud.org.Grouping; import com.cloud.projects.Project; import com.cloud.projects.ProjectManager; import com.cloud.resource.ResourceManager; +import com.cloud.resource.ResourceState; import com.cloud.server.Criteria; import com.cloud.service.ServiceOfferingVO; import com.cloud.service.dao.ServiceOfferingDao; @@ -3308,11 +3309,21 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager } throw new InvalidParameterValueException("Unsupported operation, VM uses Local storage, cannot migrate"); } + + //check if migrating to same host + long srcHostId = vm.getHostId(); + if(destinationHost.getId() == srcHostId){ + throw new InvalidParameterValueException("Cannot migrate VM, VM is already presnt on this host, please specify valid destination host to migrate the VM"); + } + + //check if host is UP + if(destinationHost.getStatus() != com.cloud.host.Status.Up || destinationHost.getResourceState() != ResourceState.Enabled){ + throw new InvalidParameterValueException("Cannot migrate VM, destination host is not in correct state, has status: "+destinationHost.getStatus() + ", state: " +destinationHost.getResourceState()); + } // call to core process DataCenterVO dcVO = _dcDao.findById(destinationHost.getDataCenterId()); HostPodVO pod = _podDao.findById(destinationHost.getPodId()); - long srcHostId = vm.getHostId(); Cluster cluster = _clusterDao.findById(destinationHost.getClusterId()); DeployDestination dest = new DeployDestination(dcVO, pod, cluster, destinationHost);