def ResolveAppLocation(project_ref, locations_client=None):
    """Gets the default location from the Cloud Tasks API.

  If an AppEngine app exists, the default location is the location where the
  app exists.

  Args:
    project_ref: The project resource to look up the location for.
    locations_client: The project resource used to look up locations.

  Returns:
    The location. Some examples: 'us-central1', 'us-east4'

  Raises:
    RegionResolvingError: If we are unable to determine a default location
      for the given project.
  """
    if not locations_client:
        locations_client = GetApiAdapter(
            calliope_base.ReleaseTrack.GA).locations
    locations = list(locations_client.List(project_ref))
    if len(locations) >= 1 and AppEngineAppExists():
        location = locations[0].labels.additionalProperties[0].value
        if len(locations) > 1:
            log.warning(
                constants.APP_ENGINE_DEFAULT_LOCATION_WARNING.format(location))
        return location
    raise RegionResolvingError(
        'Please use the location flag to manually specify a location.')
Ejemplo n.º 2
0
def _GetLocation(project_ref):
  """Gets the location from the Cloud Tasks API."""
  try:
    locations_client = GetApiAdapter(calliope_base.ReleaseTrack.GA).locations
    locations = list(locations_client.List(project_ref, page_size=2))
    if len(locations) > 1:
      # Projects currently can only use Cloud Tasks in single region, so this
      # should never happen for now, but that will change in the future.
      raise RegionResolvingError('Multiple locations found for this project. '
                                 'Please specify an exact location.')
    if len(locations) == 1:
      return locations[0].labels.additionalProperties[0].value
    return None
  except apitools_exceptions.HttpNotFoundError:
    return None
Ejemplo n.º 3
0
 def Run(self, args):
     queues_client = GetApiAdapter(self.ReleaseTrack()).queues
     app_location = args.location or app.ResolveAppLocation()
     region_ref = parsers.ParseLocation(app_location)
     return queues_client.List(region_ref, args.limit, args.page_size)
Ejemplo n.º 4
0
 def Run(self, args):
     tasks_client = GetApiAdapter(self.ReleaseTrack()).tasks
     queue_ref = parsers.ParseQueue(args.queue, args.location)
     return tasks_client.List(queue_ref, args.limit, args.page_size)
Ejemplo n.º 5
0
 def Run(self, args):
     locations_client = GetApiAdapter(self.ReleaseTrack()).locations
     project_ref = parsers.ParseProject()
     return locations_client.List(project_ref, args.limit, args.page_size)