Esempio n. 1
0
 def ListLogServiceSinks(self, project, service_name):
     """List log service sinks from the specified service."""
     result = util.GetClientV1().projects_logServices_sinks.List(
         util.GetMessagesV1().LoggingProjectsLogServicesSinksListRequest(
             projectsId=project, logServicesId=service_name))
     for sink in result.sinks:
         yield util.TypedLogSink(sink, service_name=service_name)
Esempio n. 2
0
 def YieldAllSinks(self, project):
     """Yield all log and log service sinks from the specified project."""
     client = util.GetClientV1()
     messages = util.GetMessagesV1()
     # First get all the log sinks.
     response = list_pager.YieldFromList(
         client.projects_logs,
         messages.LoggingProjectsLogsListRequest(projectsId=project),
         field='logs',
         batch_size=None,
         batch_size_attribute='pageSize')
     for log in response:
         # We need only the base log name, not the full resource uri.
         log_id = util.ExtractLogId(log.name)
         for typed_sink in self.ListLogSinks(project, log_id):
             yield typed_sink
     # Now get all the log service sinks.
     response = list_pager.YieldFromList(
         client.projects_logServices,
         messages.LoggingProjectsLogServicesListRequest(projectsId=project),
         field='logServices',
         batch_size=None,
         batch_size_attribute='pageSize')
     for service in response:
         # In contrast, service.name correctly contains only the name.
         for typed_sink in self.ListLogServiceSinks(project, service.name):
             yield typed_sink
     # Lastly, get all v2 sinks.
     for typed_sink in self.ListSinks(util.GetCurrentProjectParent()):
         yield typed_sink
Esempio n. 3
0
 def CreateLogSink(self, sink_data):
   """Creates a log sink specified by the arguments."""
   sink_ref = self.context['sink_reference']
   messages = util.GetMessagesV1()
   return util.GetClientV1().projects_logs_sinks.Create(
       messages.LoggingProjectsLogsSinksCreateRequest(
           projectsId=sink_ref.projectsId, logsId=sink_ref.logsId,
           logSink=messages.LogSink(**sink_data)))
Esempio n. 4
0
 def DeleteLogServiceSink(self, sink_ref):
     """Deletes a log service sink specified by the arguments."""
     messages = util.GetMessagesV1()
     return util.GetClientV1().projects_logServices_sinks.Delete(
         messages.LoggingProjectsLogServicesSinksDeleteRequest(
             projectsId=sink_ref.projectsId,
             logServicesId=sink_ref.logServicesId,
             sinksId=sink_ref.sinksId))
Esempio n. 5
0
 def DeleteLogSink(self):
   """Deletes a log sink specified by the arguments."""
   messages = util.GetMessagesV1()
   sink_ref = self.context['sink_reference']
   return util.GetClientV1().projects_logs_sinks.Delete(
       messages.LoggingProjectsLogsSinksDeleteRequest(
           projectsId=sink_ref.projectsId, logsId=sink_ref.logsId,
           sinksId=sink_ref.sinksId))
Esempio n. 6
0
 def GetLogServiceSink(self, sink_ref):
     """Returns a log service sink specified by the arguments."""
     client = util.GetClientV1()
     return client.projects_logServices_sinks.Get(
         client.MESSAGES_MODULE.LoggingProjectsLogServicesSinksGetRequest(
             projectsId=sink_ref.projectsId,
             logServicesId=sink_ref.logServicesId,
             sinksId=sink_ref.sinksId))
 def GetLogSink(self):
     """Returns a log sink specified by the arguments."""
     client = util.GetClientV1()
     ref = self.context['sink_reference']
     return client.projects_logs_sinks.Get(
         client.MESSAGES_MODULE.LoggingProjectsLogsSinksGetRequest(
             projectsId=ref.projectsId,
             logsId=ref.logsId,
             sinksId=ref.sinksId))
Esempio n. 8
0
 def UpdateLogServiceSink(self, sink_data):
   """Updates a log service sink specified by the arguments."""
   messages = util.GetMessagesV1()
   sink_ref = self.context['sink_reference']
   return util.GetClientV1().projects_logServices_sinks.Update(
       messages.LoggingProjectsLogServicesSinksUpdateRequest(
           projectsId=sink_ref.projectsId,
           logServicesId=sink_ref.logServicesId, sinksId=sink_data['name'],
           logSink=messages.LogSink(**sink_data)))
  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 metric.
    """
    # One of the flags is required to update the metric.
    if not (args.description or args.filter):
      raise exceptions.ToolException(
          '--description or --filter argument is required')

    client = util.GetClientV1()
    messages = util.GetMessagesV1()
    project = properties.VALUES.core.project.Get(required=True)

    # Calling the API's Update method on a non-existing metric creates it.
    # Make sure the metric exists so we don't accidentally create it.
    metric = client.projects_metrics.Get(
        messages.LoggingProjectsMetricsGetRequest(
            metricsId=args.metric_name,
            projectsId=project))

    if args.description:
      metric_description = args.description
    else:
      metric_description = metric.description
    if args.filter:
      metric_filter = args.filter
      # This prevents a clash with the Cloud SDK --filter flag.
      args.filter = None
    else:
      metric_filter = metric.filter

    updated_metric = messages.LogMetric(
        name=args.metric_name,
        description=metric_description,
        filter=metric_filter)

    result = client.projects_metrics.Update(
        messages.LoggingProjectsMetricsUpdateRequest(
            logMetric=updated_metric,
            metricsId=args.metric_name,
            projectsId=project))
    log.UpdatedResource(args.metric_name)
    return result
Esempio n. 10
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 metric with its description and configured filter.
    """
        project = properties.VALUES.core.project.Get(required=True)

        return util.GetClientV1().projects_metrics.Get(
            util.GetMessagesV1().LoggingProjectsMetricsGetRequest(
                metricsId=args.metric_name, projectsId=project))
    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.
    """
        project = properties.VALUES.core.project.Get(required=True)

        if not console_io.PromptContinue(
                'Really delete metric [%s]?' % args.metric_name):
            raise exceptions.ToolException('action canceled by user')

        util.GetClientV1().projects_metrics.Delete(
            util.GetMessagesV1().LoggingProjectsMetricsDeleteRequest(
                metricsId=args.metric_name, projectsId=project))
        log.DeletedResource(args.metric_name)
Esempio n. 12
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 list of logs.
    """
    project = properties.VALUES.core.project.Get(required=True)

    request = util.GetMessagesV1().LoggingProjectsLogsListRequest(
        projectsId=project)

    return list_pager.YieldFromList(
        util.GetClientV1().projects_logs, request, field='logs',
        limit=args.limit, batch_size=None, batch_size_attribute='pageSize')
    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 metric.
    """
        messages = util.GetMessagesV1()
        metric_filter = args.filter
        # This prevents a clash with the Cloud SDK --filter flag.
        args.filter = None
        project = properties.VALUES.core.project.Get(required=True)
        new_metric = messages.LogMetric(name=args.metric_name,
                                        description=args.description,
                                        filter=metric_filter)

        result = util.GetClientV1().projects_metrics.Create(
            messages.LoggingProjectsMetricsCreateRequest(projectsId=project,
                                                         logMetric=new_metric))
        log.CreatedResource(args.metric_name)
        return result