Search in sources :

Example 6 with NatGateway

use of com.amazonaws.services.ec2.model.NatGateway in project photon-model by vmware.

the class AWSRemoteCleanup method deleteNATGateway.

private void deleteNATGateway(String vpcId, AmazonEC2 usEastEc2Client) {
    DescribeNatGatewaysRequest natGatewaysRequest = new DescribeNatGatewaysRequest().withFilter(new Filter(VPC_KEY, Collections.singletonList(vpcId)));
    DescribeNatGatewaysResult natGatewaysResult = usEastEc2Client.describeNatGateways(natGatewaysRequest);
    natGatewaysResult.getNatGateways().forEach(natGateway -> {
        DeleteNatGatewayRequest deleteNatGatewayRequest = new DeleteNatGatewayRequest().withNatGatewayId(natGateway.getNatGatewayId());
        this.host.log("Terminating stale NAT gateway: %s", natGateway.getNatGatewayId());
        usEastEc2Client.deleteNatGateway(deleteNatGatewayRequest);
    });
}
Also used : Filter(com.amazonaws.services.ec2.model.Filter) DescribeNatGatewaysRequest(com.amazonaws.services.ec2.model.DescribeNatGatewaysRequest) DescribeNatGatewaysResult(com.amazonaws.services.ec2.model.DescribeNatGatewaysResult) DeleteNatGatewayRequest(com.amazonaws.services.ec2.model.DeleteNatGatewayRequest)

Example 7 with NatGateway

use of com.amazonaws.services.ec2.model.NatGateway in project photon-model by vmware.

the class AWSNetworkClient method waitForNatGatewayState.

/**
 * Wait for NAT Gateway to go into the desired state
 */
