com.amazonaws.services.ec2.model.DescribeInternetGatewaysResult Java Examples
The following examples show how to use
com.amazonaws.services.ec2.model.DescribeInternetGatewaysResult.
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: EC2InventoryUtilTest.java From pacbot with Apache License 2.0 | 6 votes |
/** * Fetch internet gateway test. * * @throws Exception the exception */ @SuppressWarnings("static-access") @Test public void fetchInternetGatewayTest() throws Exception { mockStatic(AmazonEC2ClientBuilder.class); AmazonEC2 ec2Client = PowerMockito.mock(AmazonEC2.class); AmazonEC2ClientBuilder amazonEC2ClientBuilder = PowerMockito.mock(AmazonEC2ClientBuilder.class); AWSStaticCredentialsProvider awsStaticCredentialsProvider = PowerMockito.mock(AWSStaticCredentialsProvider.class); PowerMockito.whenNew(AWSStaticCredentialsProvider.class).withAnyArguments().thenReturn(awsStaticCredentialsProvider); when(amazonEC2ClientBuilder.standard()).thenReturn(amazonEC2ClientBuilder); when(amazonEC2ClientBuilder.withCredentials(anyObject())).thenReturn(amazonEC2ClientBuilder); when(amazonEC2ClientBuilder.withRegion(anyString())).thenReturn(amazonEC2ClientBuilder); when(amazonEC2ClientBuilder.build()).thenReturn(ec2Client); DescribeInternetGatewaysResult describeInternetGatewaysResult = new DescribeInternetGatewaysResult(); List<InternetGateway> internetGatewayList = new ArrayList<>(); internetGatewayList.add(new InternetGateway()); describeInternetGatewaysResult.setInternetGateways(internetGatewayList); when(ec2Client.describeInternetGateways()).thenReturn(describeInternetGatewaysResult); assertThat(ec2InventoryUtil.fetchInternetGateway(new BasicSessionCredentials("awsAccessKey", "awsSecretKey", "sessionToken"), "skipRegions", "account","accountName").size(), is(1)); }
Example #2
Source File: AwsSetup.java From cloudbreak with Apache License 2.0 | 6 votes |
private void validateExistingIGW(AwsNetworkView awsNetworkView, AmazonEC2 amazonEC2Client) { if (awsNetworkView.isExistingIGW()) { DescribeInternetGatewaysRequest describeInternetGatewaysRequest = new DescribeInternetGatewaysRequest(); describeInternetGatewaysRequest.withInternetGatewayIds(awsNetworkView.getExistingIgw()); DescribeInternetGatewaysResult describeInternetGatewaysResult = amazonEC2Client.describeInternetGateways(describeInternetGatewaysRequest); if (describeInternetGatewaysResult.getInternetGateways().size() < 1) { throw new CloudConnectorException(String.format(IGW_DOES_NOT_EXIST_MSG, awsNetworkView.getExistingIgw())); } else { InternetGateway internetGateway = describeInternetGatewaysResult.getInternetGateways().get(0); InternetGatewayAttachment attachment = internetGateway.getAttachments().get(0); if (attachment != null && !attachment.getVpcId().equals(awsNetworkView.getExistingVpc())) { throw new CloudConnectorException(String.format(IGWVPC_DOES_NOT_EXIST_MSG, awsNetworkView.getExistingIgw(), awsNetworkView.getExistingVpc())); } } } }
Example #3
Source File: AwsPlatformResources.java From cloudbreak with Apache License 2.0 | 5 votes |
@Override public CloudGateWays gateways(CloudCredential cloudCredential, Region region, Map<String, String> filters) { AmazonEC2Client ec2Client = awsClient.createAccess(cloudCredential); Map<String, Set<CloudGateWay>> resultCloudGateWayMap = new HashMap<>(); CloudRegions regions = regions(cloudCredential, region, filters, true); for (Entry<Region, List<AvailabilityZone>> regionListEntry : regions.getCloudRegions().entrySet()) { if (region == null || Strings.isNullOrEmpty(region.value()) || regionListEntry.getKey().value().equals(region.value())) { ec2Client.setRegion(RegionUtils.getRegion(regionListEntry.getKey().value())); DescribeInternetGatewaysRequest describeInternetGatewaysRequest = new DescribeInternetGatewaysRequest(); DescribeInternetGatewaysResult describeInternetGatewaysResult = ec2Client.describeInternetGateways(describeInternetGatewaysRequest); Set<CloudGateWay> gateWays = new HashSet<>(); for (InternetGateway internetGateway : describeInternetGatewaysResult.getInternetGateways()) { CloudGateWay cloudGateWay = new CloudGateWay(); cloudGateWay.setId(internetGateway.getInternetGatewayId()); cloudGateWay.setName(internetGateway.getInternetGatewayId()); Collection<String> vpcs = new ArrayList<>(); for (InternetGatewayAttachment internetGatewayAttachment : internetGateway.getAttachments()) { vpcs.add(internetGatewayAttachment.getVpcId()); } Map<String, Object> properties = new HashMap<>(); properties.put("attachment", vpcs); cloudGateWay.setProperties(properties); gateWays.add(cloudGateWay); } for (AvailabilityZone availabilityZone : regionListEntry.getValue()) { resultCloudGateWayMap.put(availabilityZone.value(), gateWays); } } } return new CloudGateWays(resultCloudGateWayMap); }
Example #4
Source File: BaseTest.java From aws-mock with MIT License | 5 votes |
/** * Describe internet gateway. * * @return InternetGateway */ protected final InternetGateway getInternetGateway() { InternetGateway internetGateway = null; DescribeInternetGatewaysRequest req = new DescribeInternetGatewaysRequest(); DescribeInternetGatewaysResult result = amazonEC2Client.describeInternetGateways(req); if (result != null && !result.getInternetGateways().isEmpty()) { internetGateway = result.getInternetGateways().get(0); } return internetGateway; }
Example #5
Source File: BaseTest.java From aws-mock with MIT License | 5 votes |
/** * Describe internet gateways. * * @return List of InternetGateway */ protected final List<InternetGateway> getInternetGateways() { List<InternetGateway> internetGateways = null; DescribeInternetGatewaysRequest req = new DescribeInternetGatewaysRequest(); DescribeInternetGatewaysResult result = amazonEC2Client.describeInternetGateways(req); if (result != null && !result.getInternetGateways().isEmpty()) { internetGateways = result.getInternetGateways(); } return internetGateways; }
Example #6
Source File: InternetGatewayImpl.java From aws-sdk-java-resources with Apache License 2.0 | 4 votes |
@Override public boolean load(DescribeInternetGatewaysRequest request, ResultCapture<DescribeInternetGatewaysResult> extractor) { return resource.load(request, extractor); }
Example #7
Source File: InternetGateway.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>InternetGateway</code> resource, and any conflicting parameter * value set in the request will be overridden: * <ul> * <li> * <b><code>InternetGatewayIds.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 DescribeInternetGatewaysRequest */ boolean load(DescribeInternetGatewaysRequest request, ResultCapture<DescribeInternetGatewaysResult> extractor);