diff --git a/server/src/com/cloud/api/commands/ListVMsCmd.java b/server/src/com/cloud/api/commands/ListVMsCmd.java index 79c1fc6e472..508171af9b0 100644 --- a/server/src/com/cloud/api/commands/ListVMsCmd.java +++ b/server/src/com/cloud/api/commands/ListVMsCmd.java @@ -56,6 +56,9 @@ public class ListVMsCmd extends BaseListCmd { @Parameter(name="domainid", type=CommandType.LONG, description="the domain ID. If used with the account parameter, lists virtual machines for the specified account in this domain.") private Long domainId; + @Parameter(name="groupid", type=CommandType.LONG, description="the group ID") + private Long groupId; + @Parameter(name="hostid", type=CommandType.LONG, description="the host ID") private Long hostId; @@ -86,6 +89,10 @@ public class ListVMsCmd extends BaseListCmd { return domainId; } + public Long getGroupId() { + return groupId; + } + public Long getHostId() { return hostId; } @@ -127,6 +134,16 @@ public class ListVMsCmd extends BaseListCmd { List vmResponses = new ArrayList(); for (UserVmVO userVm : userVms) { UserVmResponse userVmResponse = new UserVmResponse(); + + Account acct = ApiDBUtils.findAccountById(Long.valueOf(userVm.getAccountId())); + if ((acct != null) && (acct.getRemoved() == null)) { + userVmResponse.setAccountName(acct.getAccountName()); + userVmResponse.setDomainId(acct.getDomainId()); + userVmResponse.setDomainName(ApiDBUtils.findDomainById(acct.getDomainId()).getName()); + } else { + continue; // the account has been deleted, skip this VM in the response + } + userVmResponse.setId(userVm.getId()); AsyncJobVO asyncJob = ApiDBUtils.findInstancePendingAsyncJob("vm_instance", userVm.getId()); if (asyncJob != null) { @@ -141,12 +158,6 @@ public class ListVMsCmd extends BaseListCmd { userVmResponse.setState(userVm.getState().toString()); } - Account acct = ApiDBUtils.findAccountById(Long.valueOf(userVm.getAccountId())); - if (acct != null) { - userVmResponse.setAccountName(acct.getAccountName()); - userVmResponse.setDomainId(acct.getDomainId()); - userVmResponse.setDomainName(ApiDBUtils.findDomainById(acct.getDomainId()).getName()); - } userVmResponse.setHaEnable(userVm.isHaEnabled()); diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java index 7704d10a203..cb3c56ec646 100755 --- a/server/src/com/cloud/server/ManagementServerImpl.java +++ b/server/src/com/cloud/server/ManagementServerImpl.java @@ -3575,6 +3575,7 @@ public class ManagementServerImpl implements ManagementServer { c.addCriteria(Criteria.NAME, cmd.getInstanceName()); c.addCriteria(Criteria.STATE, cmd.getState()); c.addCriteria(Criteria.DATACENTERID, cmd.getZoneId()); + c.addCriteria(Criteria.GROUPID, cmd.getGroupId()); // ignore these search requests if it's not an admin if (isAdmin == true) { diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index 46e3f9063db..116acf1b741 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -3432,6 +3432,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM @Override public void updateVirtualMachine(UpdateVMCmd cmd) { String displayName = cmd.getDisplayName(); + String group = cmd.getGroup(); Boolean ha = cmd.getHaEnable(); Long id = cmd.getId(); Account account = UserContext.current().getAccount(); @@ -3439,14 +3440,11 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM //Input validation UserVmVO vmInstance = null; - + // Verify input parameters - try - { + try { vmInstance = _vmDao.findById(id.longValue()); - } - catch (Exception ex1) - { + } catch (Exception ex1) { throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "unable to find virtual machine by id"); } @@ -3459,7 +3457,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM if (displayName == null) { displayName = vmInstance.getDisplayName(); } - + if (ha == null) { ha = vmInstance.isHaEnabled(); } @@ -3470,6 +3468,10 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM throw new CloudRuntimeException("Unable to find virual machine with id " + id); } + if (group != null) { + addInstanceToGroup(id, group); + } + boolean haEnabled = vm.isHaEnabled(); _vmDao.updateVM(id, displayName, ha); if (haEnabled != ha) {