private DeferredResult<String> waitForNatGatewayState(String natGatewayId, TaskManager taskManager, long taskExpirationMicros, String desiredState) {
    DeferredResult<String> waitCompleted = new DeferredResult<>();
    AWSTaskStatusChecker.create(this.client, natGatewayId, desiredState, (ignore) -> waitCompleted.complete(natGatewayId), taskManager, this.service, taskExpirationMicros).start(new NatGateway());
    return waitCompleted;
}
Also used : AWSTaskStatusChecker(com.vmware.photon.controller.model.adapters.awsadapter.AWSTaskStatusChecker) DescribeSubnetsRequest(com.amazonaws.services.ec2.model.DescribeSubnetsRequest) DescribeVpcsRequest(com.amazonaws.services.ec2.model.DescribeVpcsRequest) ReleaseAddressRequest(com.amazonaws.services.ec2.model.ReleaseAddressRequest) AllocateAddressRequest(com.amazonaws.services.ec2.model.AllocateAddressRequest) AttachInternetGatewayRequest(com.amazonaws.services.ec2.model.AttachInternetGatewayRequest) AssociateRouteTableRequest(com.amazonaws.services.ec2.model.AssociateRouteTableRequest) DescribeSubnetsResult(com.amazonaws.services.ec2.model.DescribeSubnetsResult) NatGateway(com.amazonaws.services.ec2.model.NatGateway) CreateTagsRequest(com.amazonaws.services.ec2.model.CreateTagsRequest) CreateNatGatewayResult(com.amazonaws.services.ec2.model.CreateNatGatewayResult) DeleteSubnetResult(com.amazonaws.services.ec2.model.DeleteSubnetResult) DeleteSubnetRequest(com.amazonaws.services.ec2.model.DeleteSubnetRequest) DeleteVpcRequest(com.amazonaws.services.ec2.model.DeleteVpcRequest) AWS_MAIN_ROUTE_ASSOCIATION(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AWS_MAIN_ROUTE_ASSOCIATION) StatelessService(com.vmware.xenon.common.StatelessService) CreateRouteResult(com.amazonaws.services.ec2.model.CreateRouteResult) DescribeInternetGatewaysResult(com.amazonaws.services.ec2.model.DescribeInternetGatewaysResult) TaskManager(com.vmware.photon.controller.model.adapters.util.TaskManager) List(java.util.List) DescribeRouteTablesRequest(com.amazonaws.services.ec2.model.DescribeRouteTablesRequest) Tag(com.amazonaws.services.ec2.model.Tag) DeferredResult(com.vmware.xenon.common.DeferredResult) CreateNatGatewayRequest(com.amazonaws.services.ec2.model.CreateNatGatewayRequest) AssociateRouteTableResult(com.amazonaws.services.ec2.model.AssociateRouteTableResult) DeleteRouteTableRequest(com.amazonaws.services.ec2.model.DeleteRouteTableRequest) AllocateAddressResult(com.amazonaws.services.ec2.model.AllocateAddressResult) CreateSubnetRequest(com.amazonaws.services.ec2.model.CreateSubnetRequest) DescribeRouteTablesResult(com.amazonaws.services.ec2.model.DescribeRouteTablesResult) ROUTE_DEST_ALL(com.vmware.photon.controller.model.adapters.awsadapter.AWSNetworkService.ROUTE_DEST_ALL) DeleteInternetGatewayRequest(com.amazonaws.services.ec2.model.DeleteInternetGatewayRequest) DomainType(com.amazonaws.services.ec2.model.DomainType) DeleteNatGatewayResult(com.amazonaws.services.ec2.model.DeleteNatGatewayResult) CreateSubnetResult(com.amazonaws.services.ec2.model.CreateSubnetResult) CreateRouteTableResult(com.amazonaws.services.ec2.model.CreateRouteTableResult) ArrayList(java.util.ArrayList) CreateVpcResult(com.amazonaws.services.ec2.model.CreateVpcResult) DescribeVpcsResult(com.amazonaws.services.ec2.model.DescribeVpcsResult) Filter(com.amazonaws.services.ec2.model.Filter) RouteTable(com.amazonaws.services.ec2.model.RouteTable) Subnet(com.amazonaws.services.ec2.model.Subnet) CreateVpcRequest(com.amazonaws.services.ec2.model.CreateVpcRequest) AWS_TAG_NAME(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AWS_TAG_NAME) CreateTagsResult(com.amazonaws.services.ec2.model.CreateTagsResult) ReleaseAddressResult(com.amazonaws.services.ec2.model.ReleaseAddressResult) Vpc(com.amazonaws.services.ec2.model.Vpc) DeleteRouteTableResult(com.amazonaws.services.ec2.model.DeleteRouteTableResult) CreateInternetGatewayResult(com.amazonaws.services.ec2.model.CreateInternetGatewayResult) DetachInternetGatewayRequest(com.amazonaws.services.ec2.model.DetachInternetGatewayRequest) DeleteNatGatewayRequest(com.amazonaws.services.ec2.model.DeleteNatGatewayRequest) AWSUtils(com.vmware.photon.controller.model.adapters.awsadapter.AWSUtils) CreateRouteTableRequest(com.amazonaws.services.ec2.model.CreateRouteTableRequest) InternetGateway(com.amazonaws.services.ec2.model.InternetGateway) AmazonEC2Exception(com.amazonaws.services.ec2.model.AmazonEC2Exception) DescribeInternetGatewaysRequest(com.amazonaws.services.ec2.model.DescribeInternetGatewaysRequest) AmazonEC2AsyncClient(com.amazonaws.services.ec2.AmazonEC2AsyncClient) CreateRouteRequest(com.amazonaws.services.ec2.model.CreateRouteRequest) NatGateway(com.amazonaws.services.ec2.model.NatGateway) DeferredResult(com.vmware.xenon.common.DeferredResult)

Aggregations

NatGateway (com.amazonaws.services.ec2.model.NatGateway)5 DescribeNatGatewaysRequest (com.amazonaws.services.ec2.model.DescribeNatGatewaysRequest)4 AmazonEC2Exception (com.amazonaws.services.ec2.model.AmazonEC2Exception)3 Instance (com.amazonaws.services.ec2.model.Instance)3 Volume (com.amazonaws.services.ec2.model.Volume)3 AmazonWebServiceRequest (com.amazonaws.AmazonWebServiceRequest)2 AsyncHandler (com.amazonaws.handlers.AsyncHandler)2 CreateNatGatewayRequest (com.amazonaws.services.ec2.model.CreateNatGatewayRequest)2 CreateNatGatewayResult (com.amazonaws.services.ec2.model.CreateNatGatewayResult)2 DeleteNatGatewayRequest (com.amazonaws.services.ec2.model.DeleteNatGatewayRequest)2 DescribeNatGatewaysResult (com.amazonaws.services.ec2.model.DescribeNatGatewaysResult)2 Filter (com.amazonaws.services.ec2.model.Filter)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 AmazonServiceException (com.amazonaws.AmazonServiceException)1 AmazonWebServiceResult (com.amazonaws.AmazonWebServiceResult)1 AmazonEC2AsyncClient (com.amazonaws.services.ec2.AmazonEC2AsyncClient)1 Address (com.amazonaws.services.ec2.model.Address)1 AllocateAddressRequest (com.amazonaws.services.ec2.model.AllocateAddressRequest)1 AllocateAddressResult (com.amazonaws.services.ec2.model.AllocateAddressResult)1