Skip to content

Commit de39782

Browse files
committed
server: check server capacity when start/deploy a vm
1 parent 442f89c commit de39782

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

server/src/main/java/com/cloud/vm/UserVmManagerImpl.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4851,9 +4851,19 @@ public Pair<UserVmVO, Map<VirtualMachineProfile.Param, Object>> startVirtualMach
48514851
boolean deployOnGivenHost = false;
48524852
if (destinationHost != null) {
48534853
s_logger.debug("Destination Host to deploy the VM is specified, specifying a deployment plan to deploy the VM");
4854-
plan = new DataCenterDeployment(vm.getDataCenterId(), destinationHost.getPodId(), destinationHost.getClusterId(), destinationHost.getId(), null, null);
4855-
if (!AllowDeployVmIfGivenHostFails.value()) {
4856-
deployOnGivenHost = true;
4854+
final ServiceOfferingVO offering = _offeringDao.findById(vm.getId(), vm.getServiceOfferingId());
4855+
Pair<Boolean, Boolean> cpuCapabilityAndCapacity = _capacityMgr.checkIfHostHasCpuCapabilityAndCapacity(destinationHost, offering, false);
4856+
if (!cpuCapabilityAndCapacity.first() || !cpuCapabilityAndCapacity.second()) {
4857+
String errorMsg = "Cannot deploy the VM to specified host " + hostId + "; host has cpu capability? " + cpuCapabilityAndCapacity.first() + ", host has capacity? " + cpuCapabilityAndCapacity.second();
4858+
s_logger.info(errorMsg);
4859+
if (!AllowDeployVmIfGivenHostFails.value()) {
4860+
throw new InvalidParameterValueException(errorMsg);
4861+
};
4862+
} else {
4863+
plan = new DataCenterDeployment(vm.getDataCenterId(), destinationHost.getPodId(), destinationHost.getClusterId(), destinationHost.getId(), null, null);
4864+
if (!AllowDeployVmIfGivenHostFails.value()) {
4865+
deployOnGivenHost = true;
4866+
}
48574867
}
48584868
} else if (destinationCluster != null) {
48594869
s_logger.debug("Destination Cluster to deploy the VM is specified, specifying a deployment plan to deploy the VM");

0 commit comments

Comments
 (0)