コード例 #1
0
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.')
コード例 #2
0
 def Run(self, args):
     tasks_client = GetApiAdapter(self.ReleaseTrack()).tasks
     queue_ref = parsers.ParseQueue(args.queue, args.location)
     task_ref = parsers.ParseTask(args.task, queue_ref)
     return tasks_client.Get(
         task_ref,
         response_view=self.TASK_RESPONSE_VIEW_MAPPER.GetEnumForChoice(
             args.response_view))
コード例 #3
0
 def Run(self, args):
     tasks_client = GetApiAdapter(self.ReleaseTrack()).tasks
     queue_ref = parsers.ParseQueue(args.queue, args.location)
     duration = parsers.FormatLeaseDuration(args.lease_duration)
     filter_string = parsers.ParseTasksLeaseFilterFlags(args)
     return tasks_client.Lease(queue_ref,
                               duration,
                               filter_string=filter_string,
                               max_tasks=args.limit).tasks
コード例 #4
0
ファイル: purge.py プロジェクト: Akiho-Yasuda/wip
 def Run(self, args):
   queues_client = GetApiAdapter(self.ReleaseTrack()).queues
   queue_ref = parsers.ParseQueue(args.queue, args.location)
   console_io.PromptContinue(
       cancel_on_no=True,
       prompt_string='Are you sure you want to purge: [{}]'.format(
           queue_ref.RelativeName()))
   queues_client.Purge(queue_ref)
   log.status.Print('Purged queue [{}].'.format(queue_ref.Name()))
コード例 #5
0
 def Run(self, args):
     queues_client = GetApiAdapter(self.ReleaseTrack()).queues
     queue_ref = parsers.ParseQueue(args.queue, args.location)
     policy = queues_client.GetIamPolicy(queue_ref)
     iam_util.RemoveBindingFromIamPolicy(policy, args.member, args.role)
     response = queues_client.SetIamPolicy(queue_ref, policy)
     log.status.Print('Updated IAM policy for queue [{}].'.format(
         queue_ref.Name()))
     return response
コード例 #6
0
 def Run(self, args):
     queues_client = GetApiAdapter(self.ReleaseTrack()).queues
     queue_ref = parsers.ParseQueue(args.queue, args.location)
     log.warning(constants.QUEUE_MANAGEMENT_WARNING)
     console_io.PromptContinue(
         cancel_on_no=True,
         prompt_string='Are you sure you want to delete: [{}]'.format(
             queue_ref.RelativeName()))
     queues_client.Delete(queue_ref)
     log.DeletedResource(queue_ref.Name(), 'queue')
コード例 #7
0
 def Run(self, args):
   queues_client = GetApiAdapter(self.ReleaseTrack()).queues
   queue_ref = parsers.ParseQueue(args.queue, args.location)
   queue_short = parsers.GetConsolePromptString(queue_ref.RelativeName())
   console_io.PromptContinue(
       cancel_on_no=True,
       prompt_string=(
           'Deleted queues can not be re-created for a duration of up to 7 '
           'days. Are you sure you want to delete: [{}]'.format(queue_short)))
   queues_client.Delete(queue_ref)
   log.DeletedResource(queue_short, 'queue')
コード例 #8
0
ファイル: app.py プロジェクト: piotradamczyk5/gcloud_cli
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
コード例 #9
0
 def Run(self, args):
     api = GetApiAdapter(self.ReleaseTrack())
     queues_client = api.queues
     queue_ref = parsers.ParseQueue(args.queue, args.location)
     location_ref = parsers.ExtractLocationRefFromQueueRef(queue_ref)
     queue_config = parsers.ParseCreateOrUpdateQueueArgs(
         args,
         constants.PULL_QUEUE,
         api.messages,
         release_track=self.ReleaseTrack())
     log.warning(constants.QUEUE_MANAGEMENT_WARNING)
     if self.ReleaseTrack() == base.ReleaseTrack.ALPHA:
         create_response = queues_client.Create(
             location_ref,
             queue_ref,
             retry_config=queue_config.retryConfig,
             rate_limits=queue_config.rateLimits,
             pull_target=queue_config.pullTarget)
     else:
         create_response = queues_client.Create(
             location_ref,
             queue_ref,
             retry_config=queue_config.retryConfig,
             rate_limits=queue_config.rateLimits,
             queue_type=queue_config.type)
     log.CreatedResource(queue_ref.Name(), 'queue')
     return create_response
