Skip to content

Commit cf6dc66

Browse files
server: check server capacity when start/deploy a vm (#5339)
1 parent 2297c73 commit cf6dc66

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
@@ -4853,9 +4853,19 @@ public Pair<UserVmVO, Map<VirtualMachineProfile.Param, Object>> startVirtualMach
48534853
boolean deployOnGivenHost = false;
48544854
if (destinationHost != null) {
48554855
s_logger.debug("Destination Host to deploy the VM is specified, specifying a deployment plan to deploy the VM");
4856-
plan = new DataCenterDeployment(vm.getDataCenterId(), destinationHost.getPodId(), destinationHost.getClusterId(), destinationHost.getId(), null, null);
4857-
if (!AllowDeployVmIfGivenHostFails.value()) {
4858-
deployOnGivenHost = true;
4856+
final ServiceOfferingVO offering = _offeringDao.findById(vm.getId(), vm.getServiceOfferingId());
4857+
Pair<Boolean, Boolean> cpuCapabilityAndCapacity = _capacityMgr.checkIfHostHasCpuCapabilityAndCapacity(destinationHost, offering, false);
4858+
if (!cpuCapabilityAndCapacity.first() || !cpuCapabilityAndCapacity.second()) {
4859+
String errorMsg = "Cannot deploy the VM to specified host " + hostId + "; host has cpu capability? " + cpuCapabilityAndCapacity.first() + ", host has capacity? " + cpuCapabilityAndCapacity.second();
4860+
s_logger.info(errorMsg);
4861+
if (!AllowDeployVmIfGivenHostFails.value()) {
4862+
throw new InvalidParameterValueException(errorMsg);
4863+
};
4864+
} else {
4865+
plan = new DataCenterDeployment(vm.getDataCenterId(), destinationHost.getPodId(), destinationHost.getClusterId(), destinationHost.getId(), null, null);
4866+
if (!AllowDeployVmIfGivenHostFails.value()) {
4867+
deployOnGivenHost = true;
4868+
}
48594869
}
48604870
} else if (destinationCluster != null) {
48614871
s_logger.debug("Destination Cluster to deploy the VM is specified, specifying a deployment plan to deploy the VM");

0 commit comments

Comments
 (0)