use of com.google.api.services.compute.model.RegionList in project google-cloud-java by GoogleCloudPlatform.
the class HttpComputeRpc method listRegions.
@Override
public Tuple<String, Iterable<Region>> listRegions(Map<Option, ?> options) {
try {
RegionList regionsList = compute.regions().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<Region> regions = regionsList.getItems();
return Tuple.of(regionsList.getNextPageToken(), regions);
} catch (IOException ex) {
throw translate(ex);
}
}
use of com.google.api.services.compute.model.RegionList in project cloudbreak by hortonworks.
the class GcpPlatformResources method regions.
@Override
@Cacheable(cacheNames = "cloudResourceRegionCache", key = "#cloudCredential?.id")
public CloudRegions regions(CloudCredential cloudCredential, Region region, Map<String, String> filters) throws Exception {
Compute compute = GcpStackUtil.buildCompute(cloudCredential);
String projectId = GcpStackUtil.getProjectId(cloudCredential);
Map<Region, List<AvailabilityZone>> regionListMap = new HashMap<>();
Map<Region, String> displayNames = new HashMap<>();
String defaultRegion = gcpZoneParameterDefault;
RegionList regionList = compute.regions().list(projectId).execute();
for (com.google.api.services.compute.model.Region gcpRegion : regionList.getItems()) {
if (region == null || Strings.isNullOrEmpty(region.value()) || gcpRegion.getName().equals(region.value())) {
List<AvailabilityZone> availabilityZones = new ArrayList<>();
for (String s : gcpRegion.getZones()) {
String[] split = s.split("/");
if (split.length > 0) {
availabilityZones.add(AvailabilityZone.availabilityZone(split[split.length - 1]));
}
}
regionListMap.put(region(gcpRegion.getName()), availabilityZones);
displayNames.put(region(gcpRegion.getName()), displayName(gcpRegion.getName()));
}
}
if (region != null && !Strings.isNullOrEmpty(region.value())) {
defaultRegion = region.value();
}
return new CloudRegions(regionListMap, displayNames, defaultRegion);
}
Aggregations