コード例 #10
0
 def Run(self, args):
     api = GetApiAdapter(self.ReleaseTrack())
     queues_client = api.queues
     queue_ref = parsers.ParseQueue(args.queue, args.location)
     location_ref = parsers.ExtractLocationRefFromQueueRef(queue_ref)
     queue_config = parsers.ParseCreateOrUpdateQueueArgs(
         args,
         constants.PUSH_QUEUE,
         api.messages,
         release_track=self.ReleaseTrack())
     if not self.is_alpha:
         create_response = queues_client.Create(
             location_ref,
             queue_ref,
             retry_config=queue_config.retryConfig,
             rate_limits=queue_config.rateLimits,
             app_engine_http_queue=queue_config.appEngineHttpQueue,
             stackdriver_logging_config=queue_config.
             stackdriverLoggingConfig)
     else:
         create_response = queues_client.Create(
             location_ref,
             queue_ref,
             retry_config=queue_config.retryConfig,
             rate_limits=queue_config.rateLimits,
             app_engine_http_target=queue_config.appEngineHttpTarget)
     log.CreatedResource(
         parsers.GetConsolePromptString(queue_ref.RelativeName()), 'queue')
     return create_response
コード例 #11
0
ファイル: update.py プロジェクト: Akiho-Yasuda/wip
 def Run(self, args):
     parsers.CheckUpdateArgsSpecified(args, constants.PUSH_QUEUE,
                                      self.is_alpha)
     api = GetApiAdapter(self.ReleaseTrack())
     queues_client = api.queues
     queue_ref = parsers.ParseQueue(args.queue, args.location)
     queue_config = parsers.ParseCreateOrUpdateQueueArgs(
         args,
         constants.PUSH_QUEUE,
         api.messages,
         is_update=True,
         is_alpha=self.is_alpha)
     if not self.is_alpha:
         app_engine_routing_override = (
             queue_config.appEngineHttpQueue.appEngineRoutingOverride
             if queue_config.appEngineHttpQueue is not None else None)
     else:
         app_engine_routing_override = (
             queue_config.appEngineHttpTarget.appEngineRoutingOverride
             if queue_config.appEngineHttpTarget is not None else None)
     log.warning(constants.QUEUE_MANAGEMENT_WARNING)
     update_response = queues_client.Patch(
         queue_ref,
         retry_config=queue_config.retryConfig,
         rate_limits=queue_config.rateLimits,
         app_engine_routing_override=app_engine_routing_override)
     log.status.Print('Updated queue [{}].'.format(queue_ref.Name()))
     return update_response
コード例 #12
0
ファイル: update.py プロジェクト: piotradamczyk5/gcloud_cli
 def Run(self, args):
     if self.ReleaseTrack() == base.ReleaseTrack.BETA:
         queue_type = args.type
     else:
         queue_type = constants.PUSH_QUEUE
     parsers.CheckUpdateArgsSpecified(args,
                                      queue_type,
                                      release_track=self.ReleaseTrack())
     api = GetApiAdapter(self.ReleaseTrack())
     queues_client = api.queues
     queue_ref = parsers.ParseQueue(args.queue, args.location)
     queue_config = parsers.ParseCreateOrUpdateQueueArgs(
         args,
         queue_type,
         api.messages,
         is_update=True,
         release_track=self.ReleaseTrack())
     updated_fields = parsers.GetSpecifiedFieldsMask(
         args, queue_type, release_track=self.ReleaseTrack())
     log.warning(constants.QUEUE_MANAGEMENT_WARNING)
     if self.ReleaseTrack() == base.ReleaseTrack.ALPHA:
         app_engine_routing_override = (
             queue_config.appEngineHttpTarget.appEngineRoutingOverride
             if queue_config.appEngineHttpTarget is not None else None)
         update_response = queues_client.Patch(
             queue_ref,
             updated_fields,
             retry_config=queue_config.retryConfig,
             rate_limits=queue_config.rateLimits,
             app_engine_routing_override=app_engine_routing_override)
     elif self.ReleaseTrack() == base.ReleaseTrack.BETA:
         app_engine_routing_override = (
             queue_config.appEngineHttpQueue.appEngineRoutingOverride
             if queue_config.appEngineHttpQueue is not None else None)
         update_response = queues_client.Patch(
             queue_ref,
             updated_fields,
             retry_config=queue_config.retryConfig,
             rate_limits=queue_config.rateLimits,
             app_engine_routing_override=app_engine_routing_override,
             stackdriver_logging_config=queue_config.
             stackdriverLoggingConfig,
             queue_type=queue_config.type)
     else:
         app_engine_routing_override = queue_config.appEngineRoutingOverride
         update_response = queues_client.Patch(
             queue_ref,
             updated_fields,
             retry_config=queue_config.retryConfig,
             rate_limits=queue_config.rateLimits,
             app_engine_routing_override=app_engine_routing_override,
             stackdriver_logging_config=queue_config.
             stackdriverLoggingConfig)
     log.status.Print('Updated queue [{}].'.format(queue_ref.Name()))
     return update_response
