本文整理汇总了Java中com.amazonaws.services.ec2.model.IpRange类的典型用法代码示例。如果您正苦于以下问题:Java IpRange类的具体用法?Java IpRange怎么用?Java IpRange使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IpRange类属于com.amazonaws.services.ec2.model包,在下文中一共展示了IpRange类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: testUnallowedPortFromEverywhereIPv4
import com.amazonaws.services.ec2.model.IpRange; //导入依赖的package包/类
@Test
public void testUnallowedPortFromEverywhereIPv4() throws Exception {
assertThat(pred).accepts(
new IpPermission()
.withFromPort(9100)
.withToPort(9100)
.withIpProtocol("tcp")
.withIpv4Ranges(new IpRange().withCidrIp("0.0.0.0/0")));
}
开发者ID:zalando-stups,项目名称:fullstop,代码行数:10,代码来源:PredicatesTest.java
示例17: testAllowedPortFromEverywhereIPv4
import com.amazonaws.services.ec2.model.IpRange; //导入依赖的package包/类
@Test
public void testAllowedPortFromEverywhereIPv4() throws Exception {
assertThat(pred).rejects(
new IpPermission()
.withFromPort(443)
.withToPort(443)
.withIpProtocol("tcp")
.withIpv4Ranges(new IpRange().withCidrIp("0.0.0.0/0")));
}
开发者ID:zalando-stups,项目名称:fullstop,代码行数:10,代码来源:PredicatesTest.java
示例18: addIngressRule
import com.amazonaws.services.ec2.model.IpRange; //导入依赖的package包/类
private void addIngressRule(SecurityGroup securityGroup, Protocol protocol, Source inputSource, Resources resources) {
SecurityGroup.Source source = new SecurityGroup.Source();
if (inputSource.sgId != null) {
source.securityGroup = resources.get(SecurityGroup.class, inputSource.sgId);
} else if (inputSource.cidr != null) {
source.ipRange = new IpRange().withCidrIp(inputSource.cidr);
}
securityGroup.addIngressRule(protocol, source);
}
开发者ID:neowu,项目名称:cmn-project,代码行数:10,代码来源:SGLoader.java
示例19: findDeletedIngressRules
import com.amazonaws.services.ec2.model.IpRange; //导入依赖的package包/类
List<IpPermission> findDeletedIngressRules() {
List<IpPermission> deletedRules = new ArrayList<>();
for (IpPermission permission : remoteIngressRules) {
// delete all traffic rules
if ("-1".equals(permission.getIpProtocol())) {
deletedRules.add(permission);
continue;
}
Protocol protocol = new Protocol(permission.getIpProtocol(), permission.getFromPort(), permission.getToPort());
List<SecurityGroup.Source> sources = localIngressRules.get(protocol);
if (sources == null) {
deletedRules.add(permission);
continue;
}
List<IpRange> deletedIpRanges = permission.getIpv4Ranges().stream()
.filter(ipRange -> !containsIpRange(sources, ipRange))
.collect(Collectors.toList());
List<UserIdGroupPair> deletedSecurityGroupIds = new ArrayList<>();
deletedSecurityGroupIds.addAll(permission.getUserIdGroupPairs().stream()
.filter(userGroup -> !containsSourceUserGroup(sources, userGroup))
.map(userGroup -> new UserIdGroupPair().withUserId(userGroup.getUserId()).withGroupId(userGroup.getGroupId()))
.collect(Collectors.toList()));
if (!deletedIpRanges.isEmpty() || !deletedSecurityGroupIds.isEmpty()) {
IpPermission rule = new IpPermission()
.withIpProtocol(permission.getIpProtocol())
.withFromPort(permission.getFromPort())
.withToPort(permission.getToPort())
.withIpv4Ranges(deletedIpRanges)
.withUserIdGroupPairs(deletedSecurityGroupIds);
deletedRules.add(rule);
}
}
return deletedRules;
}
开发者ID:neowu,项目名称:cmn-project,代码行数:41,代码来源:SecurityGroupRuleHelper.java
示例20: createLabel
import com.amazonaws.services.ec2.model.IpRange; //导入依赖的package包/类
private String createLabel(IpPermission perms) {
List<IpRange> ipRanges = perms.getIpv4Ranges();
String ipProtocol = perms.getIpProtocol();
if (ipProtocol.equals("-1")) {
ipProtocol = "all";
}
if (ipRanges.isEmpty()) {
return String.format("[%s]", ipProtocol);
}
return String.format("(%s)\n[%s]", ipRangesIntoTextList(ipRanges) ,ipProtocol);
}
开发者ID:cartwrightian,项目名称:cfnassist,代码行数:14,代码来源:CommonBuilder.java
注:本文中的com.amazonaws.services.ec2.model.IpRange类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论