diff --git a/api/src/com/cloud/api/commands/UpdateResourceLimitCmd.java b/api/src/com/cloud/api/commands/UpdateResourceLimitCmd.java index 0cb5da1ae8a..f2b841b930c 100644 --- a/api/src/com/cloud/api/commands/UpdateResourceLimitCmd.java +++ b/api/src/com/cloud/api/commands/UpdateResourceLimitCmd.java @@ -87,7 +87,7 @@ public class UpdateResourceLimitCmd extends BaseCmd { @Override public void execute(){ ResourceLimit result = _accountService.updateResourceLimit(this); - if (result != null){ + if (result != null || (result == null && max != null && max.longValue() == -1L)){ ResourceLimitResponse response = _responseGenerator.createResourceLimitResponse(result); response.setResponseName(getCommandName()); this.setResponseObject(response); diff --git a/server/src/com/cloud/user/AccountManagerImpl.java b/server/src/com/cloud/user/AccountManagerImpl.java index 72af7dd14a4..a1b8ca1ac25 100755 --- a/server/src/com/cloud/user/AccountManagerImpl.java +++ b/server/src/com/cloud/user/AccountManagerImpl.java @@ -645,10 +645,19 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag List limits = _resourceLimitDao.search(sc, searchFilter); if (limits.size() == 1) { - // Update the existing limit ResourceLimitVO limit = limits.get(0); - _resourceLimitDao.update(limit.getId(), max); - return _resourceLimitDao.findById(limit.getId()); + //if limit is set to -1, remove the record + if (max != null && max.longValue() == -1L) { + //this parameter is needed by API as it expects the object to be returned and updates the UI with the object's new "max" parameter + ResourceLimitVO limitToReturn = limit; + limitToReturn.setMax(-1L); + _resourceLimitDao.remove(limit.getId()); + return limitToReturn; + } else { + // Update the existing limit + _resourceLimitDao.update(limit.getId(), max); + return _resourceLimitDao.findById(limit.getId()); + } } else { // Persist the new Limit return _resourceLimitDao.persist(new ResourceLimitVO(domainId, accountId, resourceType, max));