当前位置: 首页>>代码示例>>Java>>正文


Java IpRange类代码示例

本文整理汇总了Java中com.amazonaws.services.ec2.model.IpRange的典型用法代码示例。如果您正苦于以下问题:Java IpRange类的具体用法?Java IpRange怎么用?Java IpRange使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


IpRange类属于com.amazonaws.services.ec2.model包,在下文中一共展示了IpRange类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createSecurityGroupByClusterName

import com.amazonaws.services.ec2.model.IpRange; //导入依赖的package包/类
private void createSecurityGroupByClusterName(String GROUP_NAME) {
	System.out.println("Creating security group for cluster "+name);
	CreateSecurityGroupRequest csgr = new CreateSecurityGroupRequest();

	csgr.withGroupName(GROUP_NAME).withDescription("AWS Cluster toolkit security group");
	CreateSecurityGroupResult createSecurityGroupResult =ec2.createSecurityGroup(csgr);

	IpPermission ipPermission =
			new IpPermission();

	IpRange ipRange1 = new IpRange().withCidrIp("0.0.0.0/0");


	ipPermission.withIpv4Ranges(Arrays.asList(new IpRange[] {ipRange1}))
	.withIpProtocol("tcp")
	.withFromPort(0)
	.withToPort(65535);
	AuthorizeSecurityGroupIngressRequest authorizeSecurityGroupIngressRequest =
			new AuthorizeSecurityGroupIngressRequest();

	authorizeSecurityGroupIngressRequest.withGroupName(GROUP_NAME)
	.withIpPermissions(ipPermission);
	ec2.authorizeSecurityGroupIngress(authorizeSecurityGroupIngressRequest);
	System.out.println("Created new security group "+GROUP_NAME+" with /usr/bin/ssh enabled.");

}
 
开发者ID:spagnuolocarmine,项目名称:aws-cluster-toolkit,代码行数:27,代码来源:AwsClusterManager.java

示例2: calculateIpRangeCidr

