com.amazonaws.services.ec2.model.DescribeSubnetsRequest Java Examples
The following examples show how to use
com.amazonaws.services.ec2.model.DescribeSubnetsRequest.
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: SubnetTableProviderTest.java From aws-athena-query-federation with Apache License 2.0 | 6 votes |
@Override protected void setUpRead() { when(mockEc2.describeSubnets(any(DescribeSubnetsRequest.class))).thenAnswer((InvocationOnMock invocation) -> { DescribeSubnetsRequest request = (DescribeSubnetsRequest) invocation.getArguments()[0]; assertEquals(getIdValue(), request.getSubnetIds().get(0)); DescribeSubnetsResult mockResult = mock(DescribeSubnetsResult.class); List<Subnet> values = new ArrayList<>(); values.add(makeSubnet(getIdValue())); values.add(makeSubnet(getIdValue())); values.add(makeSubnet("fake-id")); when(mockResult.getSubnets()).thenReturn(values); return mockResult; }); }
Example #2
Source File: SubnetTableProvider.java From aws-athena-query-federation with Apache License 2.0 | 6 votes |
/** * Calls DescribeSubnets on the AWS EC2 Client returning all subnets that match the supplied predicate and attempting * to push down certain predicates (namely queries for specific subnet) to EC2. * * @See TableProvider */ @Override public void readWithConstraint(BlockSpiller spiller, ReadRecordsRequest recordsRequest, QueryStatusChecker queryStatusChecker) { DescribeSubnetsRequest request = new DescribeSubnetsRequest(); ValueSet idConstraint = recordsRequest.getConstraints().getSummary().get("id"); if (idConstraint != null && idConstraint.isSingleValue()) { request.setSubnetIds(Collections.singletonList(idConstraint.getSingleValue().toString())); } DescribeSubnetsResult response = ec2.describeSubnets(request); for (Subnet subnet : response.getSubnets()) { instanceToRow(subnet, spiller); } }
Example #3
Source File: EC2Communication.java From development with Apache License 2.0 | 6 votes |
/** * Checks whether exiting Subnet is present. * * @param subnetString * @return <code>Subnet </code> if the matches one of the subnetString * */ public Subnet resolveSubnet(String subnetString) throws APPlatformException { DescribeSubnetsRequest request = new DescribeSubnetsRequest(); DescribeSubnetsResult result = getEC2().describeSubnets( request.withSubnetIds(subnetString)); List<Subnet> subnets = result.getSubnets(); if (!subnets.isEmpty()) { LOGGER.debug(" number of subnets found: " + subnets.size()); for (Subnet subnet : subnets) { LOGGER.debug("return subnet with id " + subnet.getSubnetId()); return subnet; } } throw new APPlatformException( Messages.getAll("error_invalid_subnet_id") + subnetString); }
Example #4
Source File: AwsNetworkService.java From cloudbreak with Apache License 2.0 | 6 votes |
public String findNonOverLappingCIDR(AuthenticatedContext ac, CloudStack stack) { AwsNetworkView awsNetworkView = new AwsNetworkView(stack.getNetwork()); String region = ac.getCloudContext().getLocation().getRegion().value(); AmazonEC2Client ec2Client = awsClient.createAccess(new AwsCredentialView(ac.getCloudCredential()), region); DescribeVpcsRequest vpcRequest = new DescribeVpcsRequest().withVpcIds(awsNetworkView.getExistingVpc()); Vpc vpc = ec2Client.describeVpcs(vpcRequest).getVpcs().get(0); String vpcCidr = vpc.getCidrBlock(); LOGGER.debug("Subnet cidr is empty, find a non-overlapping subnet for VPC cidr: {}", vpcCidr); DescribeSubnetsRequest request = new DescribeSubnetsRequest().withFilters(new Filter("vpc-id", singletonList(awsNetworkView.getExistingVpc()))); List<Subnet> awsSubnets = ec2Client.describeSubnets(request).getSubnets(); List<String> subnetCidrs = awsSubnets.stream().map(Subnet::getCidrBlock).collect(Collectors.toList()); LOGGER.debug("The selected VPCs: {}, has the following subnets: {}", vpc.getVpcId(), String.join(",", subnetCidrs)); return calculateSubnet(ac.getCloudContext().getName(), vpc, subnetCidrs); }
Example #5
Source File: AwsIaasGatewayScriptService.java From primecloud-controller with GNU General Public License v2.0 | 6 votes |
@Override public boolean hasSubnets(String vpcId) throws AutoException { if (StringUtils.isEmpty(vpcId)) { log.info(platform.getPlatformName() + " にvpcIdが有りません"); System.out.println("VPCID_EMPTY"); return false; } DescribeSubnetsRequest request = new DescribeSubnetsRequest(); request.withFilters(new Filter().withName("vpc-id").withValues(vpcId)); DescribeSubnetsResult result = ec2Client.describeSubnets(request); List<Subnet> subnets = result.getSubnets(); if (subnets.isEmpty()) { log.info(platform.getPlatformName() + " にサブネットが有りません"); System.out.println("SUBNET_EMPTY"); return false; } return true; }
Example #6
Source File: AwsPlatformResources.java From cloudbreak with Apache License 2.0 | 6 votes |
private List<Subnet> getSubnets(AmazonEC2Client ec2Client, Vpc vpc) { List<Subnet> awsSubnets = new ArrayList<>(); DescribeSubnetsResult describeSubnetsResult = null; boolean first = true; while (first || !isNullOrEmpty(describeSubnetsResult.getNextToken())) { LOGGER.debug("Describing subnets for VPC {}{}", vpc.getVpcId(), first ? "" : " (continuation)"); first = false; DescribeSubnetsRequest describeSubnetsRequest = createSubnetsDescribeRequest(vpc, describeSubnetsResult == null ? null : describeSubnetsResult.getNextToken()); describeSubnetsResult = ec2Client.describeSubnets(describeSubnetsRequest); awsSubnets.addAll(describeSubnetsResult.getSubnets()); awsSubnets = awsSubnets.stream().filter(subnet -> !deniedAZs.contains(subnet.getAvailabilityZone())) .collect(Collectors.toList()); } return awsSubnets; }
Example #7
Source File: AwsSetup.java From cloudbreak with Apache License 2.0 | 6 votes |
private void validateExistingSubnet(AwsNetworkView awsNetworkView, AmazonEC2 amazonEC2Client) { if (awsNetworkView.isExistingSubnet()) { DescribeSubnetsRequest describeSubnetsRequest = new DescribeSubnetsRequest(); describeSubnetsRequest.withSubnetIds(awsNetworkView.getSubnetList()); DescribeSubnetsResult describeSubnetsResult = amazonEC2Client.describeSubnets(describeSubnetsRequest); if (describeSubnetsResult.getSubnets().size() < awsNetworkView.getSubnetList().size()) { throw new CloudConnectorException(String.format(SUBNET_DOES_NOT_EXIST_MSG, awsNetworkView.getExistingSubnet())); } else { for (Subnet subnet : describeSubnetsResult.getSubnets()) { String vpcId = subnet.getVpcId(); if (vpcId != null && !vpcId.equals(awsNetworkView.getExistingVpc())) { throw new CloudConnectorException(String.format(SUBNETVPC_DOES_NOT_EXIST_MSG, awsNetworkView.getExistingSubnet(), awsNetworkView.getExistingVpc())); } } } } }
Example #8
Source File: BaseTest.java From aws-mock with MIT License | 5 votes |
/** * Describe Subnets. * @return List of Subnet */ protected final List<Subnet> getSubnets() { List<Subnet> subnets = null; DescribeSubnetsRequest req = new DescribeSubnetsRequest(); DescribeSubnetsResult result = amazonEC2Client.describeSubnets(req); if (result != null && !result.getSubnets().isEmpty()) { subnets = result.getSubnets(); } return subnets; }
Example #9
Source File: BaseTest.java From aws-mock with MIT License | 5 votes |
/** * Describe Subnet. * * @return Subnet */ protected final Subnet getSubnet() { Subnet subnet = null; DescribeSubnetsRequest req = new DescribeSubnetsRequest(); DescribeSubnetsResult result = amazonEC2Client.describeSubnets(req); if (result != null && !result.getSubnets().isEmpty()) { subnet = result.getSubnets().get(0); } return subnet; }
Example #10
Source File: AwsLaunchTest.java From cloudbreak with Apache License 2.0 | 5 votes |
private void setupDescribeSubnetResponse() { when(amazonEC2Client.describeSubnets(any())).thenAnswer( (Answer<DescribeSubnetsResult>) invocation -> { DescribeSubnetsRequest request = (DescribeSubnetsRequest) invocation.getArgument(0); String subnetId = request.getSubnetIds().get(0); DescribeSubnetsResult result = new DescribeSubnetsResult() .withSubnets(new com.amazonaws.services.ec2.model.Subnet() .withSubnetId(subnetId) .withAvailabilityZone(AVAILABILITY_ZONE)); return result; } ); }
Example #11
Source File: AwsNetworkService.java From cloudbreak with Apache License 2.0 | 5 votes |
public boolean isMapPublicOnLaunch(AwsNetworkView awsNetworkView, AmazonEC2 amazonEC2Client) { boolean mapPublicIpOnLaunch = true; if (awsNetworkView.isExistingVPC() && awsNetworkView.isExistingSubnet()) { DescribeSubnetsRequest describeSubnetsRequest = new DescribeSubnetsRequest(); describeSubnetsRequest.setSubnetIds(awsNetworkView.getSubnetList()); DescribeSubnetsResult describeSubnetsResult = amazonEC2Client.describeSubnets(describeSubnetsRequest); if (!describeSubnetsResult.getSubnets().isEmpty()) { mapPublicIpOnLaunch = describeSubnetsResult.getSubnets().get(0).isMapPublicIpOnLaunch(); } } return mapPublicIpOnLaunch; }
Example #12
Source File: AwsNetworkService.java From cloudbreak with Apache License 2.0 | 5 votes |
public List<String> getExistingSubnetCidr(AuthenticatedContext ac, CloudStack stack) { AwsNetworkView awsNetworkView = new AwsNetworkView(stack.getNetwork()); String region = ac.getCloudContext().getLocation().getRegion().value(); AmazonEC2Client ec2Client = awsClient.createAccess(new AwsCredentialView(ac.getCloudCredential()), region); DescribeSubnetsRequest subnetsRequest = new DescribeSubnetsRequest().withSubnetIds(awsNetworkView.getSubnetList()); List<Subnet> subnets = ec2Client.describeSubnets(subnetsRequest).getSubnets(); if (subnets.isEmpty()) { throw new CloudConnectorException("The specified subnet does not exist (maybe it's in a different region)."); } List<String> cidrs = Lists.newArrayList(); for (Subnet subnet : subnets) { cidrs.add(subnet.getCidrBlock()); } return cidrs; }
Example #13
Source File: AwsVolumeResourceBuilder.java From cloudbreak with Apache License 2.0 | 5 votes |
private String getAvailabilityZoneFromSubnet(AuthenticatedContext auth, CloudResource subnetResource) { AmazonEc2RetryClient amazonEC2Client = getAmazonEC2Client(auth); DescribeSubnetsResult describeSubnetsResult = amazonEC2Client.describeSubnets(new DescribeSubnetsRequest() .withSubnetIds(subnetResource.getName())); return describeSubnetsResult.getSubnets().stream() .filter(subnet -> subnetResource.getName().equals(subnet.getSubnetId())) .map(Subnet::getAvailabilityZone) .findFirst() .orElse(auth.getCloudContext().getLocation().getAvailabilityZone().value()); }
Example #14
Source File: EC2Impl.java From aws-sdk-java-resources with Apache License 2.0 | 5 votes |
@Override public SubnetCollection getSubnets(DescribeSubnetsRequest request) { ResourceCollectionImpl result = service.getCollection("Subnets", request); if (result == null) return null; return new SubnetCollectionImpl(result); }
Example #15
Source File: VpcImpl.java From aws-sdk-java-resources with Apache License 2.0 | 5 votes |
@Override public SubnetCollection getSubnets(DescribeSubnetsRequest request) { ResourceCollectionImpl result = resource.getCollection("Subnets", request); if (result == null) return null; return new SubnetCollectionImpl(result); }
Example #16
Source File: AwsCommonProcess.java From primecloud-controller with GNU General Public License v2.0 | 5 votes |
public List<Subnet> describeSubnetsByVpcId(AwsProcessClient awsProcessClient, String vpcId) { DescribeSubnetsRequest request = new DescribeSubnetsRequest(); request.withFilters(new Filter().withName("vpc-id").withValues(vpcId)); DescribeSubnetsResult result = awsProcessClient.getEc2Client().describeSubnets(request); List<Subnet> subnets = result.getSubnets(); return subnets; }
Example #17
Source File: AwsDescribeServiceImpl.java From primecloud-controller with GNU General Public License v2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public List<Subnet> getSubnets(Long userNo, Long platformNo) { // VPCかどうかのチェック PlatformAws platformAws = platformAwsDao.read(platformNo); if (BooleanUtils.isNotTrue(platformAws.getVpc())) { // 非VPCの場合、サブネットはない return new ArrayList<Subnet>(); } // サブネットを取得 AwsProcessClient awsProcessClient = awsProcessClientFactory.createAwsProcessClient(userNo, platformNo); DescribeSubnetsRequest request = new DescribeSubnetsRequest(); request.withFilters(new Filter().withName("vpc-id").withValues(platformAws.getVpcId())); DescribeSubnetsResult result = awsProcessClient.getEc2Client().describeSubnets(request); List<Subnet> subnets = result.getSubnets(); // プラットフォームにサブネットが指定されている場合、そのサブネットのみに制限する if (StringUtils.isNotEmpty(awsProcessClient.getPlatformAws().getSubnetId())) { List<String> subnetIds = new ArrayList<String>(); for (String subnetId : StringUtils.split(awsProcessClient.getPlatformAws().getSubnetId(), ",")) { subnetIds.add(subnetId.trim()); } List<Subnet> subnets2 = new ArrayList<Subnet>(); for (Subnet subnet : subnets) { if (subnetIds.contains(subnet.getSubnetId())) { subnets2.add(subnet); } } subnets = subnets2; } // ソート Collections.sort(subnets, Comparators.COMPARATOR_SUBNET); return subnets; }
Example #18
Source File: Ec2DaoImpl.java From herd with Apache License 2.0 | 5 votes |
/** * This implementation uses the DescribeSubnets API. */ @Override public List<Subnet> getSubnets(Collection<String> subnetIds, AwsParamsDto awsParamsDto) { AmazonEC2Client ec2Client = getEc2Client(awsParamsDto); DescribeSubnetsRequest describeSubnetsRequest = new DescribeSubnetsRequest(); describeSubnetsRequest.setSubnetIds(subnetIds); try { DescribeSubnetsResult describeSubnetsResult = ec2Operations.describeSubnets(ec2Client, describeSubnetsRequest); return describeSubnetsResult.getSubnets(); } catch (AmazonServiceException amazonServiceException) { /* * AWS throws a 400 error when any one of the specified subnet ID is not found. * We want to catch it and throw as an handled herd error as a 404 not found. */ if (ERROR_CODE_SUBNET_ID_NOT_FOUND.equals(amazonServiceException.getErrorCode())) { throw new ObjectNotFoundException(amazonServiceException.getErrorMessage(), amazonServiceException); } // Any other type of error we throw as is because they are unexpected. else { throw amazonServiceException; } } }
Example #19
Source File: EC2Mockup.java From development with Apache License 2.0 | 5 votes |
public void createDescribeSubnetsResult(String... subnetIds) { Collection<Subnet> subnets = new ArrayList<Subnet>(); for (int i = 0; i < subnetIds.length; i++) { subnets.add(new Subnet().withSubnetId(subnetIds[i]) .withVpcId(subnetIds[i])); } DescribeSubnetsResult subnetResult = new DescribeSubnetsResult() .withSubnets(subnets); doReturn(subnetResult).when(ec2) .describeSubnets(any(DescribeSubnetsRequest.class)); }
Example #20
Source File: SubnetImpl.java From aws-sdk-java-resources with Apache License 2.0 | 4 votes |
@Override public boolean load(DescribeSubnetsRequest request, ResultCapture<DescribeSubnetsResult> extractor) { return resource.load(request, extractor); }
Example #21
Source File: EC2Impl.java From aws-sdk-java-resources with Apache License 2.0 | 4 votes |
@Override public SubnetCollection getSubnets() { return getSubnets((DescribeSubnetsRequest)null); }
Example #22
Source File: SubnetImpl.java From aws-sdk-java-resources with Apache License 2.0 | 4 votes |
@Override public boolean load(DescribeSubnetsRequest request) { return load(request, null); }
Example #23
Source File: AwsPlatformResources.java From cloudbreak with Apache License 2.0 | 4 votes |
private DescribeSubnetsRequest createSubnetsDescribeRequest(Vpc vpc, String nextToken) { return new DescribeSubnetsRequest() .withFilters(new Filter("vpc-id", singletonList(vpc.getVpcId()))) .withNextToken(nextToken); }
Example #24
Source File: Ec2OperationsImpl.java From herd with Apache License 2.0 | 4 votes |
@Override public DescribeSubnetsResult describeSubnets(AmazonEC2Client ec2Client, DescribeSubnetsRequest describeSubnetsRequest) { return ec2Client.describeSubnets(describeSubnetsRequest); }
Example #25
Source File: AmazonEc2RetryClient.java From cloudbreak with Apache License 2.0 | 4 votes |
public DescribeSubnetsResult describeSubnets(DescribeSubnetsRequest request) { return retry.testWith2SecDelayMax15Times(() -> mapThrottlingError(() -> client.describeSubnets(request))); }
Example #26
Source File: Ec2Utils.java From pacbot with Apache License 2.0 | 3 votes |
/** * Gets the subnets for region. * * @param ec2ServiceClient the ec 2 service client * @param region the region * @param describeSubnetsRequest the describe subnets request * @return the subnets for region */ public static List<Subnet> getSubnetsForRegion(AmazonEC2 ec2ServiceClient, Region region, DescribeSubnetsRequest describeSubnetsRequest) { ec2ServiceClient.setRegion(region); DescribeSubnetsResult describeSubnetsResult = ec2ServiceClient.describeSubnets(describeSubnetsRequest); return describeSubnetsResult.getSubnets(); }
Example #27
Source File: Subnet.java From aws-sdk-java-resources with Apache License 2.0 | 2 votes |
/** * Makes a call to the service to load this resource's attributes if they * are not loaded yet. * The following request parameters will be populated from the data of this * <code>Subnet</code> resource, and any conflicting parameter value set in * the request will be overridden: * <ul> * <li> * <b><code>SubnetIds.0</code></b> * - mapped from the <code>Id</code> identifier. * </li> * </ul> * * <p> * * @return Returns {@code true} if the resource is not yet loaded when this * method was invoked, which indicates that a service call has been * made to retrieve the attributes. * @see DescribeSubnetsRequest */ boolean load(DescribeSubnetsRequest request);
Example #28
Source File: Subnet.java From aws-sdk-java-resources with Apache License 2.0 | 2 votes |
/** * Makes a call to the service to load this resource's attributes if they * are not loaded yet, and use a ResultCapture to retrieve the low-level * client response * The following request parameters will be populated from the data of this * <code>Subnet</code> resource, and any conflicting parameter value set in * the request will be overridden: * <ul> * <li> * <b><code>SubnetIds.0</code></b> * - mapped from the <code>Id</code> identifier. * </li> * </ul> * * <p> * * @return Returns {@code true} if the resource is not yet loaded when this * method was invoked, which indicates that a service call has been * made to retrieve the attributes. * @see DescribeSubnetsRequest */ boolean load(DescribeSubnetsRequest request, ResultCapture<DescribeSubnetsResult> extractor);
Example #29
Source File: EC2.java From aws-sdk-java-resources with Apache License 2.0 | 2 votes |
/** * Retrieves the Subnets collection referenced by this resource. */ SubnetCollection getSubnets(DescribeSubnetsRequest request);
Example #30
Source File: Vpc.java From aws-sdk-java-resources with Apache License 2.0 | 2 votes |
/** * Retrieves the Subnets collection referenced by this resource. */ SubnetCollection getSubnets(DescribeSubnetsRequest request);