use of com.amazonaws.services.ec2.model.DescribeSecurityGroupsResult in project SimianArmy by Netflix.
the class AWSClient method describeSecurityGroups.
/**
* Describe a set of security groups.
*
* @param groupNames the names of the groups to find
* @return a list of matching groups
*/
public List<SecurityGroup> describeSecurityGroups(String... groupNames) {
AmazonEC2 ec2Client = ec2Client();
DescribeSecurityGroupsRequest request = new DescribeSecurityGroupsRequest();
if (groupNames == null || groupNames.length == 0) {
LOGGER.info(String.format("Getting all EC2 security groups in region %s.", region));
} else {
LOGGER.info(String.format("Getting EC2 security groups for %d names in region %s.", groupNames.length, region));
request.withGroupNames(groupNames);
}
DescribeSecurityGroupsResult result;
try {
result = ec2Client.describeSecurityGroups(request);
} catch (AmazonServiceException e) {
if (e.getErrorCode().equals("InvalidGroup.NotFound")) {
LOGGER.info("Got InvalidGroup.NotFound error for security groups; returning empty list");
return Collections.emptyList();
}
throw e;
}
List<SecurityGroup> securityGroups = result.getSecurityGroups();
LOGGER.info(String.format("Got %d EC2 security groups in region %s.", securityGroups.size(), region));
return securityGroups;
}
Aggregations