diff --git a/api/src/com/cloud/api/commands/AuthorizeSecurityGroupIngressCmd.java b/api/src/com/cloud/api/commands/AuthorizeSecurityGroupIngressCmd.java index a9d0bb8238d..8e19f21d864 100644 --- a/api/src/com/cloud/api/commands/AuthorizeSecurityGroupIngressCmd.java +++ b/api/src/com/cloud/api/commands/AuthorizeSecurityGroupIngressCmd.java @@ -120,10 +120,11 @@ public class AuthorizeSecurityGroupIngressCmd extends BaseAsyncCmd { } if (securityGroupName != null) { - securityGroupId = _responseGenerator.getSecurityGroupId(securityGroupName, getEntityOwnerId()); - if (securityGroupId == null) { + Long groupId = _responseGenerator.getSecurityGroupId(securityGroupName, getEntityOwnerId()); + if (groupId == null) { throw new InvalidParameterValueException("Unable to find security group " + securityGroupName + " for account id=" + getEntityOwnerId()); } + return groupId; } return securityGroupId; diff --git a/api/src/com/cloud/api/commands/DeleteSecurityGroupCmd.java b/api/src/com/cloud/api/commands/DeleteSecurityGroupCmd.java index 024d9dc206d..3b943b76cc0 100644 --- a/api/src/com/cloud/api/commands/DeleteSecurityGroupCmd.java +++ b/api/src/com/cloud/api/commands/DeleteSecurityGroupCmd.java @@ -53,10 +53,12 @@ public class DeleteSecurityGroupCmd extends BaseCmd { } if (name != null) { - id = _responseGenerator.getSecurityGroupId(name, getEntityOwnerId()); - if (id == null) { + Long groupId = _responseGenerator.getSecurityGroupId(name, getEntityOwnerId()); + if (groupId == null) { throw new InvalidParameterValueException("Unable to find security group by name " + name + " for the account id=" + getEntityOwnerId()); } + + return groupId; } return id; diff --git a/api/src/com/cloud/api/commands/DeployVMCmd.java b/api/src/com/cloud/api/commands/DeployVMCmd.java index 254aa09529e..08fbc41c4d6 100644 --- a/api/src/com/cloud/api/commands/DeployVMCmd.java +++ b/api/src/com/cloud/api/commands/DeployVMCmd.java @@ -147,21 +147,22 @@ public class DeployVMCmd extends BaseAsyncCreateCmd { } public List getSecurityGroupIdList() { - if (securityGroupIdList != null && securityGroupIdList != null) { + if (securityGroupIdList != null && securityGroupNameList != null) { throw new InvalidParameterValueException("securitygroupids parameter is mutually exclusive with securitygroupnames parameter"); } //transform group names to ids here if (securityGroupNameList != null) { - securityGroupIdList = new ArrayList(); + List securityGroupIdListToReturn = new ArrayList(); 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); + securityGroupIdListToReturn.add(groupId); } - } + } + return securityGroupIdListToReturn; } return securityGroupIdList; diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index f05162b3820..b249a994220 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -1953,8 +1953,11 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager if (securityGroupIdList != null && isVmWare) { throw new InvalidParameterValueException("Security group feature is not supported for vmWare hypervisor"); - } else if (securityGroupIdList == null && !isVmWare) { - securityGroupIdList = new ArrayList(); + } else if (!isVmWare) { + if (securityGroupIdList == null) { + securityGroupIdList = new ArrayList(); + } + SecurityGroup defaultGroup = _securityGroupMgr.getDefaultSecurityGroup(owner.getId()); if (defaultGroup != null) { //check if security group id list already contains Default security group, and if not - add it