Search in sources :

Example 16 with DescribeSubnetsRequest

use of com.amazonaws.services.ec2.model.DescribeSubnetsRequest in project cloudbreak by hortonworks.

the class AwsResourceConnector method findNonOverLappingCIDR.

protected String findNonOverLappingCIDR(AuthenticatedContext ac, CloudStack stack) {
    AwsNetworkView awsNetworkView = new AwsNetworkView(stack.getNetwork());
    String region = ac.getCloudContext().getLocation().getRegion().value();
    AmazonEC2Client ec2Client = awsClient.createAccess(new AwsCredentialView(ac.getCloudCredential()), region);
    DescribeVpcsRequest vpcRequest = new DescribeVpcsRequest().withVpcIds(awsNetworkView.getExistingVPC());
    Vpc vpc = ec2Client.describeVpcs(vpcRequest).getVpcs().get(0);
    String vpcCidr = vpc.getCidrBlock();
    LOGGER.info("Subnet cidr is empty, find a non-overlapping subnet for VPC cidr: {}", vpcCidr);
    DescribeSubnetsRequest request = new DescribeSubnetsRequest().withFilters(new Filter("vpc-id", singletonList(awsNetworkView.getExistingVPC())));
    List<Subnet> awsSubnets = ec2Client.describeSubnets(request).getSubnets();
    List<String> subnetCidrs = awsSubnets.stream().map(Subnet::getCidrBlock).collect(Collectors.toList());
    LOGGER.info("The selected VPCs: {}, has the following subnets: {}", vpc.getVpcId(), subnetCidrs.stream().collect(Collectors.joining(",")));
    return calculateSubnet(ac.getCloudContext().getName(), vpc, subnetCidrs);
}
Also used : AmazonEC2Client(com.amazonaws.services.ec2.AmazonEC2Client) AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView) AwsNetworkView(com.sequenceiq.cloudbreak.cloud.aws.view.AwsNetworkView) DescribeVpcsRequest(com.amazonaws.services.ec2.model.DescribeVpcsRequest) Filter(com.amazonaws.services.ec2.model.Filter) Vpc(com.amazonaws.services.ec2.model.Vpc) Subnet(com.amazonaws.services.ec2.model.Subnet) 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