use of software.amazon.awssdk.services.ec2.model.DescribeVpcsRequest in project cloudbreak by hortonworks.
the class AwsPlatformResources method networks.
@Override
public CloudNetworks networks(CloudCredential cloudCredential, Region region, Map<String, String> filters) {
Map<String, Set<CloudNetwork>> result = new HashMap<>();
Set<CloudNetwork> cloudNetworks = new HashSet<>();
AmazonEC2Client ec2Client = awsClient.createAccess(new AwsCredentialView(cloudCredential), region.value());
// create vpc filter view
PlatformResourceVpcFilterView filter = new PlatformResourceVpcFilterView(filters);
DescribeVpcsRequest describeVpcsRequest = new DescribeVpcsRequest();
// If the filtervalue is provided then we should filter only for those vpc
if (!Strings.isNullOrEmpty(filter.getVpcId())) {
describeVpcsRequest.withVpcIds(filter.getVpcId());
}
for (Vpc vpc : ec2Client.describeVpcs(describeVpcsRequest).getVpcs()) {
Map<String, String> subnetMap = new HashMap<>();
List<Subnet> subnets = ec2Client.describeSubnets(createVpcDescribeRequest(vpc)).getSubnets();
Map<String, Object> properties = new HashMap<>();
properties.put("cidrBlock", vpc.getCidrBlock());
properties.put("default", vpc.getIsDefault());
properties.put("dhcpOptionsId", vpc.getDhcpOptionsId());
properties.put("instanceTenancy", vpc.getInstanceTenancy());
properties.put("state", vpc.getState());
for (Subnet subnet : subnets) {
subnetMap.put(subnet.getSubnetId(), subnet.getSubnetId());
}
cloudNetworks.add(new CloudNetwork(vpc.getVpcId(), vpc.getVpcId(), subnetMap, properties));
}
result.put(region.value(), cloudNetworks);
return new CloudNetworks(result);
}
use of software.amazon.awssdk.services.ec2.model.DescribeVpcsRequest 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);
}
Aggregations