use of com.sequenceiq.cloudbreak.cloud.model.view.PlatformResourceVpcFilterView 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);
}
Aggregations