Search in sources :

Example 1 with PlatformResourceVpcFilterView

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);
}
Also used : AmazonEC2Client(com.amazonaws.services.ec2.AmazonEC2Client) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) PlatformResourceVpcFilterView(com.sequenceiq.cloudbreak.cloud.model.view.PlatformResourceVpcFilterView) Vpc(com.amazonaws.services.ec2.model.Vpc) CloudNetworks(com.sequenceiq.cloudbreak.cloud.model.CloudNetworks) AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView) DescribeVpcsRequest(com.amazonaws.services.ec2.model.DescribeVpcsRequest) Subnet(com.amazonaws.services.ec2.model.Subnet) CloudNetwork(com.sequenceiq.cloudbreak.cloud.model.CloudNetwork) HashSet(java.util.HashSet)

Aggregations

AmazonEC2Client (com.amazonaws.services.ec2.AmazonEC2Client)1 DescribeVpcsRequest (com.amazonaws.services.ec2.model.DescribeVpcsRequest)1 Subnet (com.amazonaws.services.ec2.model.Subnet)1 Vpc (com.amazonaws.services.ec2.model.Vpc)1 AwsCredentialView (com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView)1 CloudNetwork (com.sequenceiq.cloudbreak.cloud.model.CloudNetwork)1 CloudNetworks (com.sequenceiq.cloudbreak.cloud.model.CloudNetworks)1 PlatformResourceVpcFilterView (com.sequenceiq.cloudbreak.cloud.model.view.PlatformResourceVpcFilterView)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1