use of com.amazonaws.services.ec2.model.DescribeInternetGatewaysRequest in project photon-model by vmware.
the class AWSRemoteCleanup method deleteInternetGateways.
private void deleteInternetGateways(String vpcId, AmazonEC2 usEastEc2Client) {
DescribeInternetGatewaysRequest internetGatewaysRequest = new DescribeInternetGatewaysRequest().withFilters(new Filter(ATTACHMENT_VPC_KEY, Collections.singletonList(vpcId)));
DescribeInternetGatewaysResult internetGatewaysResult = usEastEc2Client.describeInternetGateways(internetGatewaysRequest);
internetGatewaysResult.getInternetGateways().forEach(internetGateway -> {
DetachInternetGatewayRequest detachInternetGatewayRequest = new DetachInternetGatewayRequest().withInternetGatewayId(internetGateway.getInternetGatewayId());
detachInternetGatewayRequest.setVpcId(vpcId);
usEastEc2Client.detachInternetGateway(detachInternetGatewayRequest);
DeleteInternetGatewayRequest deleteInternetGatewayRequest = new DeleteInternetGatewayRequest().withInternetGatewayId(internetGateway.getInternetGatewayId());
this.host.log("Terminating stale internet gateway: %s", internetGateway.getInternetGatewayId());
usEastEc2Client.deleteInternetGateway(deleteInternetGatewayRequest);
});
}
use of com.amazonaws.services.ec2.model.DescribeInternetGatewaysRequest in project photon-model by vmware.
the class AWSNetworkStateEnumerationAdapterService method getInternetGatewayInformation.
/**
* Gets the Internet gateways that are attached to the VPCs that were discovered during the
* enumeration process.
*/
private void getInternetGatewayInformation(AWSNetworkStateCreationContext context, AWSNetworkStateCreationStage next) {
DescribeInternetGatewaysRequest internetGatewayRequest = new DescribeInternetGatewaysRequest();
List<String> vpcList = new ArrayList<>(context.vpcs.keySet());
Filter filter = new Filter(AWS_ATTACHMENT_VPC_FILTER, vpcList);
internetGatewayRequest.getFilters().add(filter);
AWSInternetGatewayAsyncHandler asyncHandler = new AWSInternetGatewayAsyncHandler(next, context);
context.amazonEC2Client.describeInternetGatewaysAsync(internetGatewayRequest, asyncHandler);
}
use of com.amazonaws.services.ec2.model.DescribeInternetGatewaysRequest in project photon-model by vmware.
the class AWSNetworkClient method getInternetGateway.
public InternetGateway getInternetGateway(String resourceId) {
DescribeInternetGatewaysRequest req = new DescribeInternetGatewaysRequest().withInternetGatewayIds(resourceId);
DescribeInternetGatewaysResult res = this.client.describeInternetGateways(req);
List<InternetGateway> internetGateways = res.getInternetGateways();
return internetGateways.isEmpty() ? null : internetGateways.get(0);
}
use of com.amazonaws.services.ec2.model.DescribeInternetGatewaysRequest in project cloudbreak by hortonworks.
the class AwsSetup method validateExistingIGW.
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()));
}
}
}
}
use of com.amazonaws.services.ec2.model.DescribeInternetGatewaysRequest in project cloudbreak by hortonworks.
the class AwsPlatformResources method gateways.
@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);
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);
}
Aggregations