use of org.openstack4j.model.compute.SecGroupExtension in project cloudbreak by hortonworks.
the class OpenStackPlatformResources method securityGroups.
@Override
public CloudSecurityGroups securityGroups(CloudCredential cloudCredential, Region region, Map<String, String> filters) {
OSClient<?> osClient = openStackClient.createOSClient(cloudCredential);
KeystoneCredentialView osCredential = openStackClient.createKeystoneCredential(cloudCredential);
Set<CloudSecurityGroup> cloudSecurityGroups = new HashSet<>();
List<? extends SecGroupExtension> osSecurityGroups = osClient.compute().securityGroups().list();
LOGGER.info("security groups from openstack: {}", osSecurityGroups);
for (SecGroupExtension secGroup : osSecurityGroups) {
Map<String, Object> properties = new HashMap<>();
properties.put("tenantId", secGroup.getTenantId());
properties.put("rules", secGroup.getRules());
CloudSecurityGroup cloudSecurityGroup = new CloudSecurityGroup(secGroup.getName(), secGroup.getId(), properties);
cloudSecurityGroups.add(cloudSecurityGroup);
}
Map<String, Set<CloudSecurityGroup>> result = new HashMap<>();
result.put(region.value() == null ? osCredential.getTenantName() : region.value(), cloudSecurityGroups);
LOGGER.info("openstack security groups result: {}", result);
return new CloudSecurityGroups(result);
}
use of org.openstack4j.model.compute.SecGroupExtension in project cloudbreak by hortonworks.
the class OpenStackSecurityGroupResourceBuilder method build.
@Override
public CloudResource build(OpenStackContext context, AuthenticatedContext auth, Group group, Network network, Security security, CloudResource resource) {
try {
OSClient<?> osClient = createOSClient(auth);
ComputeSecurityGroupService securityGroupService = osClient.compute().securityGroups();
SecGroupExtension securityGroup = securityGroupService.create(resource.getName(), "");
String securityGroupId = securityGroup.getId();
for (SecurityRule rule : security.getRules()) {
IPProtocol osProtocol = getProtocol(rule.getProtocol());
String cidr = rule.getCidr();
for (PortDefinition portStr : rule.getPorts()) {
int from = Integer.parseInt(portStr.getFrom());
int to = Integer.parseInt(portStr.getTo());
securityGroupService.createRule(createRule(securityGroupId, osProtocol, cidr, from, to));
}
}
NeutronNetworkView neutronView = new NeutronNetworkView(network);
String subnetCidr = neutronView.isExistingSubnet() ? utils.getExistingSubnetCidr(auth, neutronView) : network.getSubnet().getCidr();
securityGroupService.createRule(createRule(securityGroupId, IPProtocol.TCP, subnetCidr, MIN_PORT, MAX_PORT));
securityGroupService.createRule(createRule(securityGroupId, IPProtocol.UDP, subnetCidr, MIN_PORT, MAX_PORT));
securityGroupService.createRule(createRule(securityGroupId, IPProtocol.ICMP, "0.0.0.0/0"));
return createPersistedResource(resource, group.getName(), securityGroup.getId());
} catch (OS4JException ex) {
throw new OpenStackResourceException("SecurityGroup creation failed", resourceType(), resource.getName(), ex);
}
}
Aggregations