Revision 2928de47

b/lib/cli.py
2569 2569

  
2570 2570

  
2571 2571
def GenericList(resource, fields, names, unit, separator, header, cl=None,
2572
                format_override=None, verbose=False):
2572
                format_override=None, verbose=False, force_filter=False):
2573 2573
  """Generic implementation for listing all items of a resource.
2574 2574

  
2575 2575
  @param resource: One of L{constants.QR_VIA_LUXI}
......
2585 2585
  @param separator: String used to separate fields
2586 2586
  @type header: bool
2587 2587
  @param header: Whether to show header row
2588
  @type force_filter: bool
2589
  @param force_filter: Whether to always treat names as filter
2588 2590
  @type format_override: dict
2589 2591
  @param format_override: Dictionary for overriding field formatting functions,
2590 2592
    indexed by field name, contents like L{_DEFAULT_FORMAT_QUERY}
......
2598 2600
  if not names:
2599 2601
    names = None
2600 2602

  
2601
  response = cl.Query(resource, fields, qlang.MakeSimpleFilter("name", names))
2603
  if (force_filter or
2604
      (names and len(names) == 1 and qlang.MaybeFilter(names[0]))):
2605
    try:
2606
      (filter_text, ) = names
2607
    except ValueError:
2608
      raise errors.OpPrereqError("Exactly one argument must be given as a"
2609
                                 " filter")
2610

  
2611
    logging.debug("Parsing '%s' as filter", filter_text)
2612
    filter_ = qlang.ParseFilter(filter_text)
2613
  else:
2614
    filter_ = qlang.MakeSimpleFilter("name", names)
2615

  
2616
  response = cl.Query(resource, fields, filter_)
2602 2617

  
2603 2618
  found_unknown = _WarnUnknownFields(response.fields)
2604 2619

  

Also available in: Unified diff