コード例 #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:
      The created sink with its destination.
    """
    util.CheckSinksCommandArguments(args)

    if not (args.log or args.service or args.log_filter):
      # Attempt to create a project sink with an empty filter.
      if not console_io.PromptContinue(
          'Sink with empty filter matches all entries in the project.'):
        raise exceptions.ToolException('action canceled by user')

    sink_ref = self.context['sink_reference']
    sink_data = {'name': sink_ref.sinksId, 'destination': args.destination,
                 'filter': args.log_filter}

    if args.log:
      result = util.TypedLogSink(self.CreateLogSink(sink_data),
                                 log_name=args.log)
    elif args.service:
      result = util.TypedLogSink(self.CreateLogServiceSink(sink_data),
                                 service_name=args.service)
    else:
      sink_data['outputVersionFormat'] = args.output_version_format
      result = util.TypedLogSink(self.CreateProjectSink(sink_data))
    log.CreatedResource(sink_ref)
    return result
コード例 #2
0
ファイル: create.py プロジェクト: mzha/HomewardBound
  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 created sink with its destination.
    """
    util.CheckSinksCommandArguments(args)

    if not args.unique_writer_identity:
      log.warn(
          '--unique-writer-identity is deprecated and will soon be removed.')

    if not (args.log or args.service or args.log_filter):
      # Attempt to create a sink with an empty filter.
      console_io.PromptContinue(
          'Sink with empty filter matches all entries.', cancel_on_no=True)

    sink_ref = self.context['sink_reference']
    sink_data = {'name': sink_ref.sinksId, 'destination': args.destination,
                 'filter': args.log_filter}

    if args.log:
      result = util.TypedLogSink(self.CreateLogSink(sink_data),
                                 log_name=args.log)
    elif args.service:
      result = util.TypedLogSink(self.CreateLogServiceSink(sink_data),
                                 service_name=args.service)
    else:
      sink_data['outputVersionFormat'] = args.output_version_format
      result = util.TypedLogSink(
          self.CreateSink(util.GetParentFromArgs(args), sink_data,
                          args.unique_writer_identity))
    log.CreatedResource(sink_ref)
    self._epilog_result_destination = result.destination
    self._writer_identity = result.writer_identity
    return result
コード例 #3
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 updated sink with its new destination.
    """
        util.CheckSinksCommandArguments(args)

        # One of the flags is required to update the sink.
        # log_filter can be an empty string, so check explicitly for None.
        if not (args.destination or args.log_filter is not None
                or args.output_version_format):
            raise calliope_exceptions.ToolException(
                '[destination], --log-filter or --output-version-format is required'
            )

        # Calling Update on a non-existing sink creates it.
        # We need to make sure it exists, otherwise we would create it.
        try:
            if args.log:
                sink = self.GetLogSink()
            elif args.service:
                sink = self.GetLogServiceSink()
            else:
                sink = self.GetProjectSink()
        except apitools_exceptions.HttpError as error:
            project_sink = not args.log and not args.service
            # Suggest the user to add --log or --log-service flag.
            if project_sink and exceptions.HttpException(
                    error).payload.status_code == 404:
                log.status.Print(
                    ('Project sink was not found. '
                     'Did you forget to add --log or --log-service flag?'))
            raise error

        # Only update fields that were passed to the command.
        if args.destination:
            destination = args.destination
        else:
            destination = sink.destination

        if args.log_filter is not None:
            log_filter = args.log_filter
        else:
            log_filter = sink.filter

        sink_ref = self.context['sink_reference']
        sink_data = {
            'name': sink_ref.sinksId,
            'destination': destination,
            'filter': log_filter
        }

        if args.log:
            result = util.TypedLogSink(self.UpdateLogSink(sink_data),
                                       log_name=args.log)
            kind = 'log sink'
        elif args.service:
            result = util.TypedLogSink(self.UpdateLogServiceSink(sink_data),
                                       service_name=args.service)
            kind = 'service log sink'
        else:
            if args.output_version_format:
                sink_data['outputVersionFormat'] = args.output_version_format
            else:
                sink_data[
                    'outputVersionFormat'] = sink.outputVersionFormat.name
            result = util.TypedLogSink(self.UpdateProjectSink(sink_data))
            kind = 'project sink'
        log.UpdatedResource(sink_ref, kind=kind)
        util.PrintPermissionInstructions(result.destination,
                                         result.writer_identity)
        return result
コード例 #4
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 updated sink with its new destination.
    """
        util.CheckSinksCommandArguments(args)

        # One of the flags is required to update the sink.
        # log_filter can be an empty string, so check explicitly for None.
        if not (args.destination or args.log_filter is not None
                or args.output_version_format):
            raise exceptions.ToolException(
                '[destination], --log-filter or --output-version-format is required'
            )

        # Calling Update on a non-existing sink creates it.
        # We need to make sure it exists, otherwise we would create it.
        if args.log:
            sink = self.GetLogSink()
        elif args.service:
            sink = self.GetLogServiceSink()
        else:
            sink = self.GetProjectSink()

        # Only update fields that were passed to the command.
        if args.destination:
            destination = args.destination
        else:
            destination = sink.destination

        if args.log_filter is not None:
            log_filter = args.log_filter
        else:
            log_filter = sink.filter

        sink_ref = self.context['sink_reference']
        sink_data = {
            'name': sink_ref.sinksId,
            'destination': destination,
            'filter': log_filter
        }

        if args.log:
            result = util.TypedLogSink(self.UpdateLogSink(sink_data),
                                       log_name=args.log)
        elif args.service:
            result = util.TypedLogSink(self.UpdateLogServiceSink(sink_data),
                                       service_name=args.service)
        else:
            if args.output_version_format:
                sink_data['outputVersionFormat'] = args.output_version_format
            else:
                sink_data[
                    'outputVersionFormat'] = sink.outputVersionFormat.name
            result = util.TypedLogSink(self.UpdateProjectSink(sink_data))
        log.UpdatedResource(sink_ref)
        return result