コード例 #13
0
 def Run(self, args):
     api = GetApiAdapter(self.ReleaseTrack())
     queues_client = api.queues
     queues_messages = api.messages
     queue_ref = parsers.ParseQueue(args.queue, args.location)
     try:
         policy = queues_client.GetIamPolicy(queue_ref)
     except apitools_exceptions.HttpNotFoundError:
         # If the error is a 404, no IAM policy exists, so just create a blank one.
         policy = queues_messages.Policy()
     iam_util.AddBindingToIamPolicy(queues_messages.Binding, policy,
                                    args.member, args.role)
     response = queues_client.SetIamPolicy(queue_ref, policy)
     return response
コード例 #14
0
 def Run(self, args):
   api = GetApiAdapter(self.ReleaseTrack())
   tasks_client = api.tasks
   queue_ref = parsers.ParseQueue(args.queue, args.location)
   task_ref = parsers.ParseTask(args.task,
                                queue_ref) if args.task else None
   task_config = parsers.ParseCreateTaskArgs(
       args, constants.PULL_QUEUE, api.messages, is_alpha=True)
   create_response = tasks_client.Create(
       queue_ref, task_ref,
       schedule_time=task_config.scheduleTime,
       pull_message=task_config.pullMessage)
   log.CreatedResource(create_response.name, 'task')
   return create_response
コード例 #15
0
 def Run(self, args):
     api = GetApiAdapter(self.ReleaseTrack())
     tasks_client = api.tasks
     queue_ref = parsers.ParseQueue(args.queue, args.location)
     task_ref = parsers.ParseTask(args.task,
                                  queue_ref) if args.task else None
     task_config = parsers.ParseCreateTaskArgs(args, constants.PUSH_QUEUE,
                                               api.messages)
     create_response = tasks_client.Create(
         queue_ref,
         task_ref,
         schedule_time=task_config.scheduleTime,
         app_engine_http_request=task_config.appEngineHttpRequest)
     log.CreatedResource(create_response.name, 'task')
     return create_response
コード例 #16
0
 def Run(self, args):
     api = GetApiAdapter(self.ReleaseTrack())
     queues_client = api.queues
     queue_ref = parsers.ParseQueue(args.queue, args.location)
     location_ref = parsers.ExtractLocationRefFromQueueRef(queue_ref)
     queue_config = parsers.ParseCreateOrUpdateQueueArgs(
         args, constants.APP_ENGINE_QUEUE, api.messages, is_alpha=True)
     log.warning(constants.QUEUE_MANAGEMENT_WARNING)
     create_response = queues_client.Create(
         location_ref,
         queue_ref,
         retry_config=queue_config.retryConfig,
         rate_limits=queue_config.rateLimits,
         app_engine_http_target=queue_config.appEngineHttpTarget)
     log.CreatedResource(queue_ref.Name(), 'queue')
     return create_response
コード例 #17
0
 def Run(self, args):
     parsers.CheckUpdateArgsSpecified(args,
                                      constants.PULL_QUEUE,
                                      release_track=self.ReleaseTrack())
     api = GetApiAdapter(self.ReleaseTrack())
     queues_client = api.queues
     queue_ref = parsers.ParseQueue(args.queue, args.location)
     queue_config = parsers.ParseCreateOrUpdateQueueArgs(
         args,
         constants.PULL_QUEUE,
         api.messages,
         is_update=True,
         release_track=base.ReleaseTrack.ALPHA)
     log.warning(constants.QUEUE_MANAGEMENT_WARNING)
     update_response = queues_client.Patch(
         queue_ref, retry_config=queue_config.retryConfig)
     log.status.Print('Updated queue [{}].'.format(queue_ref.Name()))
     return update_response
