Revision f037e9d7

b/lib/cli.py
2800 2800

  
2801 2801
def GenericList(resource, fields, names, unit, separator, header, cl=None,
2802 2802
                format_override=None, verbose=False, force_filter=False,
2803
                namefield=None):
2803
                namefield=None, qfilter=None):
2804 2804
  """Generic implementation for listing all items of a resource.
2805 2805

  
2806 2806
  @param resource: One of L{constants.QR_VIA_LUXI}
......
2826 2826
  @type namefield: string
2827 2827
  @param namefield: Name of field to use for simple filters (see
2828 2828
    L{qlang.MakeFilter} for details)
2829
  @type qfilter: list or None
2830
  @param qfilter: Query filter (in addition to names)
2829 2831

  
2830 2832
  """
2831 2833
  if not names:
2832 2834
    names = None
2833 2835

  
2834
  qfilter = qlang.MakeFilter(names, force_filter, namefield=namefield)
2836
  namefilter = qlang.MakeFilter(names, force_filter, namefield=namefield)
2837

  
2838
  if qfilter is None:
2839
    qfilter = namefilter
2840
  elif namefilter is not None:
2841
    qfilter = [qlang.OP_AND, namefilter, qfilter]
2835 2842

  
2836 2843
  if cl is None:
2837 2844
    cl = GetClient()
b/lib/client/gnt_job.py
79 79
  fmtoverride.update(dict.fromkeys(["opstart", "opexec", "opend"],
80 80
    (lambda value: map(FormatTimestamp, value), None)))
81 81

  
82
  qfilter = qlang.MakeSimpleFilter("status", opts.status_filter)
83

  
82 84
  return GenericList(constants.QR_JOB, selected_fields, args, None,
83 85
                     opts.separator, not opts.no_headers,
84 86
                     format_override=fmtoverride, verbose=opts.verbose,
85
                     force_filter=opts.force_filter, namefield="id")
87
                     force_filter=opts.force_filter, namefield="id",
88
                     qfilter=qfilter)
86 89

  
87 90

  
88 91
def ListJobFields(opts, args):
......
337 340
  return retcode
338 341

  
339 342

  
343
_PENDING_OPT = \
344
  cli_option("--pending", default=None,
345
             action="store_const", dest="status_filter",
346
             const=frozenset([
347
               constants.JOB_STATUS_QUEUED,
348
               constants.JOB_STATUS_WAITING,
349
               ]),
350
             help="Show only jobs pending execution")
351

  
352
_RUNNING_OPT = \
353
  cli_option("--running", default=None,
354
             action="store_const", dest="status_filter",
355
             const=frozenset([
356
               constants.JOB_STATUS_RUNNING,
357
               ]),
358
             help="Show jobs currently running only")
359

  
360
_ERROR_OPT = \
361
  cli_option("--error", default=None,
362
             action="store_const", dest="status_filter",
363
             const=frozenset([
364
               constants.JOB_STATUS_ERROR,
365
               ]),
366
             help="Show failed jobs only")
367

  
368
_FINISHED_OPT = \
369
  cli_option("--finished", default=None,
370
             action="store_const", dest="status_filter",
371
             const=constants.JOBS_FINALIZED,
372
             help="Show finished jobs only")
373

  
374

  
340 375
commands = {
341 376
  "list": (
342 377
    ListJobs, [ArgJobId()],
343
    [NOHDR_OPT, SEP_OPT, FIELDS_OPT, VERBOSE_OPT, FORCE_FILTER_OPT],
378
    [NOHDR_OPT, SEP_OPT, FIELDS_OPT, VERBOSE_OPT, FORCE_FILTER_OPT,
379
     _PENDING_OPT, _RUNNING_OPT, _ERROR_OPT, _FINISHED_OPT],
344 380
    "[job_id ...]",
345 381
    "Lists the jobs and their status. The available fields can be shown"
346 382
    " using the \"list-fields\" command (see the man page for details)."

Also available in: Unified diff