import com.amazonaws.services.ec2.model.IpRange; //导入依赖的package包/类
public static String calculateIpRangeCidr(Rule rule, IpPermission ipPermission) {
    List<IpRange> ipv4Ranges = ipPermission.getIpv4Ranges();
    List<Ipv6Range> ipv6Ranges = ipPermission.getIpv6Ranges();

    if (rule.protocol.equals(Protocol.ICMPv6.getName())) {

        return ipv6Ranges.size() > 0 ? ipv6Ranges.get(0).getCidrIpv6() : ANY;

    }
    if (rule.protocol.equals(Protocol.ICMPv4.getName())) {

        // it is possible to specify Ipv6Range for IPv4 ICMP protocol
        return ipv4Ranges.size() > 0 ? ipv4Ranges.get(0).getCidrIp() :
        // in case there is no ipv4 cidr, try to obtain ipv6 one
                ipv6Ranges.size() > 0 ? ipv6Ranges.get(0).getCidrIpv6() : ANY;

    }

    return ipv4Ranges.size() > 0 ? ipv4Ranges.get(0).getCidrIp() : ANY;
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:21,代码来源:AWSSecurityGroupUtils.java

示例3: testAllocateSecurityGroupUpdate

import com.amazonaws.services.ec2.model.IpRange; //导入依赖的package包/类
@Test
public void testAllocateSecurityGroupUpdate() throws Throwable {
    String groupId = this.client.createDefaultSecurityGroup(null);

    List<IpPermission> rules = new ArrayList<>();
    IpRange ipRange = new IpRange().withCidrIp(DEFAULT_ALLOWED_NETWORK);
    rules.add(new IpPermission()
            .withIpProtocol(DEFAULT_PROTOCOL)
            .withFromPort(22)
            .withToPort(22)
            .withIpv4Ranges(ipRange));
    this.client.addIngressRules(groupId, rules);
    SecurityGroup updatedGroup = this.client.getDefaultSecurityGroup(null);
    validateDefaultRules(updatedGroup.getIpPermissions());
    this.client.deleteSecurityGroup(groupId);
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:17,代码来源:TestAWSSecurityGroupService.java

示例4: getIpRangesFromSgPermission

import com.amazonaws.services.ec2.model.IpRange; //导入依赖的package包/类
/**
 * Gets the IP ranges defined in the given security group rule.
 *
 * @param permission the given security group rule
 * @return           a list of IP ranges that the security group rule applies to
 */
private List<String> getIpRangesFromSgPermission(IpPermission permission) {
  List<String> cidrs = Lists.newArrayList();
  List<IpRange> ipRanges = permission.getIpv4Ranges();
  if (ipRanges != null && !ipRanges.isEmpty()) {
    for (IpRange ipRange : ipRanges) {
      cidrs.add(ipRange.getCidrIp());
    }
  } else {
    List<Ipv6Range> ipv6Ranges = permission.getIpv6Ranges();
    if (ipv6Ranges != null && !ipv6Ranges.isEmpty()) {
      for (Ipv6Range ipv6Range : ipv6Ranges) {
        cidrs.add(ipv6Range.getCidrIpv6());
      }
    }
  }
  return cidrs;
}
 
开发者ID:cloudera,项目名称:director-aws-plugin,代码行数:24,代码来源:EC2NetworkValidator.java

示例5: testAllTcpFromEverywhereIPv4

import com.amazonaws.services.ec2.model.IpRange; //导入依赖的package包/类
@Test
public void testAllTcpFromEverywhereIPv4() throws Exception {
    assertThat(pred).accepts(
            new IpPermission()
                    .withFromPort(0)
                    .withToPort(65535)
                    .withIpProtocol("tcp")
                    .withIpv4Ranges(new IpRange().withCidrIp("0.0.0.0/0")));

    assertThat(pred).accepts(
            new IpPermission()
                    .withFromPort(0)
                    .withToPort(65535)
                    .withIpProtocol("6")
                    .withIpv4Ranges(new IpRange().withCidrIp("0.0.0.0/0")));
}
 
开发者ID:zalando-stups,项目名称:fullstop,代码行数:17,代码来源:PredicatesTest.java

示例6: testAllUDPFromEverywhereIPv4

import com.amazonaws.services.ec2.model.IpRange; //导入依赖的package包/类
@Test
public void testAllUDPFromEverywhereIPv4() throws Exception {
    assertThat(pred).accepts(
            new IpPermission()
                    .withIpProtocol("udp")
                    .withFromPort(0)
                    .withToPort(65535)
                    .withIpv4Ranges(new IpRange().withCidrIp("0.0.0.0/0")));

    assertThat(pred).accepts(
            new IpPermission()
                    .withIpProtocol("17")
                    .withFromPort(0)
                    .withToPort(65535)
                    .withIpv4Ranges(new IpRange().withCidrIp("0.0.0.0/0")));
}
 
开发者ID:zalando-stups,项目名称:fullstop,代码行数:17,代码来源:PredicatesTest.java

示例7: testAllICMPIPv6FromEverywhereIPv4

import com.amazonaws.services.ec2.model.IpRange; //导入依赖的package包/类
@Test
public void testAllICMPIPv6FromEverywhereIPv4() throws Exception {
    assertThat(pred).rejects(
            new IpPermission()
                    .withIpProtocol("icmpv6")
                    .withFromPort(-1)
                    .withToPort(-1)
                    .withIpv4Ranges(new IpRange().withCidrIp("0.0.0.0/0")));

    assertThat(pred).rejects(
            new IpPermission()
                    .withIpProtocol("58")
                    .withFromPort(-1)
                    .withToPort(-1)
                    .withIpv4Ranges(new IpRange().withCidrIp("0.0.0.0/0")));
}
 
开发者ID:zalando-stups,项目名称:fullstop,代码行数:17,代码来源:PredicatesTest.java

示例8: testAllICMPIPv4FromEverywhereIPv4

import com.amazonaws.services.ec2.model.IpRange; //导入依赖的package包/类
@Test
public void testAllICMPIPv4FromEverywhereIPv4() throws Exception {
    assertThat(pred).rejects(
            new IpPermission()
                    .withIpProtocol("icmp")
                    .withFromPort(-1)
                    .withToPort(-1)
                    .withIpv4Ranges(new IpRange().withCidrIp("0.0.0.0/0")));

    assertThat(pred).rejects(
            new IpPermission()
                    .withIpProtocol("1")
                    .withFromPort(-1)
                    .withToPort(-1)
                    .withIpv4Ranges(new IpRange().withCidrIp("0.0.0.0/0")));
}
 
开发者ID:zalando-stups,项目名称:fullstop,代码行数:17,代码来源:PredicatesTest.java

示例9: setUp

import com.amazonaws.services.ec2.model.IpRange; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Before
public void setUp() throws Exception {
    final ClientProvider mockClientProvider = mock(ClientProvider.class);
    final AmazonEC2Client mockEC2 = mock(AmazonEC2Client.class);
    mockPredicate = (Predicate<IpPermission>) mock(Predicate.class);

    when(mockClientProvider.getClient(any(), any(), any())).thenReturn(mockEC2);

    securityGroupsChecker = new SecurityGroupsCheckerImpl(mockClientProvider, mockPredicate);

    final DescribeSecurityGroupsResult securityGroups = new DescribeSecurityGroupsResult()
            .withSecurityGroups(new SecurityGroup()
                    .withGroupId("sg-12345678")
                    .withGroupName("my-sec-group")
                    .withIpPermissions(new IpPermission()
                            .withIpProtocol("tcp")
                            .withIpv4Ranges(new IpRange().withCidrIp("0.0.0.0/0"))
                            .withFromPort(0)
                            .withToPort(65535)
                            .withIpv6Ranges(new Ipv6Range().withCidrIpv6("::/0"))
                            .withUserIdGroupPairs(new UserIdGroupPair()
                                    .withUserId("111222333444")
                                    .withGroupId("sg-11223344"))));
    when(mockEC2.describeSecurityGroups(any())).thenReturn(securityGroups);
}
 
开发者ID:zalando-stups,项目名称:fullstop,代码行数:27,代码来源:SecurityGroupsCheckerImplTest.java

示例10: createSG

import com.amazonaws.services.ec2.model.IpRange; //导入依赖的package包/类
private String createSG(Environment env) throws Exception {
    String sgName = env.name + ":" + resourceId;
    CreateSecurityGroupRequest request = new CreateSecurityGroupRequest(sgName, sgName);
    if (bakeSubnet != null) request.setVpcId(bakeSubnet.getVpcId());

    String sgId = AWS.ec2.createSecurityGroup(request).getGroupId();
    AWS.ec2.createSGIngressRules(sgId, Lists.newArrayList(new IpPermission()
        .withIpv4Ranges(new IpRange().withCidrIp("0.0.0.0/0"))
        .withFromPort(22)
        .withToPort(22)
        .withIpProtocol("tcp")));

    AWS.ec2.createTags(new CreateTagsRequest()
        .withResources(sgId)
        .withTags(tagHelper.name(resourceId), tagHelper.env(), tagHelper.resourceId(resourceId)));

    return sgId;
}
 
开发者ID:neowu,项目名称:cmn-project,代码行数:19,代码来源:BakeAMITask.java

示例11: createRule

import com.amazonaws.services.ec2.model.IpRange; //导入依赖的package包/类
private IpPermission createRule(int fromPort, int toPort, String subnet,
        String protocol) {

    IpRange ipRange = new IpRange().withCidrIp(subnet);

    protocol = protocol.equals(ALL_TRAFFIC) ? ALL_PROTOCOLS : protocol;

    return new IpPermission()
            .withIpProtocol(protocol)
            .withFromPort(fromPort)
            .withToPort(toPort)
            .withIpv4Ranges(ipRange);
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:14,代码来源:AWSSecurityGroupClient.java

示例12: hasExternalSource

import com.amazonaws.services.ec2.model.IpRange; //导入依赖的package包/类
private static boolean hasExternalSource(final IpPermission rule) {
    final boolean hasExternalIpv4Range = rule.getIpv4Ranges().stream()
            .map(IpRange::getCidrIp)
            .map(Ipv4Range::parseCidr)
            .anyMatch(range -> PRIVATE_IPV4_RANGES.stream().noneMatch(privateRange -> privateRange.contains(range)));

    final boolean hasExternalIpv6Ranges = rule.getIpv6Ranges().stream()
            .map(com.amazonaws.services.ec2.model.Ipv6Range::getCidrIpv6)
            .map(Ipv6Range::parseCidr)
            .anyMatch(range -> !PRIVATE_IPV6_RANGE.contains(range));

    return hasExternalIpv4Range || hasExternalIpv6Ranges;
}
 
开发者ID:zalando-stups,项目名称:fullstop,代码行数:14,代码来源:Predicates.java

示例13: testAllTrafficFromPrivateNetworks

import com.amazonaws.services.ec2.model.IpRange; //导入依赖的package包/类
@Test
public void testAllTrafficFromPrivateNetworks() throws Exception {
    assertThat(pred).rejects(
            new IpPermission()
                    .withIpProtocol("-1")
                    .withIpv4Ranges(
                            new IpRange().withCidrIp("10.0.0.0/8"),
                            new IpRange().withCidrIp("172.31.0.0/16"),
                            new IpRange().withCidrIp("172.16.0.0/12"),
                            new IpRange().withCidrIp("192.168.0.0/16"))
                    .withIpv6Ranges(
                            new Ipv6Range().withCidrIpv6("fc00::/7"))
    );
}
 
开发者ID:zalando-stups,项目名称:fullstop,代码行数:15,代码来源:PredicatesTest.java

示例14: testAllTrafficFromPartiallyPrivateNetwork

import com.amazonaws.services.ec2.model.IpRange; //导入依赖的package包/类
@Test
public void testAllTrafficFromPartiallyPrivateNetwork() throws Exception {
    assertThat(pred).accepts(
            new IpPermission()
                    .withIpProtocol("-1")
                    .withIpv4Ranges(
                            new IpRange().withCidrIp("192.168.0.0/15"))
    );
}
 
开发者ID:zalando-stups,项目名称:fullstop,代码行数:10,代码来源:PredicatesTest.java

示例15: testAllTrafficFromEverywhereIPv4

import com.amazonaws.services.ec2.model.IpRange; //导入依赖的package包/类
@Test
public void testAllTrafficFromEverywhereIPv4() throws Exception {
    assertThat(pred).accepts(
            new IpPermission()
                    .withIpProtocol("-1")
                    .withIpv4Ranges(new IpRange().withCidrIp("0.0.0.0/0")));

    assertThat(pred).accepts(
            new IpPermission()
                    .withIpProtocol(null)
                    .withIpv4Ranges(new IpRange().withCidrIp("0.0.0.0/0")));
}
 
开发者ID:zalando-stups,项目名称:fullstop,代码行数:13,代码来源:PredicatesTest.java


注:本文中的com.amazonaws.services.ec2.model.IpRange类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。