use of com.amazonaws.services.ec2.model.DescribeSubnetsRequest 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.DescribeSubnetsRequest 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.DescribeSubnetsRequest in project photon-model by vmware.
the class AWSSubnetTaskServiceTest method testCreateSubnet.
@Test
public void testCreateSubnet() throws Throwable {
SubnetState subnetState = provisionSubnet(AWS_NON_EXISTING_SUBNET_NAME, AWS_NON_EXISTING_SUBNET_CIDR, null);
assertNotNull(subnetState.id);
assertEquals(LifecycleState.READY, subnetState.lifecycleState);
if (!this.isMock) {
// Verify that the subnet was created.
DescribeSubnetsRequest describeRequest = new DescribeSubnetsRequest().withSubnetIds(Collections.singletonList(subnetState.id));
List<Subnet> subnets = this.client.describeSubnets(describeRequest).getSubnets();
assertNotNull(subnets);
assertEquals(1, subnets.size());
}
}
use of com.amazonaws.services.ec2.model.DescribeSubnetsRequest in project photon-model by vmware.
the class AWSSubnetTaskServiceTest method testDeleteSubnet.
@Test
public void testDeleteSubnet() throws Throwable {
Subnet awsSubnet = createAwsSubnet();
SubnetState subnetState = createSubnetState(awsSubnet.getSubnetId(), AWS_NON_EXISTING_SUBNET_NAME, AWS_NON_EXISTING_SUBNET_CIDR, null);
kickOffSubnetProvision(InstanceRequestType.DELETE, subnetState, TaskStage.FINISHED);
if (!this.isMock) {
// Verify that the subnet was deleted.
DescribeSubnetsRequest describeRequest = new DescribeSubnetsRequest().withSubnetIds(Collections.singletonList(awsSubnet.getSubnetId()));
try {
this.client.describeSubnets(describeRequest).getSubnets();
fail("Subnet should not exist in AWS.");
} catch (AmazonEC2Exception ex) {
assertEquals(HttpResponseStatus.BAD_REQUEST.code(), ex.getStatusCode());
}
}
}
use of com.amazonaws.services.ec2.model.DescribeSubnetsRequest in project photon-model by vmware.
the class AWSNetworkClient method getSubnet.
public Subnet getSubnet(String subnetId) {
DescribeSubnetsRequest req = new DescribeSubnetsRequest().withSubnetIds(subnetId);
DescribeSubnetsResult subnetResult = this.client.describeSubnets(req);
List<Subnet> subnets = subnetResult.getSubnets();
return subnets.isEmpty() ? null : subnets.get(0);
}
Aggregations