Search in sources :

Example 1 with DeleteSubnetRequest

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

the class AWSSubnetTaskServiceTest method deleteAwsSubnet.

public void deleteAwsSubnet() {
    if (this.isMock) {
        return;
    }
    DescribeSubnetsRequest subnetRequest = new DescribeSubnetsRequest().withFilters(new Filter(AWS_VPC_ID_FILTER, singletonList((String) this.awsTestContext.get(TestAWSSetupUtils.VPC_KEY)))).withFilters(new Filter(AWS_SUBNET_CIDR_FILTER, singletonList(AWS_NON_EXISTING_SUBNET_CIDR)));
    DescribeSubnetsResult subnetResult = this.client.describeSubnets(subnetRequest);
    subnetResult.getSubnets().forEach(subnet -> {
        DeleteSubnetRequest deleteRequest = new DeleteSubnetRequest(subnet.getSubnetId());
        this.client.deleteSubnet(deleteRequest);
    });
}
Also used : Filter(com.amazonaws.services.ec2.model.Filter) DescribeSubnetsResult(com.amazonaws.services.ec2.model.DescribeSubnetsResult) DeleteSubnetRequest(com.amazonaws.services.ec2.model.DeleteSubnetRequest) DescribeSubnetsRequest(com.amazonaws.services.ec2.model.DescribeSubnetsRequest)

Example 2 with DeleteSubnetRequest

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

the class AWSNetworkClient method deleteSubnetAsync.

public DeferredResult<Void> deleteSubnetAsync(String subnetId) {
    DeleteSubnetRequest req = new DeleteSubnetRequest().withSubnetId(subnetId);
    String message = "Delete AWS Subnet with id [" + subnetId + "].";
    AWSDeferredResultAsyncHandler<DeleteSubnetRequest, DeleteSubnetResult> handler = new AWSDeferredResultAsyncHandler<DeleteSubnetRequest, DeleteSubnetResult>(this.service, message) {

        @Override
        protected Exception consumeError(Exception exception) {
            if (exception instanceof AmazonEC2Exception) {
                AmazonEC2Exception amazonExc = (AmazonEC2Exception) exception;
                if (STATUS_CODE_SUBNET_NOT_FOUND.equals(amazonExc.getErrorCode())) {
                    // AWS subnet doesn't exist.
                    this.service.logWarning(() -> String.format("Unable to delete AWS " + "subnet with id [%s], as it does not exist.", subnetId));
                    return RECOVERED;
                }
            }
            return exception;
        }
    };
    this.client.deleteSubnetAsync(req, handler);
    return handler.toDeferredResult().thenApply(result -> (Void) null);
}
Also used : DeleteSubnetResult(com.amazonaws.services.ec2.model.DeleteSubnetResult) DeleteSubnetRequest(com.amazonaws.services.ec2.model.DeleteSubnetRequest) AmazonEC2Exception(com.amazonaws.services.ec2.model.AmazonEC2Exception) AmazonEC2Exception(com.amazonaws.services.ec2.model.AmazonEC2Exception)

Example 3 with DeleteSubnetRequest

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

the class AWSRemoteCleanup method deleteSubnets.

private void deleteSubnets(String vpcId, AmazonEC2 usEastEc2Client) {
    DescribeSubnetsRequest subnetsRequest = new DescribeSubnetsRequest().withFilters(new Filter(VPC_KEY, Collections.singletonList(vpcId)));
    DescribeSubnetsResult securityGroupsResult = usEastEc2Client.describeSubnets(subnetsRequest);
    securityGroupsResult.getSubnets().forEach(subnet -> {
        DeleteSubnetRequest deleteSubnetRequest = new DeleteSubnetRequest().withSubnetId(subnet.getSubnetId());
        this.host.log("Terminating stale subnet: %s", subnet.getSubnetId());
        usEastEc2Client.deleteSubnet(deleteSubnetRequest);
    });
}
Also used : Filter(com.amazonaws.services.ec2.model.Filter) DescribeSubnetsResult(com.amazonaws.services.ec2.model.DescribeSubnetsResult) DeleteSubnetRequest(com.amazonaws.services.ec2.model.DeleteSubnetRequest) DescribeSubnetsRequest(com.amazonaws.services.ec2.model.DescribeSubnetsRequest)

Example 4 with DeleteSubnetRequest

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

the class AWSSubnetTaskServiceTest method deleteAwsPublicSubnet.

public void deleteAwsPublicSubnet() {
    if (this.isMock) {
        return;
    }
    DescribeSubnetsRequest subnetRequest = new DescribeSubnetsRequest().withFilters(new Filter(AWS_VPC_ID_FILTER, singletonList((String) this.awsTestContext.get(TestAWSSetupUtils.VPC_KEY)))).withFilters(new Filter(AWS_SUBNET_CIDR_FILTER, singletonList(AWS_NON_EXISTING_PUBLIC_SUBNET_CIDR)));
    DescribeSubnetsResult subnetResult = this.client.describeSubnets(subnetRequest);
    subnetResult.getSubnets().forEach(subnet -> {
        DeleteSubnetRequest deleteRequest = new DeleteSubnetRequest(subnet.getSubnetId());
        this.client.deleteSubnet(deleteRequest);
    });
}
Also used : Filter(com.amazonaws.services.ec2.model.Filter) DescribeSubnetsResult(com.amazonaws.services.ec2.model.DescribeSubnetsResult) DeleteSubnetRequest(com.amazonaws.services.ec2.model.DeleteSubnetRequest) DescribeSubnetsRequest(com.amazonaws.services.ec2.model.DescribeSubnetsRequest)

Example 5 with DeleteSubnetRequest

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

the class AWSNetworkClient method deleteSubnet.

/**
 * Delete the specified subnet
 *
 * @throws AmazonEC2Exception if the subnet doesn't exist.
 */
public void deleteSubnet(String subnetId) throws AmazonEC2Exception {
    DeleteSubnetRequest req = new DeleteSubnetRequest().withSubnetId(subnetId);
    this.client.deleteSubnet(req);
}
Also used : DeleteSubnetRequest(com.amazonaws.services.ec2.model.DeleteSubnetRequest)

Aggregations

DeleteSubnetRequest (com.amazonaws.services.ec2.model.DeleteSubnetRequest)5 DescribeSubnetsRequest (com.amazonaws.services.ec2.model.DescribeSubnetsRequest)3 DescribeSubnetsResult (com.amazonaws.services.ec2.model.DescribeSubnetsResult)3 Filter (com.amazonaws.services.ec2.model.Filter)3 AmazonEC2Exception (com.amazonaws.services.ec2.model.AmazonEC2Exception)1 DeleteSubnetResult (com.amazonaws.services.ec2.model.DeleteSubnetResult)1