}
public void createAndDeleteSecurityGroupRule() throws Exception {
for (String zoneId : api.getConfiguredZones()) {
SecurityGroupApi securityGroupApi = api.getSecurityGroupExtensionForZone(zoneId).get();
SecurityGroup securityGroup = null;
try {
securityGroup = securityGroupApi.createWithDescription(SECURITY_GROUP_NAME, "test security group");
assertNotNull(securityGroup);
for (int port : ImmutableSet.of(22, 8080)) {
SecurityGroupRule rule = securityGroupApi.createRuleAllowingCidrBlock(securityGroup.getId(), Ingress
.builder().ipProtocol(IpProtocol.TCP).fromPort(port).toPort(port).build(), "0.0.0.0/0");
assertNotNull(rule);
SecurityGroupRule rule2 = securityGroupApi.createRuleAllowingSecurityGroupId(securityGroup.getId(),
Ingress.builder().ipProtocol(IpProtocol.TCP).fromPort(port).toPort(port).build(), securityGroup
.getId());
assertNotNull(rule2);
}
securityGroup = securityGroupApi.get(securityGroup.getId());
} finally {
if (securityGroup != null) {
securityGroupApi.delete(securityGroup.getId());
}
}
}
}