Remove user vm from instance_group when empty string is passed as value for "group" parameter in updateVirtualMachine API.

This commit is contained in:
alena 2010-09-27 14:20:05 -07:00
parent e46306b5d7
commit 49143dbe4a
4 changed files with 12 additions and 8 deletions

View File

@ -66,11 +66,7 @@ public class UpdateVMCmd extends BaseCmd{
// default userId to SYSTEM user
if (userId == null) {
userId = Long.valueOf(1);
}
//don't accept empty parameter for the group
if (group != null && group.isEmpty())
group = null;
}
// Verify input parameters
try {

View File

@ -2804,9 +2804,14 @@ public class ManagementServerImpl implements ManagementServer {
}
if (group != null) {
boolean addToGroup = _vmMgr.addInstanceToGroup(Long.valueOf(vmId), group);
if (!addToGroup) {
throw new CloudRuntimeException("Unable to update Vm with the the group " + group);
if (group.isEmpty()) {
_vmMgr.removeInstanceFromGroup(vmId);
}
else {
boolean addToGroup = _vmMgr.addInstanceToGroup(Long.valueOf(vmId), group);
if (!addToGroup) {
throw new CloudRuntimeException("Unable to update Vm with the the group " + group);
}
}
}

View File

@ -232,5 +232,7 @@ public interface UserVmManager extends Manager, VirtualMachineManager<UserVmVO>
boolean addInstanceToGroup(long userVmId, String group);
InstanceGroupVO getGroupForVm(long vmId);
void removeInstanceFromGroup(long vmId);
}

View File

@ -3154,6 +3154,7 @@ public class UserVmManagerImpl implements UserVmManager {
}
}
@Override
public void removeInstanceFromGroup(long vmId) {
try {
List<InstanceGroupVMMapVO> groupVmMaps = _groupVMMapDao.listByInstanceId(vmId);