Java Code Examples for org.jclouds.net.domain.IpPermission#Builder
The following examples show how to use
org.jclouds.net.domain.IpPermission#Builder .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JcloudsLocationSecurityGroupCustomizer.java From brooklyn-server with Apache License 2.0 | 5 votes |
/** * Creates a security group with rules to: * <ul> * <li>Allow SSH access on port 22 from the world</li> * <li>Allow TCP, UDP and ICMP communication between machines in the same group</li> * </ul> * * It needs to consider locationId as port ranges and groupId are cloud provider-dependent e.g openstack nova * wants from 1-65535 while aws-ec2 accepts from 0-65535. * * * @param groupName The name of the security group to create * @param securityApi The API to use to create the security group * * @return the created security group */ private SecurityGroup createBaseSecurityGroupInLocation(String groupName, SecurityGroupEditor groupEditor) { SecurityGroup group = groupEditor.createSecurityGroup(groupName); String groupId = group.getProviderId(); int fromPort = 0; if (isOpenstackNova(groupEditor.getLocation())) { groupId = group.getId(); fromPort = 1; } // Note: For groupName to work with GCE we also need to tag the machines with the same ID. // See sourceTags section at https://developers.google.com/compute/docs/networking#firewalls IpPermission.Builder allWithinGroup = IpPermission.builder() .groupId(groupId) .fromPort(fromPort) .toPort(65535); group = groupEditor.addPermission(group, allWithinGroup.ipProtocol(IpProtocol.TCP).build()); group = groupEditor.addPermission(group, allWithinGroup.ipProtocol(IpProtocol.UDP).build()); if (!isAzure(groupEditor.getLocation())) { group = groupEditor.addPermission(group, allWithinGroup.ipProtocol(IpProtocol.ICMP).fromPort(-1).toPort(-1).build()); } IpPermission sshPermission = IpPermission.builder() .fromPort(22) .toPort(22) .ipProtocol(IpProtocol.TCP) .cidrBlock(getBrooklynCidrBlock()) .build(); group = groupEditor.addPermission(group, sshPermission); return group; }
Example 2
Source File: AWSEC2SecurityGroupExtension.java From attic-stratos with Apache License 2.0 | 5 votes |
@Override public SecurityGroup addIpPermission(IpProtocol protocol, int startPort, int endPort, Multimap<String, String> tenantIdGroupNamePairs, Iterable<String> ipRanges, Iterable<String> groupIds, SecurityGroup group) { String region = AWSUtils.getRegionFromLocationOrNull(group.getLocation()); String id = group.getProviderId(); IpPermission.Builder builder = IpPermission.builder(); builder.ipProtocol(protocol); builder.fromPort(startPort); builder.toPort(endPort); if (!Iterables.isEmpty(ipRanges)) { for (String cidr : ipRanges) { builder.cidrBlock(cidr); } } if (!tenantIdGroupNamePairs.isEmpty()) { for (String userId : tenantIdGroupNamePairs.keySet()) { for (String groupString : tenantIdGroupNamePairs.get(userId)) { String[] parts = AWSUtils.parseHandle(groupString); String groupId = parts[1]; builder.tenantIdGroupNamePair(userId, groupId); } } } client.getSecurityGroupApi().get().authorizeSecurityGroupIngressInRegion(region, id, builder.build()); return getSecurityGroupById(group.getId()); }
Example 3
Source File: AWSEC2SecurityGroupExtension.java From attic-stratos with Apache License 2.0 | 5 votes |
@Override public SecurityGroup removeIpPermission(IpProtocol protocol, int startPort, int endPort, Multimap<String, String> tenantIdGroupNamePairs, Iterable<String> ipRanges, Iterable<String> groupIds, SecurityGroup group) { String region = AWSUtils.getRegionFromLocationOrNull(group.getLocation()); String id = group.getProviderId(); IpPermission.Builder builder = IpPermission.builder(); builder.ipProtocol(protocol); builder.fromPort(startPort); builder.toPort(endPort); if (!Iterables.isEmpty(ipRanges)) { for (String cidr : ipRanges) { builder.cidrBlock(cidr); } } if (!tenantIdGroupNamePairs.isEmpty()) { for (String userId : tenantIdGroupNamePairs.keySet()) { for (String groupString : tenantIdGroupNamePairs.get(userId)) { String[] parts = AWSUtils.parseHandle(groupString); String groupId = parts[1]; builder.tenantIdGroupNamePair(userId, groupId); } } } client.getSecurityGroupApi().get().revokeSecurityGroupIngressInRegion(region, id, builder.build()); return getSecurityGroupById(group.getId()); }