Search in sources :

Example 6 with Subnetwork

use of com.google.api.services.compute.model.Subnetwork in project cloudbreak by hortonworks.

the class GcpPlatformResources method networks.

@Override
public CloudNetworks networks(CloudCredential cloudCredential, Region region, Map<String, String> filters) throws Exception {
    Compute compute = GcpStackUtil.buildCompute(cloudCredential);
    String projectId = GcpStackUtil.getProjectId(cloudCredential);
    Map<String, Set<CloudNetwork>> result = new HashMap<>();
    Set<CloudNetwork> cloudNetworks = new HashSet<>();
    if (compute != null) {
        NetworkList networkList = compute.networks().list(projectId).execute();
        List<Subnetwork> subnetworkList = compute.subnetworks().list(projectId, region.value()).execute().getItems();
        for (Network network : networkList.getItems()) {
            Map<String, Object> properties = new HashMap<>();
            properties.put("gatewayIPv4", Strings.nullToEmpty(network.getGatewayIPv4()));
            properties.put("description", Strings.nullToEmpty(network.getDescription()));
            properties.put("IPv4Range", Strings.nullToEmpty(network.getIPv4Range()));
            properties.put("creationTimestamp", Strings.nullToEmpty(network.getCreationTimestamp()));
            Map<String, String> subnets = new HashMap<>();
            if (subnetworkList != null && network.getSubnetworks() != null) {
                for (Subnetwork subnetwork : subnetworkList) {
                    if (network.getSubnetworks().contains(subnetwork.getSelfLink())) {
                        subnets.put(subnetwork.getName(), subnetwork.getName());
                    }
                }
            }
            CloudNetwork cloudNetwork = new CloudNetwork(network.getName(), network.getId().toString(), subnets, properties);
            cloudNetworks.add(cloudNetwork);
        }
        result.put(region.value(), cloudNetworks);
    }
    return new CloudNetworks(result);
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) Subnetwork(com.google.api.services.compute.model.Subnetwork) HashMap(java.util.HashMap) CloudNetworks(com.sequenceiq.cloudbreak.cloud.model.CloudNetworks) NetworkList(com.google.api.services.compute.model.NetworkList) Compute(com.google.api.services.compute.Compute) Network(com.google.api.services.compute.model.Network) CloudNetwork(com.sequenceiq.cloudbreak.cloud.model.CloudNetwork) CloudNetwork(com.sequenceiq.cloudbreak.cloud.model.CloudNetwork) HashSet(java.util.HashSet)

Aggregations

Subnetwork (com.google.api.services.compute.model.Subnetwork)6 Compute (com.google.api.services.compute.Compute)3 Insert (com.google.api.services.compute.Compute.Subnetworks.Insert)2 Network (com.google.api.services.compute.model.Network)2 Operation (com.google.api.services.compute.model.Operation)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 GoogleCredential (com.google.api.client.googleapis.auth.oauth2.GoogleCredential)1 GoogleNetHttpTransport (com.google.api.client.googleapis.javanet.GoogleNetHttpTransport)1 GoogleJsonResponseException (com.google.api.client.googleapis.json.GoogleJsonResponseException)1 HttpTransport (com.google.api.client.http.HttpTransport)1 JacksonFactory (com.google.api.client.json.jackson2.JacksonFactory)1 Builder (com.google.api.services.compute.Compute.Builder)1 Networks (com.google.api.services.compute.Compute.Networks)1 NetworkList (com.google.api.services.compute.model.NetworkList)1 SubnetworkAggregatedList (com.google.api.services.compute.model.SubnetworkAggregatedList)1 SubnetworkList (com.google.api.services.compute.model.SubnetworkList)1 SubnetworksScopedList (com.google.api.services.compute.model.SubnetworksScopedList)1 ImmutableList (com.google.common.collect.ImmutableList)1 NetworkRequest (com.sequenceiq.cloudbreak.api.model.NetworkRequest)1