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);
}
}
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);
}
Aggregations