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);
});
}
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);
}
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);
});
}
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);
});
}
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);
}
Aggregations