Search in sources :

Example 11 with DescribeSubnetsRequest

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);
    });
}
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 12 with DescribeSubnetsRequest

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);
    });
}
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 13 with DescribeSubnetsRequest

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());
    }
}
Also used : Subnet(com.amazonaws.services.ec2.model.Subnet) SubnetState(com.vmware.photon.controller.model.resources.SubnetService.SubnetState) DescribeSubnetsRequest(com.amazonaws.services.ec2.model.DescribeSubnetsRequest) BaseModelTest(com.vmware.photon.controller.model.helpers.BaseModelTest) Test(org.junit.Test)

Example 14 with DescribeSubnetsRequest

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());
        }
    }
}
Also used : Subnet(com.amazonaws.services.ec2.model.Subnet) SubnetState(com.vmware.photon.controller.model.resources.SubnetService.SubnetState) AmazonEC2Exception(com.amazonaws.services.ec2.model.AmazonEC2Exception) DescribeSubnetsRequest(com.amazonaws.services.ec2.model.DescribeSubnetsRequest) BaseModelTest(com.vmware.photon.controller.model.helpers.BaseModelTest) Test(org.junit.Test)

Example 15 with DescribeSubnetsRequest

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);
}
Also used : Subnet(com.amazonaws.services.ec2.model.Subnet) DescribeSubnetsResult(com.amazonaws.services.ec2.model.DescribeSubnetsResult) DescribeSubnetsRequest(com.amazonaws.services.ec2.model.DescribeSubnetsRequest)

Aggregations

DescribeSubnetsRequest (com.amazonaws.services.ec2.model.DescribeSubnetsRequest)15 DescribeSubnetsResult (com.amazonaws.services.ec2.model.DescribeSubnetsResult)10 Subnet (com.amazonaws.services.ec2.model.Subnet)9 Filter (com.amazonaws.services.ec2.model.Filter)7 AmazonEC2Client (com.amazonaws.services.ec2.AmazonEC2Client)4 DeleteSubnetRequest (com.amazonaws.services.ec2.model.DeleteSubnetRequest)4 SubnetState (com.vmware.photon.controller.model.resources.SubnetService.SubnetState)4 ArrayList (java.util.ArrayList)4 AmazonEC2Exception (com.amazonaws.services.ec2.model.AmazonEC2Exception)3 AmazonServiceException (com.amazonaws.AmazonServiceException)2 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)2 BaseModelTest (com.vmware.photon.controller.model.helpers.BaseModelTest)2 Test (org.junit.Test)2 AsyncHandler (com.amazonaws.handlers.AsyncHandler)1 AmazonEC2AsyncClient (com.amazonaws.services.ec2.AmazonEC2AsyncClient)1 Address (com.amazonaws.services.ec2.model.Address)1 AttachInternetGatewayRequest (com.amazonaws.services.ec2.model.AttachInternetGatewayRequest)1 AttachNetworkInterfaceRequest (com.amazonaws.services.ec2.model.AttachNetworkInterfaceRequest)1 AttachNetworkInterfaceResult (com.amazonaws.services.ec2.model.AttachNetworkInterfaceResult)1 BlockDeviceMapping (com.amazonaws.services.ec2.model.BlockDeviceMapping)1