コード例 #18
0
 def Run(self, args):
   parsers.CheckUpdateArgsSpecified(args, constants.PULL_QUEUE,
                                    release_track=self.ReleaseTrack())
   api = GetApiAdapter(self.ReleaseTrack())
   queues_client = api.queues
   queue_ref = parsers.ParseQueue(args.queue, args.location)
   queue_config = parsers.ParseCreateOrUpdateQueueArgs(
       args,
       constants.PULL_QUEUE,
       api.messages,
       is_update=True,
       release_track=self.ReleaseTrack())
   updated_fields = parsers.GetSpecifiedFieldsMask(
       args, constants.PULL_QUEUE, release_track=self.ReleaseTrack())
   update_response = queues_client.Patch(
       queue_ref, updated_fields, retry_config=queue_config.retryConfig)
   log.status.Print('Updated queue [{}].'.format(
       parsers.GetConsolePromptString(queue_ref.RelativeName())))
   return update_response
コード例 #19
0
 def Run(self, args):
     if self.ReleaseTrack() == base.ReleaseTrack.BETA:
         queue_type = args.type
     else:
         queue_type = constants.PUSH_QUEUE
     api = GetApiAdapter(self.ReleaseTrack())
     queues_client = api.queues
     queue_ref = parsers.ParseQueue(args.queue, args.location)
     location_ref = parsers.ExtractLocationRefFromQueueRef(queue_ref)
     queue_config = parsers.ParseCreateOrUpdateQueueArgs(
         args, queue_type, api.messages, release_track=self.ReleaseTrack())
     if self.ReleaseTrack() == base.ReleaseTrack.ALPHA:
         create_response = queues_client.Create(
             location_ref,
             queue_ref,
             retry_config=queue_config.retryConfig,
             rate_limits=queue_config.rateLimits,
             app_engine_http_target=queue_config.appEngineHttpTarget)
     elif self.ReleaseTrack() == base.ReleaseTrack.BETA:
         create_response = queues_client.Create(
             location_ref,
             queue_ref,
             retry_config=queue_config.retryConfig,
             rate_limits=queue_config.rateLimits,
             app_engine_http_queue=queue_config.appEngineHttpQueue,
             stackdriver_logging_config=queue_config.
             stackdriverLoggingConfig,
             queue_type=queue_config.type)
     else:
         create_response = queues_client.Create(
             location_ref,
             queue_ref,
             retry_config=queue_config.retryConfig,
             rate_limits=queue_config.rateLimits,
             app_engine_routing_override=queue_config.
             appEngineRoutingOverride,
             stackdriver_logging_config=queue_config.
             stackdriverLoggingConfig)
     log.CreatedResource(
         parsers.GetConsolePromptString(queue_ref.RelativeName()), 'queue')
     return create_response
コード例 #20
0
  def Run(self, args):
    if self.ReleaseTrack() == base.ReleaseTrack.ALPHA:
      # This functionality doesn't exist in the alpha API so use beta.
      api_release_track = base.ReleaseTrack.BETA
    else:
      api_release_track = self.ReleaseTrack()

    api = GetApiAdapter(api_release_track)
    tasks_client = api.tasks
    queue_ref = parsers.ParseQueue(args.queue, args.location)
    task_ref = parsers.ParseTask(args.task,
                                 queue_ref) if args.task else None
    task_config = parsers.ParseCreateTaskArgs(
        args, constants.HTTP_TASK, api.messages,
        release_track=api_release_track)
    create_response = tasks_client.Create(
        queue_ref, task_ref,
        schedule_time=task_config.scheduleTime,
        http_request=task_config.httpRequest)
    log.CreatedResource(create_response.name, 'task')
    return create_response
 def Run(self, args):
     parsers.CheckUpdateArgsSpecified(args,
                                      constants.PUSH_QUEUE,
                                      release_track=self.ReleaseTrack())
     api = GetApiAdapter(self.ReleaseTrack())
     queues_client = api.queues
     queue_ref = parsers.ParseQueue(args.queue, args.location)
     queue_config = parsers.ParseCreateOrUpdateQueueArgs(
         args,
         constants.PUSH_QUEUE,
         api.messages,
         is_update=True,
         release_track=self.ReleaseTrack())
     updated_fields = parsers.GetSpecifiedFieldsMask(
         args, constants.PUSH_QUEUE, release_track=self.ReleaseTrack())
     if not self.is_alpha:
         app_engine_routing_override = (
             queue_config.appEngineHttpQueue.appEngineRoutingOverride
             if queue_config.appEngineHttpQueue is not None else None)
         update_response = queues_client.Patch(
             queue_ref,
             updated_fields,
             retry_config=queue_config.retryConfig,
             rate_limits=queue_config.rateLimits,
             app_engine_routing_override=app_engine_routing_override,
             stackdriver_logging_config=queue_config.
             stackdriverLoggingConfig)
     else:
         app_engine_routing_override = (
             queue_config.appEngineHttpTarget.appEngineRoutingOverride
             if queue_config.appEngineHttpTarget is not None else None)
         update_response = queues_client.Patch(
             queue_ref,
             updated_fields,
             retry_config=queue_config.retryConfig,
             rate_limits=queue_config.rateLimits,
             app_engine_routing_override=app_engine_routing_override)
     log.status.Print('Updated queue [{}].'.format(
         parsers.GetConsolePromptString(queue_ref.RelativeName())))
     return update_response
