weizhouapache commented on a change in pull request #5428:
URL: https://github.com/apache/cloudstack/pull/5428#discussion_r707381128
##########
File path: server/src/main/java/com/cloud/vm/UserVmManagerImpl.java
##########
@@ -2575,6 +2575,53 @@ protected void runInContext() {
}
}
+ private void verifyVmLimits(UserVmVO vmInstance, Map<String,String>
details) {
+ Long newCpu = Long.valueOf(details.get(VmDetailConstants.CPU_NUMBER)
!= null ? details.get(VmDetailConstants.CPU_NUMBER) : "0");
+ Long newMemory = Long.valueOf(details.get(VmDetailConstants.MEMORY) !=
null ? details.get(VmDetailConstants.MEMORY) : "0");
+ long currentCpu = 0L;
+ long currentMemory = 0L;
+ List<UserVmDetailVO> vmDetails =
userVmDetailsDao.listDetails(vmInstance.getId());
+ for (UserVmDetailVO detailVO : vmDetails) {
+ if (VmDetailConstants.CPU_NUMBER.equals(detailVO.getName())) {
+ currentCpu = Long.parseLong(detailVO.getValue());
+ }
+ if (VmDetailConstants.MEMORY.equals(detailVO.getName())) {
+ currentMemory = Long.parseLong(detailVO.getValue());
+ }
+ }
+ Account owner = _accountDao.findById(vmInstance.getAccountId());
+ if (owner == null) {
+ throw new InvalidParameterValueException("The owner of " +
vmInstance + " does not exist: " + vmInstance.getAccountId());
+ }
+
+ if (VirtualMachineManager.ResoureCountRunningVMsonly.value()) {
+ return;
+ }
+
+ try {
+ if (newCpu > currentCpu) {
+ _resourceLimitMgr.checkResourceLimit(owner, ResourceType.cpu,
newCpu - currentCpu);
+ }
+ if (newMemory > currentMemory) {
+ _resourceLimitMgr.checkResourceLimit(owner,
ResourceType.memory, newMemory - currentMemory);
+ }
+ } catch (ResourceAllocationException e) {
+ throw new CloudRuntimeException("Failed to update VM settings", e);
+ }
+
+ if (newCpu > currentCpu) {
+ _resourceLimitMgr.incrementResourceCount(owner.getAccountId(),
ResourceType.cpu, newCpu - currentCpu);
+ } else {
Review comment:
@Pearl1594
might newCpu be 0 in line 2584 ?
```
long newCpu = NumberUtils.toLong(details.get(VmDetailConstants.CPU_NUMBER));
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]