response.setDomainId(securityGroup.getDomainUuid());
response.setDomainName(securityGroup.getDomainName());
for (SecurityRule securityRule : securityRules) {
SecurityGroupRuleResponse securityGroupData = new SecurityGroupRuleResponse();
securityGroupData.setRuleId(securityRule.getUuid());
securityGroupData.setProtocol(securityRule.getProtocol());
if ("icmp".equalsIgnoreCase(securityRule.getProtocol())) {
securityGroupData.setIcmpType(securityRule.getStartPort());
securityGroupData.setIcmpCode(securityRule.getEndPort());
} else {
securityGroupData.setStartPort(securityRule.getStartPort());
securityGroupData.setEndPort(securityRule.getEndPort());
}
Long allowedSecurityGroupId = securityRule.getAllowedNetworkId();
if (allowedSecurityGroupId != null) {
List<SecurityGroupJoinVO> sgs = ApiDBUtils.findSecurityGroupViewById(allowedSecurityGroupId);
if (sgs != null && sgs.size() > 0) {
SecurityGroupJoinVO sg = sgs.get(0);
securityGroupData.setSecurityGroupName(sg.getName());
securityGroupData.setAccountName(sg.getAccountName());
}
} else {
securityGroupData.setCidr(securityRule.getAllowedSourceIpCidr());
}
if (securityRule.getRuleType() == SecurityRuleType.IngressRule) {
securityGroupData.setObjectName("ingressrule");
response.addSecurityGroupIngressRule(securityGroupData);
} else {
securityGroupData.setObjectName("egressrule");
response.addSecurityGroupEgressRule(securityGroupData);
}
}
response.setObjectName("securitygroup");