@Override public SecurityGroup getSecurityGroupById(String id) { RegionAndId regionAndId = RegionAndId.fromSlashEncoded(checkNotNull(id, "id")); String region = regionAndId.getRegion(); String groupId = regionAndId.getId(); SecurityGroupApi securityGroupApi = getSecurityGroupApi(region); Location location = locationIndex.get().get(region); return neutronSecurityGroupToSecurityGroup.create(location).apply(securityGroupApi.getSecurityGroup(groupId)); }
@Override public SecurityGroup getSecurityGroupById(String id) { RegionAndId regionAndId = RegionAndId.fromSlashEncoded(checkNotNull(id, "id")); String region = regionAndId.getRegion(); String groupId = regionAndId.getId(); SecurityGroupApi securityGroupApi = getSecurityGroupApi(region); Location location = locationIndex.get().get(region); return neutronSecurityGroupToSecurityGroup.create(location).apply(securityGroupApi.getSecurityGroup(groupId)); }
private SecurityGroup createSecurityGroupFrom(final org.jclouds.openstack.neutron.v2.domain.SecurityGroup group, Location location, Set<Integer> ports) { SecurityGroup securityGroup = neutronSecurityGroupToSecurityGroup.create(location).apply(group); logger.debug("<< created securityGroup(%s)", securityGroup); SecurityGroupApi securityGroupApi = getNeutronSecurityGroupApi(location.getId()); try { for (int inboundPort : ports) { logger.debug(">> authorizing securityGroup(%s) permission to 0.0.0.0/0 on port %d", securityGroup, inboundPort); securityGroupApi.create( Rule.CreateRule.createBuilder(RuleDirection.INGRESS, RegionAndId.fromSlashEncoded(securityGroup.getId()).getId()).protocol(RuleProtocol.TCP) .portRangeMin(inboundPort).portRangeMax(inboundPort).remoteIpPrefix("0.0.0.0/0").build()); logger.debug("<< authorized securityGroup(%s) permission to 0.0.0.0/0 on port %d", securityGroup, inboundPort); } return securityGroup; } catch (IllegalStateException e) { logger.trace("<< trying to find securityGroup(%s): %s", group, e.getMessage()); return securityGroupApi.listSecurityGroups().concat() .filter(new Predicate<org.jclouds.openstack.neutron.v2.domain.SecurityGroup>() { @Override public boolean apply(@Nullable org.jclouds.openstack.neutron.v2.domain.SecurityGroup input) { return input.getName().equals(group.getName()); } }).transform(neutronSecurityGroupToSecurityGroup.create(location)).first().orNull(); } }
private SecurityGroup createSecurityGroupFrom(final org.jclouds.openstack.neutron.v2.domain.SecurityGroup group, Location location, Set<Integer> ports) { SecurityGroup securityGroup = neutronSecurityGroupToSecurityGroup.create(location).apply(group); logger.debug("<< created securityGroup(%s)", securityGroup); SecurityGroupApi securityGroupApi = getNeutronSecurityGroupApi(location.getId()); try { for (int inboundPort : ports) { logger.debug(">> authorizing securityGroup(%s) permission to 0.0.0.0/0 on port %d", securityGroup, inboundPort); securityGroupApi.create( Rule.CreateRule.createBuilder(RuleDirection.INGRESS, RegionAndId.fromSlashEncoded(securityGroup.getId()).getId()).protocol(RuleProtocol.TCP) .portRangeMin(inboundPort).portRangeMax(inboundPort).remoteIpPrefix("0.0.0.0/0").build()); logger.debug("<< authorized securityGroup(%s) permission to 0.0.0.0/0 on port %d", securityGroup, inboundPort); } return securityGroup; } catch (IllegalStateException e) { logger.trace("<< trying to find securityGroup(%s): %s", group, e.getMessage()); return securityGroupApi.listSecurityGroups().concat() .filter(new Predicate<org.jclouds.openstack.neutron.v2.domain.SecurityGroup>() { @Override public boolean apply(@Nullable org.jclouds.openstack.neutron.v2.domain.SecurityGroup input) { return input.getName().equals(group.getName()); } }).transform(neutronSecurityGroupToSecurityGroup.create(location)).first().orNull(); } }