|
78 | 78 | import com.cloud.async.AsyncJobManager; |
79 | 79 | import com.cloud.async.AsyncJobVO; |
80 | 80 | import com.cloud.async.BaseAsyncJobExecutor; |
| 81 | +import com.cloud.capacity.CapacityManager; |
81 | 82 | import com.cloud.configuration.Config; |
82 | 83 | import com.cloud.configuration.ConfigurationManager; |
83 | 84 | import com.cloud.configuration.Resource.ResourceType; |
@@ -326,9 +327,11 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager |
326 | 327 | @Inject |
327 | 328 | protected UserVmDetailsDao _vmDetailsDao; |
328 | 329 | @Inject |
| 330 | + protected HypervisorCapabilitiesDao _hypervisorCapabilitiesDao; |
| 331 | + @Inject |
329 | 332 | protected SecurityGroupDao _securityGroupDao; |
330 | 333 | @Inject |
331 | | - protected HypervisorCapabilitiesDao _hypervisorCapabilitiesDao; |
| 334 | + protected CapacityManager _capacityMgr;; |
332 | 335 | @Inject |
333 | 336 | protected VMInstanceDao _vmInstanceDao; |
334 | 337 | @Inject |
@@ -3268,15 +3271,12 @@ public VirtualMachine migrateVirtualMachine(Long vmId, Host destinationHost) thr |
3268 | 3271 | DeployDestination dest = new DeployDestination(dcVO, pod, cluster, destinationHost); |
3269 | 3272 |
|
3270 | 3273 | //check max guest vm limit for the destinationHost |
3271 | | - HypervisorType hypervisorType = destinationHost.getHypervisorType(); |
3272 | | - String hypervisorVersion = destinationHost.getHypervisorVersion(); |
3273 | | - Long maxGuestLimit = _hypervisorCapabilitiesDao.getMaxGuestsLimit(hypervisorType, hypervisorVersion); |
3274 | | - Long vmCount = _vmInstanceDao.countRunningByHostId(destinationHost.getId()); |
3275 | | - if (vmCount.longValue() == maxGuestLimit.longValue()){ |
| 3274 | + HostVO destinationHostVO = _hostDao.findById(destinationHost.getId()); |
| 3275 | + if(_capacityMgr.checkIfHostReachMaxGuestLimit(destinationHostVO)){ |
3276 | 3276 | if (s_logger.isDebugEnabled()) { |
3277 | | - s_logger.debug("Host name: " + destinationHost.getName() + ", hostId: "+ destinationHost.getId() +" already has max Running VMs(count includes system VMs), limit is: " + maxGuestLimit + " , cannot migrate to this host"); |
| 3277 | + s_logger.debug("Host name: " + destinationHost.getName() + ", hostId: "+ destinationHost.getId() +" already has max Running VMs(count includes system VMs), cannot migrate to this host"); |
3278 | 3278 | } |
3279 | | - throw new VirtualMachineMigrationException("Destination host, hostId: "+ destinationHost.getId() +" already has max Running VMs(count includes system VMs), limit is: " + maxGuestLimit + " , cannot migrate to this host"); |
| 3279 | + throw new VirtualMachineMigrationException("Destination host, hostId: "+ destinationHost.getId() +" already has max Running VMs(count includes system VMs), cannot migrate to this host"); |
3280 | 3280 | } |
3281 | 3281 |
|
3282 | 3282 | VMInstanceVO migratedVm = _itMgr.migrate(vm, srcHostId, dest); |
|
0 commit comments