@@ -5792,21 +5792,7 @@ public VirtualMachine migrateVirtualMachine(Long vmId, Host destinationHost) thr
57925792
57935793 DeployDestination dest = null ;
57945794 if (destinationHost == null ) {
5795- vm .setLastHostId (null ); // Last host does not have higher priority in vm migration
5796- final ServiceOfferingVO offering = _offeringDao .findById (vm .getId (), vm .getServiceOfferingId ());
5797- final VirtualMachineProfile profile = new VirtualMachineProfileImpl (vm , null , offering , null , null );
5798- final Host host = _hostDao .findById (srcHostId );
5799- ExcludeList excludes = new ExcludeList ();
5800- excludes .addHost (srcHostId );
5801- final DataCenterDeployment plan = _itMgr .getMigrationDeployment (vm .getId (), host , null , excludes );
5802- try {
5803- dest = _planningMgr .planDeployment (profile , plan , excludes , null );
5804- } catch (final AffinityConflictException e2 ) {
5805- s_logger .warn ("Unable to create deployment, affinity rules associted to the VM conflict" , e2 );
5806- throw new CloudRuntimeException ("Unable to create deployment, affinity rules associted to the VM conflict" );
5807- } catch (final InsufficientServerCapacityException e3 ) {
5808- throw new CloudRuntimeException ("Unable to find a server to migrate the vm to" );
5809- }
5795+ dest = findVmMigrationDestination (vm , srcHostId );
58105796 } else {
58115797 dest = checkVmMigrationDestination (vm , srcHostId , destinationHost );
58125798 }
@@ -5830,6 +5816,27 @@ public VirtualMachine migrateVirtualMachine(Long vmId, Host destinationHost) thr
58305816 }
58315817 }
58325818
5819+ private DeployDestination findVmMigrationDestination (VMInstanceVO vm , Long srcHostId ) {
5820+ DeployDestination dest = null ;
5821+ vm .setLastHostId (null ); // Last host does not have higher priority in vm migration
5822+ final ServiceOfferingVO offering = _offeringDao .findById (vm .getId (), vm .getServiceOfferingId ());
5823+ final VirtualMachineProfile profile = new VirtualMachineProfileImpl (vm , null , offering , null , null );
5824+ final Host host = _hostDao .findById (srcHostId );
5825+ ExcludeList excludes = new ExcludeList ();
5826+ excludes .addHost (srcHostId );
5827+ final DataCenterDeployment plan = _itMgr .getMigrationDeployment (vm .getId (), host , null , excludes );
5828+ try {
5829+ dest = _planningMgr .planDeployment (profile , plan , excludes , null );
5830+ } catch (final AffinityConflictException e2 ) {
5831+ s_logger .warn ("Unable to create deployment, affinity rules associted to the VM conflict" , e2 );
5832+ throw new CloudRuntimeException ("Unable to create deployment, affinity rules associted to the VM conflict" );
5833+ } catch (final InsufficientServerCapacityException e3 ) {
5834+ throw new CloudRuntimeException ("Unable to find a server to migrate the vm to" );
5835+ }
5836+ return dest ;
5837+ }
5838+
5839+
58335840 private DeployDestination checkVmMigrationDestination (VMInstanceVO vm , Long srcHostId , Host destinationHost ) throws VirtualMachineMigrationException {
58345841 if (destinationHost == null ) {
58355842 return null ;
0 commit comments