コード例 #22
0
 def Run(self, args):
     api = GetApiAdapter(self.ReleaseTrack())
     queues_client = api.queues
     queue_ref = parsers.ParseQueue(args.queue, args.location)
     location_ref = parsers.ExtractLocationRefFromQueueRef(queue_ref)
     queue_config = parsers.ParseCreateOrUpdateQueueArgs(
         args,
         constants.PUSH_QUEUE,
         api.messages,
         release_track=self.ReleaseTrack())
     log.warning(constants.QUEUE_MANAGEMENT_WARNING)
     if self.ReleaseTrack() == base.ReleaseTrack.ALPHA:
         create_response = queues_client.Create(
             location_ref,
             queue_ref,
             retry_config=queue_config.retryConfig,
             rate_limits=queue_config.rateLimits,
             app_engine_http_target=queue_config.appEngineHttpTarget)
     elif self.ReleaseTrack() == base.ReleaseTrack.BETA:
         create_response = queues_client.Create(
             location_ref,
             queue_ref,
             retry_config=queue_config.retryConfig,
             rate_limits=queue_config.rateLimits,
             app_engine_http_queue=queue_config.appEngineHttpQueue,
             stackdriver_logging_config=queue_config.
             stackdriverLoggingConfig)
     else:
         create_response = queues_client.Create(
             location_ref,
             queue_ref,
             retry_config=queue_config.retryConfig,
             rate_limits=queue_config.rateLimits,
             app_engine_routing_override=queue_config.
             appEngineRoutingOverride)
     log.CreatedResource(queue_ref.Name(), 'queue')
     return create_response
コード例 #23
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)
コード例 #24
0
ファイル: pause.py プロジェクト: Guliux10/bchacks_deepbreath
 def Run(self, args):
   queues_client = GetApiAdapter(self.ReleaseTrack()).queues
   queue_ref = parsers.ParseQueue(args.queue, args.location)
   log.warning(constants.QUEUE_MANAGEMENT_WARNING)
   queues_client.Pause(queue_ref)
   log.status.Print('Paused queue [{}].'.format(queue_ref.Name()))
コード例 #25
0
 def Run(self, args):
     tasks_client = GetApiAdapter(self.ReleaseTrack()).tasks
     queue_ref = parsers.ParseQueue(args.queue, args.location)
     task_ref = parsers.ParseTask(args.task, queue_ref)
     return tasks_client.CancelLease(task_ref, args.schedule_time)
コード例 #26
0
ファイル: describe.py プロジェクト: Akiho-Yasuda/wip
 def Run(self, args):
     queues_client = GetApiAdapter(self.ReleaseTrack()).queues
     queue_ref = parsers.ParseQueue(args.queue, args.location)
     return queues_client.Get(queue_ref)
コード例 #27
0
 def Run(self, args):
   queues_client = GetApiAdapter(self.ReleaseTrack()).queues
   queue_ref = parsers.ParseQueue(args.queue, args.location)
   queues_client.Resume(queue_ref)
   log.status.Print('Resumed queue [{}].'.format(
       parsers.GetConsolePromptString(queue_ref.RelativeName())))
コード例 #28
0
ファイル: list.py プロジェクト: Guliux10/bchacks_deepbreath
 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)
コード例 #29
0
ファイル: list.py プロジェクト: Guliux10/bchacks_deepbreath
 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)
コード例 #30
0
ファイル: delete.py プロジェクト: Akiho-Yasuda/wip
 def Run(self, args):
     tasks_client = GetApiAdapter(self.ReleaseTrack()).tasks
     queue_ref = parsers.ParseQueue(args.queue, args.location)
     task_ref = parsers.ParseTask(args.task, queue_ref)
     tasks_client.Delete(task_ref)
     log.DeletedResource(task_ref.Name(), kind='task')