Exemplo n.º 1
0
def get_zones_in_region(compute_api: discovery.Resource, project_id: str,
                        region: str) -> Optional[List[str]]:
  '''get list of zones for given region

  Args:
  compute_api: compute_api instance
  project_id: project id
  region: region

  Returns:
  list of zone strings on success, None otherwise
  '''

  rsp = compute_api.regions().get(project=project_id, region=region).execute()

  return [urlparse(x).path.split('/')[-1] for x in rsp['zones']]
Exemplo n.º 2
0
def get_region_quotas(compute_api: discovery.Resource, project_id: str,
                      region: str) -> Optional[List[Dict[str, Any]]]:
  """gets compute quotas for given region

  These quotas include cpu and gpu quotas for the given region.
  (tpu quotas are not included here)

  Args:
  compute_api: compute_api instance
  project_id: project id
  region: region string

  Returns:
  list of quota dicts, with keys {'limit', 'metric', 'usage'}, None on error
  """

  return compute_api.regions().get(project=project_id,
                                   region=region).execute().get('quotas', [])