Ejemplo n.º 1
0
  def _ApplyArgsToFunction(
      self, base_function, is_new_function, trigger_params, name, args):
    """Apply values from args to base_function.

    Args:
        base_function: function message to modify
        is_new_function: bool, indicates if this is a new function (and source
                         code for it must be deployed) or an existing function
                         (so it may keep its old source code).
        trigger_params: parameters for creating functions trigger.
        name: relative name of the function.
        args: commandline args specyfying how to modify the function.
    """
    if args.IsSpecified('retry'):
      retry = args.retry
    else:
      retry = None
    self._ApplyNonSourceArgsToFunction(
        base_function, name, args.entry_point, args.timeout,
        args.trigger_http, trigger_params, retry, args.memory)
    if args.source:
      deploy_util.AddSourceToFunction(
          base_function, args.source, args.include_ignored_files, args.name,
          args.stage_bucket)
    elif args.source_url:
      messages = util.GetApiMessagesModule()
      source_path = args.source_path
      source_branch = args.source_branch or 'master'
      base_function.sourceRepository = messages.SourceRepository(
          tag=args.source_tag, branch=source_branch,
          revision=args.source_revision, repositoryUrl=args.source_url,
          sourcePath=source_path)
    elif is_new_function or args.local_path or args.stage_bucket:
      # Do not change source of existing function unless instructed to.
      base_function.sourceArchiveUrl = self._PrepareSourcesOnGcs(args)
Ejemplo n.º 2
0
 def _DeployFunction(self, name, location, args, deploy_method,
                     trigger_params):
     function = self._PrepareFunctionWithoutSources(name, args.entry_point,
                                                    args.timeout,
                                                    args.trigger_http,
                                                    trigger_params)
     if args.source:
         deploy_util.AddSourceToFunction(function, args.source,
                                         args.include_ignored_files,
                                         args.name, args.stage_bucket)
     elif args.source_url:
         messages = util.GetApiMessagesModule()
         source_path = args.source_path
         source_branch = args.source_branch or 'master'
         function.sourceRepository = messages.SourceRepository(
             tag=args.source_tag,
             branch=source_branch,
             revision=args.source_revision,
             repositoryUrl=args.source_url,
             sourcePath=source_path)
     else:
         function.sourceArchiveUrl = self._PrepareSourcesOnGcs(args)
     memory_mb = utils.BytesToMb(args.memory)
     if memory_mb:
         function.availableMemoryMb = memory_mb
     return deploy_method(location, function)
Ejemplo n.º 3
0
    def _ApplyArgsToFunction(self, base_function, is_new_function,
                             trigger_params, name, args, project):
        """Apply values from args to base_function.

    Args:
        base_function: function message to modify
        is_new_function: bool, indicates if this is a new function (and source
                         code for it must be deployed) or an existing function
                         (so it may keep its old source code).
        trigger_params: parameters for creating functions trigger.
        name: relative name of the function.
        args: commandline args specyfying how to modify the function.
        project: project of the function.
    """
        if args.IsSpecified('retry'):
            retry = args.retry
        else:
            retry = None
        self._ApplyNonSourceArgsToFunction(base_function, name,
                                           args.entry_point, args.timeout,
                                           args.trigger_http, trigger_params,
                                           retry, args.memory)
        messages = util.GetApiMessagesModule()
        if args.source:
            deploy_util.AddSourceToFunction(base_function, args.source,
                                            args.include_ignored_files,
                                            args.name, args.stage_bucket,
                                            messages)
        elif args.source_url:
            deploy_util.CleanOldSourceInfo(base_function)
            source_path = args.source_path
            source_branch = args.source_branch or 'master'
            base_function.sourceRepository = messages.SourceRepository(
                url=self._GetSourceUrlFromArgs(project,
                                               tag=args.source_tag,
                                               branch=source_branch,
                                               revision=args.source_revision,
                                               source_url=args.source_url,
                                               source_path=source_path))

        elif args.stage_bucket:
            # Do not change source of existing function unless instructed to.
            deploy_util.CleanOldSourceInfo(base_function)
            base_function.sourceArchiveUrl = self._PrepareSourcesOnGcs(args)
        elif is_new_function or args.local_path:
            raise exceptions.FunctionsError(
                'argument --stage-bucket: required when the function is deployed '
                'from a local directory.')
        # Set information about deplouyment tool.
        labels_to_update = args.update_labels or {}
        labels_to_update['deployment-tool'] = 'cli-gcloud'
        updated_labels = labels_util.UpdateLabels(
            base_function.labels,
            messages.CloudFunction.LabelsValue,
            update_labels=labels_to_update,
            remove_labels=args.remove_labels)
        if updated_labels is not None:
            base_function.labels = updated_labels
Ejemplo n.º 4
0
    def _ApplyArgsToFunction(self, function, is_new_function, trigger_params,
                             function_ref, args, project):
        """Apply values from args to base_function.

    Args:
        function: function message to modify
        is_new_function: bool, indicates if this is a new function (and source
                         code for it must be deployed) or an existing function
                         (so it may keep its old source code).
        trigger_params: parameters for creating functions trigger.
        function_ref: reference to function.
        args: commandline args specyfying how to modify the function.
        project: project of the function.
    Returns:
      Pair of function and update mask.
    """
        update_mask = []

        messages = util.GetApiMessagesModule()
        client = util.GetApiClientInstance()

        self._ApplyNonSourceArgsToFunction(function, function_ref, update_mask,
                                           messages, args, trigger_params)
        # Only Add source to function if its explicitly provided, a new function,
        # using a stage budget or deploy of an existing function that previously
        # used local source
        if (args.source or args.stage_bucket or is_new_function
                or function.sourceUploadUrl):  #
            deploy_util.AddSourceToFunction(
                function, function_ref, update_mask, args.source,
                args.stage_bucket, messages,
                client.projects_locations_functions)
        # Set information about deployment tool.
        labels_to_update = args.update_labels or {}
        labels_to_update['deployment-tool'] = 'cli-gcloud'
        labels_diff = labels_util.Diff(additions=labels_to_update,
                                       subtractions=args.remove_labels,
                                       clear=args.clear_labels)
        labels_update = labels_diff.Apply(messages.CloudFunction.LabelsValue,
                                          function.labels)
        if labels_update.needs_update:
            function.labels = labels_update.labels
            update_mask.append('labels')
        return function, ','.join(sorted(update_mask))