Example #1
0
  def Run(self, args):
    """This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      None
    """
    client = self.context['functions_client']
    messages = self.context['functions_messages']
    project = properties.VALUES.core.project.Get(required=True)
    name = 'projects/{0}/regions/{1}/functions/{2}'.format(
        project, args.region, args.name)

    prompt_message = 'Resource [{0}] will be deleted.'.format(name)
    if not console_io.PromptContinue(message=prompt_message):
      raise exceptions.FunctionsError('Deletion aborted by user.')
    try:
      # TODO(user): Use resources.py here after b/21908671 is fixed.
      op = client.projects_regions_functions.Delete(
          messages.CloudfunctionsProjectsRegionsFunctionsDeleteRequest(
              name=name))
      operations.Wait(op, messages, client)
      log.DeletedResource(name)
    except apitools_base.HttpError as error:
      raise base_exceptions.HttpException(util.GetError(error))
Example #2
0
 def _UpdateFunction(self, unused_location, function):
     client = self.context['functions_client']
     messages = self.context['functions_messages']
     try:
         # TODO(user): Use resources.py here after b/21908671 is fixed.
         op = client.projects_regions_functions.Update(function)
         operations.Wait(op, messages, client)
         return self._GetExistingFunction(function.name)
     except apitools_base.HttpError as error:
         raise base_exceptions.HttpException(util.GetError(error))
Example #3
0
 def _CreateFunction(self, location, function):
     client = self.context['functions_client']
     messages = self.context['functions_messages']
     try:
         # TODO(user): Use resources.py here after b/21908671 is fixed.
         op = client.projects_regions_functions.Create(
             messages.CloudfunctionsProjectsRegionsFunctionsCreateRequest(
                 location=location, hostedFunction=function))
         operations.Wait(op, messages, client)
         return self._GetExistingFunction(function.name)
     except apitools_base.HttpError as error:
         raise base_exceptions.HttpException(util.GetError(error))
Example #4
0
 def _GetExistingFunction(self, name):
     client = self.context['functions_client']
     messages = self.context['functions_messages']
     try:
         # TODO(user): Use resources.py here after b/21908671 is fixed.
         # We got response for a get request so a function exists.
         return client.projects_regions_functions.Get(
             messages.CloudfunctionsProjectsRegionsFunctionsGetRequest(
                 name=name))
     except apitools_base.HttpError as error:
         if error.status_code == httplib.NOT_FOUND:
             # The function has not been found.
             return None
         raise base_exceptions.HttpException(util.GetError(error))
Example #5
0
    def Run(self, args):
        """This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      The specified function with its description and configured filter.
    """
        client = self.context['functions_client']
        messages = self.context['functions_messages']
        project = properties.VALUES.core.project.Get(required=True)
        name = 'projects/{0}/regions/{1}/functions/{2}'.format(
            project, args.region, args.name)

        try:
            # TODO(user): Use resources.py here after b/21908671 is fixed.
            return client.projects_regions_functions.Get(
                messages.CloudfunctionsProjectsRegionsFunctionsGetRequest(
                    name=name))
        except apitools_base.HttpError as error:
            raise base_exceptions.HttpException(util.GetError(error))