Search in sources :

Example 1 with NetworkList

use of com.google.api.services.compute.model.NetworkList in project google-cloud-java by GoogleCloudPlatform.

the class HttpComputeRpc method listNetworks.

@Override
public Tuple<String, Iterable<Network>> listNetworks(Map<Option, ?> options) {
    try {
        NetworkList networkList = compute.networks().list(this.options.getProjectId()).setFilter(Option.FILTER.getString(options)).setMaxResults(Option.MAX_RESULTS.getLong(options)).setPageToken(Option.PAGE_TOKEN.getString(options)).setFields(Option.FIELDS.getString(options)).execute();
        Iterable<Network> networks = networkList.getItems();
        return Tuple.of(networkList.getNextPageToken(), networks);
    } catch (IOException ex) {
        throw translate(ex);
    }
}
Also used : NetworkList(com.google.api.services.compute.model.NetworkList) Network(com.google.api.services.compute.model.Network) IOException(java.io.IOException)

Example 2 with NetworkList

use of com.google.api.services.compute.model.NetworkList 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

Network (com.google.api.services.compute.model.Network)2 NetworkList (com.google.api.services.compute.model.NetworkList)2 Compute (com.google.api.services.compute.Compute)1 Subnetwork (com.google.api.services.compute.model.Subnetwork)1 CloudNetwork (com.sequenceiq.cloudbreak.cloud.model.CloudNetwork)1 CloudNetworks (com.sequenceiq.cloudbreak.cloud.model.CloudNetworks)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1