Allow to use securityGroupNames in deployVm command (the code transforms them to the ids)

This commit is contained in:
alena 2011-06-06 14:03:38 -07:00
parent a03e2b8a12
commit cec4e7235b
1 changed files with 11 additions and 8 deletions

View File

@ -145,24 +145,27 @@ public class DeployVMCmd extends BaseAsyncCreateCmd {
}
public List<Long> getSecurityGroupIdList() {
if (securityGroupIdList != null && securityGroupIdList != null) {
if (securityGroupNameList != null && securityGroupIdList != null) {
throw new InvalidParameterValueException("securitygroupids parameter is mutually exclusive with securitygroupnames parameter");
} else if (securityGroupNameList == null && securityGroupIdList == null) {
throw new InvalidParameterValueException("securitygroupids or securitygroupnames must be specified");
}
//transform group names to ids here
if (securityGroupNameList != null) {
securityGroupIdList = new ArrayList<Long>();
List<Long> securityGroupIds = new ArrayList<Long>();
for (String groupName : securityGroupNameList) {
Long groupId = _responseGenerator.getSecurityGroupId(groupName, getEntityOwnerId());
if (groupId == null) {
throw new InvalidParameterValueException("Unable to find group by name " + groupName + " for account " + getEntityOwnerId());
} else {
securityGroupIdList.add(groupId);
securityGroupIds.add(groupId);
}
}
return securityGroupIds;
} else {
return securityGroupIdList;
}
return securityGroupIdList;
}
public Long getServiceOfferingId() {
@ -320,15 +323,15 @@ public class DeployVMCmd extends BaseAsyncCreateCmd {
if (getNetworkIds() != null) {
throw new InvalidParameterValueException("Can't specify network Ids in Basic zone");
} else {
vm = _userVmService.createBasicSecurityGroupVirtualMachine(zone, serviceOffering, template, securityGroupIdList, owner, name,
vm = _userVmService.createBasicSecurityGroupVirtualMachine(zone, serviceOffering, template, getSecurityGroupIdList(), owner, name,
displayName, diskOfferingId, size, group, getHypervisor(), userData, sshKeyPairName);
}
} else {
if (zone.isSecurityGroupEnabled()) {
vm = _userVmService.createAdvancedSecurityGroupVirtualMachine(zone, serviceOffering, template, getNetworkIds(), securityGroupIdList,
vm = _userVmService.createAdvancedSecurityGroupVirtualMachine(zone, serviceOffering, template, getNetworkIds(), getSecurityGroupIdList(),
owner, name, displayName, diskOfferingId, size, group, getHypervisor(), userData, sshKeyPairName);
} else {
if (securityGroupIdList != null && !securityGroupIdList.isEmpty()) {
if (getSecurityGroupIdList() != null && !getSecurityGroupIdList().isEmpty()) {
throw new InvalidParameterValueException("Can't create vm with security groups; security group feature is not enabled per zone");
}
vm = _userVmService.createAdvancedVirtualMachine(zone, serviceOffering, template, getNetworkIds(), owner, name, displayName,