@@ -5632,12 +5632,14 @@ public VirtualMachine migrateVirtualMachine(Long vmId, Host destinationHost) thr
56325632
56335633 DeployDestination dest = null ;
56345634 if (destinationHost == null ) {
5635- vm .setLastHostId (null ); // Do not check last host
56365635 final VirtualMachineProfile profile = new VirtualMachineProfileImpl (vm );
56375636 final Host host = _hostDao .findById (srcHostId );
5638- final DataCenterDeployment plan = new DataCenterDeployment (host .getDataCenterId (), null , null , null , null , null );
5637+ final DataCenterDeployment plan = new DataCenterDeployment (host .getDataCenterId (), host . getPodId (), host . getClusterId () , null , null , null );
56395638 ExcludeList excludes = new ExcludeList ();
56405639 excludes .addHost (srcHostId );
5640+ if (vm .getLastHostId () != null && vm .getLastHostId () != srcHostId ) {
5641+ excludes .addHost (vm .getLastHostId ());
5642+ }
56415643 try {
56425644 dest = _planningMgr .planDeployment (profile , plan , excludes , null );
56435645 } catch (final AffinityConflictException e2 ) {
@@ -5652,7 +5654,7 @@ public VirtualMachine migrateVirtualMachine(Long vmId, Host destinationHost) thr
56525654
56535655 // If no suitable destination found then throw exception
56545656 if (dest == null ) {
5655- throw new RuntimeException ("Unable to find suitable destination to migrate VM " + vm .getInstanceName ());
5657+ throw new CloudRuntimeException ("Unable to find suitable destination to migrate VM " + vm .getInstanceName ());
56565658 }
56575659
56585660 UserVmVO uservm = _vmDao .findById (vmId );
@@ -7296,4 +7298,4 @@ private void checkUnmanagingVMVolumes(UserVmVO vm, List<VolumeVO> volumes) {
72967298 }
72977299 }
72987300 }
7299- }
7301+ }
0 commit comments