}
public SecurityGroupData deleteRule(Auth auth, Project project, long ruleId) throws CloudException {
// This sort of sucks, because we don't have an index on ruleId
NumberedItemCollection<SecurityGroupData> store = getStore(project);
SecurityGroupData securityGroupData = null;
int ruleIndex = -1;
for (SecurityGroupData g : store.list()) {
for (int i = 0; i < g.getRulesCount(); i++) {
SecurityGroupRuleData r = g.getRules(i);
if (r.getId() == ruleId) {
securityGroupData = g;
ruleIndex = i;
break;
}
}
}
if (securityGroupData == null) {
throw new WebApplicationException(Status.NOT_FOUND);
}
SecurityGroupData.Builder b = SecurityGroupData.newBuilder(securityGroupData);
b.removeRules(ruleIndex);
SecurityGroupData updated = store.update(b);
applySecurityGroup(auth, project, updated);
return updated;
}