use of org.openstack.model.compute.SecurityGroupList in project platformlayer by platformlayer.
the class OpenstackCloudHelpers method getMachineSecurityGroup.
public SecurityGroup getMachineSecurityGroup(OpenstackComputeClient openstackComputeClient, Server server) throws OpsException {
// SecurityGroupList securityGroups;
// try {
// securityGroups = openstackComputeClient.root().servers().server(server.getId()).listSecurityGroups();
// } catch (OpenstackException e) {
// throw new OpsException("Error getting security groups for server", e);
// }
SecurityGroupList securityGroups;
try {
log.info("Listing security groups");
securityGroups = openstackComputeClient.root().securityGroups().list();
} catch (OpenstackException e) {
throw new OpsException("Error getting security groups for server", e);
}
SecurityGroup securityGroup = null;
if (securityGroups != null && securityGroups.getList() != null) {
for (SecurityGroup candidate : securityGroups.getList()) {
if (candidate.getName() == null) {
continue;
}
if (candidate.getName().equals(OpenstackCloudContext.SECURITY_GROUP_PREFIX + server.getName())) {
securityGroup = candidate;
break;
}
// if (candidate.getName().startsWith(OpenstackCloudContext.SECURITY_GROUP_PREFIX)) {
// securityGroup = candidate;
// break;
// }
}
}
if (securityGroup == null) {
throw new OpsException("Could not find platform layer security group for server: " + server);
}
return securityGroup;
}
Aggregations