Revision e7b61bb0

b/autotools/build-bash-completion
312 312
      # Only static choices implemented so far (e.g. no node list)
313 313
      suggest = getattr(opt, "completion_suggest", None)
314 314

  
315
      # our custom option type
316
      if opt.type == "bool":
317
        suggest = ["yes", "no"]
318

  
315 319
      if not suggest:
316 320
        suggest = opt.choices
317 321

  
b/lib/cli.py
457 457
  return _SplitKeyVal(opt, value)
458 458

  
459 459

  
460
def check_bool(option, opt, value): # pylint: disable-msg=W0613
461
  """Custom parser for yes/no options.
462

  
463
  This will store the parsed value as either True or False.
464

  
465
  """
466
  value = value.lower()
467
  if value == constants.VALUE_FALSE or value == "no":
468
    return False
469
  elif value == constants.VALUE_TRUE or value == "yes":
470
    return True
471
  else:
472
    raise errors.ParameterError("Invalid boolean value '%s'" % value)
473

  
474

  
460 475
# completion_suggestion is normally a list. Using numeric values not evaluating
461 476
# to False for dynamic completion.
462 477
(OPT_COMPL_MANY_NODES,
......
487 502
    "identkeyval",
488 503
    "keyval",
489 504
    "unit",
505
    "bool",
490 506
    )
491 507
  TYPE_CHECKER = Option.TYPE_CHECKER.copy()
492 508
  TYPE_CHECKER["identkeyval"] = check_ident_key_val
493 509
  TYPE_CHECKER["keyval"] = check_key_val
494 510
  TYPE_CHECKER["unit"] = check_unit
511
  TYPE_CHECKER["bool"] = check_bool
495 512

  
496 513

  
497 514
# optparse.py sets make_option, so we do it for our own option class, too
498 515
cli_option = CliOption
499 516

  
500 517

  
501
_YESNO = ("yes", "no")
502 518
_YORNO = "yes|no"
503 519

  
504 520
DEBUG_OPT = cli_option("-d", "--debug", default=0, action="count",
......
759 775

  
760 776

  
761 777
MC_OPT = cli_option("-C", "--master-candidate", dest="master_candidate",
762
                    choices=_YESNO, default=None, metavar=_YORNO,
778
                    type="bool", default=None, metavar=_YORNO,
763 779
                    help="Set the master_candidate flag on the node")
764 780

  
765 781
OFFLINE_OPT = cli_option("-O", "--offline", dest="offline", metavar=_YORNO,
766
                         choices=_YESNO, default=None,
782
                         type="bool", default=None,
767 783
                         help="Set the offline flag on the node")
768 784

  
769 785
DRAINED_OPT = cli_option("-D", "--drained", dest="drained", metavar=_YORNO,
770
                         choices=_YESNO, default=None,
786
                         type="bool", default=None,
771 787
                         help="Set the drained flag on the node")
772 788

  
773 789
ALLOCATABLE_OPT = cli_option("--allocatable", dest="allocatable",
774
                             choices=_YESNO, default=None, metavar=_YORNO,
790
                             type="bool", default=None, metavar=_YORNO,
775 791
                             help="Set the allocatable flag on a volume")
776 792

  
777 793
NOLVM_STORAGE_OPT = cli_option("--no-lvm-storage", dest="lvm_storage",
b/scripts/gnt-node
571 571
  changes = {}
572 572

  
573 573
  if opts.allocatable is not None:
574
    changes[constants.SF_ALLOCATABLE] = (opts.allocatable == "yes")
574
    changes[constants.SF_ALLOCATABLE] = opts.allocatable
575 575

  
576 576
  if changes:
577 577
    op = opcodes.OpModifyNodeStorage(node_name=node_name,
......
618 618
    ToStderr("Please give at least one of the parameters.")
619 619
    return 1
620 620

  
621
  if opts.master_candidate is not None:
622
    candidate = opts.master_candidate == 'yes'
623
  else:
624
    candidate = None
625
  if opts.offline is not None:
626
    offline = opts.offline == 'yes'
627
  else:
628
    offline = None
629

  
630
  if opts.drained is not None:
631
    drained = opts.drained == 'yes'
632
  else:
633
    drained = None
634 621
  op = opcodes.OpSetNodeParams(node_name=args[0],
635
                               master_candidate=candidate,
636
                               offline=offline,
637
                               drained=drained,
622
                               master_candidate=opts.master_candidate,
623
                               offline=opts.offline,
624
                               drained=opts.drained,
638 625
                               force=opts.force,
639 626
                               auto_promote=opts.auto_promote)
640 627

  

Also available in: Unified diff