Package ganeti :: Module cli_opts
[hide private]
[frames] | no frames]

Source Code for Module ganeti.cli_opts

   1  # 
   2  # 
   3   
   4  # Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014 Google Inc. 
   5  # All rights reserved. 
   6  # 
   7  # Redistribution and use in source and binary forms, with or without 
   8  # modification, are permitted provided that the following conditions are 
   9  # met: 
  10  # 
  11  # 1. Redistributions of source code must retain the above copyright notice, 
  12  # this list of conditions and the following disclaimer. 
  13  # 
  14  # 2. Redistributions in binary form must reproduce the above copyright 
  15  # notice, this list of conditions and the following disclaimer in the 
  16  # documentation and/or other materials provided with the distribution. 
  17  # 
  18  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 
  19  # IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 
  20  # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
  21  # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 
  22  # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
  23  # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
  24  # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
  25  # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 
  26  # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 
  27  # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
  28  # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
  29   
  30   
  31  """Module containing Ganeti's command line parsing options""" 
  32   
  33  import re 
  34  import simplejson 
  35   
  36  from ganeti import utils 
  37  from ganeti import errors 
  38  from ganeti import constants 
  39  from ganeti import compat 
  40  from ganeti import pathutils 
  41  from ganeti import serializer 
  42   
  43  from optparse import (Option, OptionValueError) 
  44   
  45   
  46  __all__ = [ 
  47    "ABSOLUTE_OPT", 
  48    "ADD_RESERVED_IPS_OPT", 
  49    "ADD_UIDS_OPT", 
  50    "ALL_OPT", 
  51    "ALLOC_POLICY_OPT", 
  52    "ALLOCATABLE_OPT", 
  53    "ALLOW_FAILOVER_OPT", 
  54    "AUTO_PROMOTE_OPT", 
  55    "AUTO_REPLACE_OPT", 
  56    "BACKEND_OPT", 
  57    "BLK_OS_OPT", 
  58    "CAPAB_MASTER_OPT", 
  59    "CAPAB_VM_OPT", 
  60    "CLEANUP_OPT", 
  61    "cli_option", 
  62    "CLUSTER_DOMAIN_SECRET_OPT", 
  63    "COMMIT_OPT", 
  64    "COMMON_CREATE_OPTS", 
  65    "COMMON_OPTS", 
  66    "COMPRESS_OPT", 
  67    "COMPRESSION_TOOLS_OPT", 
  68    "CONFIRM_OPT", 
  69    "CP_SIZE_OPT", 
  70    "DEBUG_OPT", 
  71    "DEBUG_SIMERR_OPT", 
  72    "DEFAULT_IALLOCATOR_OPT", 
  73    "DEFAULT_IALLOCATOR_PARAMS_OPT", 
  74    "DISK_OPT", 
  75    "DISK_PARAMS_OPT", 
  76    "DISK_STATE_OPT", 
  77    "DISK_TEMPLATE_OPT", 
  78    "DISKIDX_OPT", 
  79    "DRAINED_OPT", 
  80    "DRBD_HELPER_OPT", 
  81    "DRY_RUN_OPT", 
  82    "DST_NODE_OPT", 
  83    "EARLY_RELEASE_OPT", 
  84    "ENABLED_DATA_COLLECTORS_OPT", 
  85    "DIAGNOSE_DATA_COLLECTOR_FILENAME_OPT", 
  86    "ENABLED_DISK_TEMPLATES_OPT", 
  87    "ENABLED_HV_OPT", 
  88    "ENABLED_USER_SHUTDOWN_OPT", 
  89    "ERROR_CODES_OPT", 
  90    "EXT_PARAMS_OPT", 
  91    "FAILURE_ONLY_OPT", 
  92    "FIELDS_OPT", 
  93    "FILESTORE_DIR_OPT", 
  94    "FILESTORE_DRIVER_OPT", 
  95    "FORCE_FAILOVER_OPT", 
  96    "FORCE_FILTER_OPT", 
  97    "FORCE_OPT", 
  98    "FORCE_VARIANT_OPT", 
  99    "FORTHCOMING_OPT", 
 100    "GATEWAY6_OPT", 
 101    "GATEWAY_OPT", 
 102    "GLOBAL_FILEDIR_OPT", 
 103    "GLOBAL_GLUSTER_FILEDIR_OPT", 
 104    "GLOBAL_SHARED_FILEDIR_OPT", 
 105    "HELPER_SHUTDOWN_TIMEOUT_OPT", 
 106    "HELPER_STARTUP_TIMEOUT_OPT", 
 107    "HID_OS_OPT", 
 108    "HOTPLUG_IF_POSSIBLE_OPT", 
 109    "HOTPLUG_OPT", 
 110    "HV_STATE_OPT", 
 111    "HVLIST_OPT", 
 112    "HVOPTS_OPT", 
 113    "HYPERVISOR_OPT", 
 114    "IALLOCATOR_OPT", 
 115    "IDENTIFY_DEFAULTS_OPT", 
 116    "IGNORE_CONSIST_OPT", 
 117    "IGNORE_ERRORS_OPT", 
 118    "IGNORE_FAILURES_OPT", 
 119    "IGNORE_HVVERSIONS_OPT", 
 120    "IGNORE_IPOLICY_OPT", 
 121    "IGNORE_OFFLINE_OPT", 
 122    "IGNORE_REMOVE_FAILURES_OPT", 
 123    "IGNORE_SECONDARIES_OPT", 
 124    "IGNORE_SOFT_ERRORS_OPT", 
 125    "IGNORE_SIZE_OPT", 
 126    "INCLUDEDEFAULTS_OPT", 
 127    "INPUT_OPT", 
 128    "INSTALL_IMAGE_OPT", 
 129    "INSTANCE_COMMUNICATION_NETWORK_OPT", 
 130    "INSTANCE_COMMUNICATION_OPT", 
 131    "INSTANCE_POLICY_OPTS", 
 132    "INTERVAL_OPT", 
 133    "IPOLICY_BOUNDS_SPECS_STR", 
 134    "IPOLICY_DISK_TEMPLATES", 
 135    "IPOLICY_SPINDLE_RATIO", 
 136    "IPOLICY_STD_SPECS_OPT", 
 137    "IPOLICY_STD_SPECS_STR", 
 138    "IPOLICY_VCPU_RATIO", 
 139    "IPOLICY_MEMORY_RATIO", 
 140    "LONG_SLEEP_OPT", 
 141    "MAC_PREFIX_OPT", 
 142    "MAINT_BALANCE_OPT", 
 143    "MAINT_BALANCE_THRESHOLD_OPT", 
 144    "MAINT_INTERVAL_OPT", 
 145    "MAINTAIN_NODE_HEALTH_OPT", 
 146    "MASTER_NETDEV_OPT", 
 147    "MASTER_NETMASK_OPT", 
 148    "MAX_TRACK_OPT", 
 149    "MC_OPT", 
 150    "MIGRATION_MODE_OPT", 
 151    "MODIFY_ETCHOSTS_OPT", 
 152    "NET_OPT", 
 153    "NETWORK6_OPT", 
 154    "NETWORK_OPT", 
 155    "NEW_CLUSTER_CERT_OPT", 
 156    "NEW_CLUSTER_DOMAIN_SECRET_OPT", 
 157    "NEW_CONFD_HMAC_KEY_OPT", 
 158    "NEW_NODE_CERT_OPT", 
 159    "NEW_PRIMARY_OPT", 
 160    "NEW_RAPI_CERT_OPT", 
 161    "NEW_SECONDARY_OPT", 
 162    "NEW_SPICE_CERT_OPT", 
 163    "NEW_SSH_KEY_OPT", 
 164    "NIC_PARAMS_OPT", 
 165    "NO_INSTALL_OPT", 
 166    "NO_REMEMBER_OPT", 
 167    "NOCONFLICTSCHECK_OPT", 
 168    "NODE_FORCE_JOIN_OPT", 
 169    "NODE_LIST_OPT", 
 170    "NODE_PARAMS_OPT", 
 171    "NODE_PLACEMENT_OPT", 
 172    "NODE_POWERED_OPT", 
 173    "NODEGROUP_OPT", 
 174    "NODEGROUP_OPT_NAME", 
 175    "NOHDR_OPT", 
 176    "NOIPCHECK_OPT", 
 177    "NOMODIFY_ETCHOSTS_OPT", 
 178    "NOMODIFY_SSH_SETUP_OPT", 
 179    "NONAMECHECK_OPT", 
 180    "NONICS_OPT", 
 181    "NONLIVE_OPT", 
 182    "NONPLUS1_OPT", 
 183    "NORUNTIME_CHGS_OPT", 
 184    "NOSHUTDOWN_OPT", 
 185    "NOSSH_KEYCHECK_OPT", 
 186    "NOSTART_OPT", 
 187    "NOVOTING_OPT", 
 188    "NWSYNC_OPT", 
 189    "OFFLINE_INST_OPT", 
 190    "OFFLINE_OPT", 
 191    "ON_PRIMARY_OPT", 
 192    "ON_SECONDARY_OPT", 
 193    "ONLINE_INST_OPT", 
 194    "OOB_TIMEOUT_OPT", 
 195    "OPT_COMPL_ALL", 
 196    "OPT_COMPL_INST_ADD_NODES", 
 197    "OPT_COMPL_MANY_NODES", 
 198    "OPT_COMPL_ONE_EXTSTORAGE", 
 199    "OPT_COMPL_ONE_FILTER", 
 200    "OPT_COMPL_ONE_IALLOCATOR", 
 201    "OPT_COMPL_ONE_INSTANCE", 
 202    "OPT_COMPL_ONE_NETWORK", 
 203    "OPT_COMPL_ONE_NODE", 
 204    "OPT_COMPL_ONE_NODEGROUP", 
 205    "OPT_COMPL_ONE_OS", 
 206    "OS_OPT", 
 207    "OS_SIZE_OPT", 
 208    "OSPARAMS_OPT", 
 209    "OSPARAMS_PRIVATE_OPT", 
 210    "OSPARAMS_SECRET_OPT", 
 211    "POWER_DELAY_OPT", 
 212    "PREALLOC_WIPE_DISKS_OPT", 
 213    "PRIMARY_IP_VERSION_OPT", 
 214    "PRIMARY_ONLY_OPT", 
 215    "PRINT_JOBID_OPT", 
 216    "PRIORITY_OPT", 
 217    "RAPI_CERT_OPT", 
 218    "READD_OPT", 
 219    "REASON_OPT", 
 220    "REBOOT_TYPE_OPT", 
 221    "REMOVE_INSTANCE_OPT", 
 222    "REMOVE_RESERVED_IPS_OPT", 
 223    "REMOVE_UIDS_OPT", 
 224    "RESERVED_LVS_OPT", 
 225    "ROMAN_OPT", 
 226    "RQL_OPT", 
 227    "RUNTIME_MEM_OPT", 
 228    "SECONDARY_IP_OPT", 
 229    "SECONDARY_ONLY_OPT", 
 230    "SELECT_OS_OPT", 
 231    "SEP_OPT", 
 232    "SEQUENTIAL_OPT", 
 233    "SHOW_MACHINE_OPT", 
 234    "SHOWCMD_OPT", 
 235    "SHUTDOWN_TIMEOUT_OPT", 
 236    "SINGLE_NODE_OPT", 
 237    "SPECS_CPU_COUNT_OPT", 
 238    "SPECS_DISK_COUNT_OPT", 
 239    "SPECS_DISK_SIZE_OPT", 
 240    "SPECS_MEM_SIZE_OPT", 
 241    "SPECS_NIC_COUNT_OPT", 
 242    "SPICE_CACERT_OPT", 
 243    "SPICE_CERT_OPT", 
 244    "SPLIT_ISPECS_OPTS", 
 245    "SRC_DIR_OPT", 
 246    "SRC_NODE_OPT", 
 247    "SSH_KEY_BITS_OPT", 
 248    "SSH_KEY_TYPE_OPT", 
 249    "STARTUP_PAUSED_OPT", 
 250    "STATIC_OPT", 
 251    "SUBMIT_OPT", 
 252    "SUBMIT_OPTS", 
 253    "SYNC_OPT", 
 254    "TAG_ADD_OPT", 
 255    "TAG_SRC_OPT", 
 256    "TIMEOUT_OPT", 
 257    "TO_GROUP_OPT", 
 258    "TRANSPORT_COMPRESSION_OPT", 
 259    "UIDPOOL_OPT", 
 260    "USE_EXTERNAL_MIP_SCRIPT", 
 261    "USE_REPL_NET_OPT", 
 262    "USEUNITS_OPT", 
 263    "VERBOSE_OPT", 
 264    "VERIFY_CLUTTER_OPT", 
 265    "VG_NAME_OPT", 
 266    "WFSYNC_OPT", 
 267    "YES_DOIT_OPT", 
 268    "ZERO_FREE_SPACE_OPT", 
 269    "ZEROING_IMAGE_OPT", 
 270    "ZEROING_TIMEOUT_FIXED_OPT", 
 271    "ZEROING_TIMEOUT_PER_MIB_OPT", 
 272    ] 
 273   
 274   
 275  NO_PREFIX = "no_" 
 276  UN_PREFIX = "-" 
 277   
 278   
 279  #: Priorities (sorted) 
 280  _PRIORITY_NAMES = [ 
 281    ("low", constants.OP_PRIO_LOW), 
 282    ("normal", constants.OP_PRIO_NORMAL), 
 283    ("high", constants.OP_PRIO_HIGH), 
 284    ] 
 285   
 286  #: Priority dictionary for easier lookup 
 287  # TODO: Replace this and _PRIORITY_NAMES with a single sorted dictionary once 
 288  # we migrate to Python 2.6 
 289  _PRIONAME_TO_VALUE = dict(_PRIORITY_NAMES) 
 290   
 291   
292 -def check_unit(option, opt, value): # pylint: disable=W0613
293 """OptParsers custom converter for units. 294 295 """ 296 try: 297 return utils.ParseUnit(value) 298 except errors.UnitParseError, err: 299 raise OptionValueError("option %s: %s" % (opt, err)) 300 301
302 -def _SplitKeyVal(opt, data, parse_prefixes):
303 """Convert a KeyVal string into a dict. 304 305 This function will convert a key=val[,...] string into a dict. Empty 306 values will be converted specially: keys which have the prefix 'no_' 307 will have the value=False and the prefix stripped, keys with the prefix 308 "-" will have value=None and the prefix stripped, and the others will 309 have value=True. 310 311 @type opt: string 312 @param opt: a string holding the option name for which we process the 313 data, used in building error messages 314 @type data: string 315 @param data: a string of the format key=val,key=val,... 316 @type parse_prefixes: bool 317 @param parse_prefixes: whether to handle prefixes specially 318 @rtype: dict 319 @return: {key=val, key=val} 320 @raises errors.ParameterError: if there are duplicate keys 321 322 """ 323 kv_dict = {} 324 if data: 325 for elem in utils.UnescapeAndSplit(data, sep=","): 326 if "=" in elem: 327 key, val = elem.split("=", 1) 328 elif parse_prefixes: 329 if elem.startswith(NO_PREFIX): 330 key, val = elem[len(NO_PREFIX):], False 331 elif elem.startswith(UN_PREFIX): 332 key, val = elem[len(UN_PREFIX):], None 333 else: 334 key, val = elem, True 335 else: 336 raise errors.ParameterError("Missing value for key '%s' in option %s" % 337 (elem, opt)) 338 if key in kv_dict: 339 raise errors.ParameterError("Duplicate key '%s' in option %s" % 340 (key, opt)) 341 kv_dict[key] = val 342 return kv_dict
343 344
345 -def _SplitIdentKeyVal(opt, value, parse_prefixes):
346 """Helper function to parse "ident:key=val,key=val" options. 347 348 @type opt: string 349 @param opt: option name, used in error messages 350 @type value: string 351 @param value: expected to be in the format "ident:key=val,key=val,..." 352 @type parse_prefixes: bool 353 @param parse_prefixes: whether to handle prefixes specially (see 354 L{_SplitKeyVal}) 355 @rtype: tuple 356 @return: (ident, {key=val, key=val}) 357 @raises errors.ParameterError: in case of duplicates or other parsing errors 358 359 """ 360 if ":" not in value: 361 ident, rest = value, "" 362 else: 363 ident, rest = value.split(":", 1) 364 365 if parse_prefixes and ident.startswith(NO_PREFIX): 366 if rest: 367 msg = "Cannot pass options when removing parameter groups: %s" % value 368 raise errors.ParameterError(msg) 369 retval = (ident[len(NO_PREFIX):], False) 370 elif (parse_prefixes and ident.startswith(UN_PREFIX) and 371 (len(ident) <= len(UN_PREFIX) or not ident[len(UN_PREFIX)].isdigit())): 372 if rest: 373 msg = "Cannot pass options when removing parameter groups: %s" % value 374 raise errors.ParameterError(msg) 375 retval = (ident[len(UN_PREFIX):], None) 376 else: 377 kv_dict = _SplitKeyVal(opt, rest, parse_prefixes) 378 retval = (ident, kv_dict) 379 return retval
380 381
382 -def check_ident_key_val(option, opt, value): # pylint: disable=W0613
383 """Custom parser for ident:key=val,key=val options. 384 385 This will store the parsed values as a tuple (ident, {key: val}). As such, 386 multiple uses of this option via action=append is possible. 387 388 """ 389 return _SplitIdentKeyVal(opt, value, True) 390 391
392 -def check_key_val(option, opt, value): # pylint: disable=W0613
393 """Custom parser class for key=val,key=val options. 394 395 This will store the parsed values as a dict {key: val}. 396 397 """ 398 return _SplitKeyVal(opt, value, True) 399 400
401 -def check_key_private_val(option, opt, value): # pylint: disable=W0613
402 """Custom parser class for private and secret key=val,key=val options. 403 404 This will store the parsed values as a dict {key: val}. 405 406 """ 407 return serializer.PrivateDict(_SplitKeyVal(opt, value, True)) 408 409
410 -def _SplitListKeyVal(opt, value):
411 retval = {} 412 for elem in value.split("/"): 413 if not elem: 414 raise errors.ParameterError("Empty section in option '%s'" % opt) 415 (ident, valdict) = _SplitIdentKeyVal(opt, elem, False) 416 if ident in retval: 417 msg = ("Duplicated parameter '%s' in parsing %s: %s" % 418 (ident, opt, elem)) 419 raise errors.ParameterError(msg) 420 retval[ident] = valdict 421 return retval
422 423
424 -def check_multilist_ident_key_val(_, opt, value):
425 """Custom parser for "ident:key=val,key=val/ident:key=val//ident:.." options. 426 427 @rtype: list of dictionary 428 @return: [{ident: {key: val, key: val}, ident: {key: val}}, {ident:..}] 429 430 """ 431 retval = [] 432 for line in value.split("//"): 433 retval.append(_SplitListKeyVal(opt, line)) 434 return retval
435 436
437 -def check_bool(option, opt, value): # pylint: disable=W0613
438 """Custom parser for yes/no options. 439 440 This will store the parsed value as either True or False. 441 442 """ 443 value = value.lower() 444 if value == constants.VALUE_FALSE or value == "no": 445 return False 446 elif value == constants.VALUE_TRUE or value == "yes": 447 return True 448 else: 449 raise errors.ParameterError("Invalid boolean value '%s'" % value) 450 451
452 -def check_list(option, opt, value): # pylint: disable=W0613
453 """Custom parser for comma-separated lists. 454 455 """ 456 # we have to make this explicit check since "".split(",") is [""], 457 # not an empty list :( 458 if not value: 459 return [] 460 else: 461 return utils.UnescapeAndSplit(value) 462 463
464 -def check_maybefloat(option, opt, value): # pylint: disable=W0613
465 """Custom parser for float numbers which might be also defaults. 466 467 """ 468 value = value.lower() 469 470 if value == constants.VALUE_DEFAULT: 471 return value 472 else: 473 return float(value) 474 475
476 -def check_json(option, opt, value): # pylint: disable=W0613
477 """Custom parser for JSON arguments. 478 479 Takes a string containing JSON, returns a Python object. 480 481 """ 482 return simplejson.loads(value) 483 484
485 -def check_filteraction(option, opt, value): # pylint: disable=W0613
486 """Custom parser for filter rule actions. 487 488 Takes a string, returns an action as a Python object (list or string). 489 490 The string "RATE_LIMIT n" becomes `["RATE_LIMIT", n]`. 491 All other strings stay as they are. 492 493 """ 494 match = re.match(r"RATE_LIMIT\s+(\d+)", value) 495 if match: 496 n = int(match.group(1)) 497 return ["RATE_LIMIT", n] 498 else: 499 return value 500 501 502 # completion_suggestion is normally a list. Using numeric values not evaluating 503 # to False for dynamic completion. 504 (OPT_COMPL_MANY_NODES, 505 OPT_COMPL_ONE_NODE, 506 OPT_COMPL_ONE_INSTANCE, 507 OPT_COMPL_ONE_OS, 508 OPT_COMPL_ONE_EXTSTORAGE, 509 OPT_COMPL_ONE_FILTER, 510 OPT_COMPL_ONE_IALLOCATOR, 511 OPT_COMPL_ONE_NETWORK, 512 OPT_COMPL_INST_ADD_NODES, 513 OPT_COMPL_ONE_NODEGROUP) = range(100, 110) 514 515 OPT_COMPL_ALL = compat.UniqueFrozenset([ 516 OPT_COMPL_MANY_NODES, 517 OPT_COMPL_ONE_NODE, 518 OPT_COMPL_ONE_INSTANCE, 519 OPT_COMPL_ONE_OS, 520 OPT_COMPL_ONE_EXTSTORAGE, 521 OPT_COMPL_ONE_FILTER, 522 OPT_COMPL_ONE_IALLOCATOR, 523 OPT_COMPL_ONE_NETWORK, 524 OPT_COMPL_INST_ADD_NODES, 525 OPT_COMPL_ONE_NODEGROUP, 526 ]) 527 528
529 -class CliOption(Option):
530 """Custom option class for optparse. 531 532 """ 533 ATTRS = Option.ATTRS + [ 534 "completion_suggest", 535 ] 536 TYPES = Option.TYPES + ( 537 "multilistidentkeyval", 538 "identkeyval", 539 "keyval", 540 "keyprivateval", 541 "unit", 542 "bool", 543 "list", 544 "maybefloat", 545 "json", 546 "filteraction", 547 ) 548 TYPE_CHECKER = Option.TYPE_CHECKER.copy() 549 TYPE_CHECKER["multilistidentkeyval"] = check_multilist_ident_key_val 550 TYPE_CHECKER["identkeyval"] = check_ident_key_val 551 TYPE_CHECKER["keyval"] = check_key_val 552 TYPE_CHECKER["keyprivateval"] = check_key_private_val 553 TYPE_CHECKER["unit"] = check_unit 554 TYPE_CHECKER["bool"] = check_bool 555 TYPE_CHECKER["list"] = check_list 556 TYPE_CHECKER["maybefloat"] = check_maybefloat 557 TYPE_CHECKER["json"] = check_json 558 TYPE_CHECKER["filteraction"] = check_filteraction
559 560 561 # optparse.py sets make_option, so we do it for our own option class, too 562 cli_option = CliOption 563 564 565 _YORNO = "yes|no" 566 567 DEBUG_OPT = cli_option("-d", "--debug", default=0, action="count", 568 help="Increase debugging level") 569 570 NOHDR_OPT = cli_option("--no-headers", default=False, 571 action="store_true", dest="no_headers", 572 help="Don't display column headers") 573 574 SEP_OPT = cli_option("--separator", default=None, 575 action="store", dest="separator", 576 help=("Separator between output fields" 577 " (defaults to one space)")) 578 579 USEUNITS_OPT = cli_option("--units", default=None, 580 dest="units", choices=("h", "m", "g", "t"), 581 help="Specify units for output (one of h/m/g/t)") 582 583 FIELDS_OPT = cli_option("-o", "--output", dest="output", action="store", 584 type="string", metavar="FIELDS", 585 help="Comma separated list of output fields") 586 587 FORCE_OPT = cli_option("-f", "--force", dest="force", action="store_true", 588 default=False, help="Force the operation") 589 590 CONFIRM_OPT = cli_option("--yes", dest="confirm", action="store_true", 591 default=False, help="Do not require confirmation") 592 593 IGNORE_OFFLINE_OPT = cli_option("--ignore-offline", dest="ignore_offline", 594 action="store_true", default=False, 595 help=("Ignore offline nodes and do as much" 596 " as possible")) 597 598 IGNORE_SOFT_ERRORS_OPT = cli_option("--ignore-soft-errors", 599 dest="ignore_soft_errors", 600 action="store_true", default=False, 601 help=("Tell htools to ignore any soft" 602 " errors like N+1 violations")) 603 604 TAG_ADD_OPT = cli_option("--tags", dest="tags", 605 default=None, help="Comma-separated list of instance" 606 " tags") 607 608 TAG_SRC_OPT = cli_option("--from", dest="tags_source", 609 default=None, help="File with tag names") 610 611 SUBMIT_OPT = cli_option("--submit", dest="submit_only", 612 default=False, action="store_true", 613 help=("Submit the job and return the job ID, but" 614 " don't wait for the job to finish")) 615 616 PRINT_JOBID_OPT = cli_option("--print-jobid", dest="print_jobid", 617 default=False, action="store_true", 618 help=("Additionally print the job as first line" 619 " on stdout (for scripting).")) 620 621 SEQUENTIAL_OPT = cli_option("--sequential", dest="sequential", 622 default=False, action="store_true", 623 help=("Execute all resulting jobs sequentially")) 624 625 SYNC_OPT = cli_option("--sync", dest="do_locking", 626 default=False, action="store_true", 627 help=("Grab locks while doing the queries" 628 " in order to ensure more consistent results")) 629 630 DRY_RUN_OPT = cli_option("--dry-run", default=False, 631 action="store_true", 632 help=("Do not execute the operation, just run the" 633 " check steps and verify if it could be" 634 " executed")) 635 636 VERBOSE_OPT = cli_option("-v", "--verbose", default=False, 637 action="store_true", 638 help="Increase the verbosity of the operation") 639 640 DEBUG_SIMERR_OPT = cli_option("--debug-simulate-errors", default=False, 641 action="store_true", dest="simulate_errors", 642 help="Debugging option that makes the operation" 643 " treat most runtime checks as failed") 644 645 NWSYNC_OPT = cli_option("--no-wait-for-sync", dest="wait_for_sync", 646 default=True, action="store_false", 647 help="Don't wait for sync (DANGEROUS!)") 648 649 WFSYNC_OPT = cli_option("--wait-for-sync", dest="wait_for_sync", 650 default=False, action="store_true", 651 help="Wait for disks to sync") 652 653 ONLINE_INST_OPT = cli_option("--online", dest="online_inst", 654 action="store_true", default=False, 655 help="Enable offline instance") 656 657 OFFLINE_INST_OPT = cli_option("--offline", dest="offline_inst", 658 action="store_true", default=False, 659 help="Disable down instance") 660 661 DISK_TEMPLATE_OPT = cli_option("-t", "--disk-template", dest="disk_template", 662 help=("Custom disk setup (%s)" % 663 utils.CommaJoin(constants.DISK_TEMPLATES)), 664 default=None, metavar="TEMPL", 665 choices=list(constants.DISK_TEMPLATES)) 666 667 EXT_PARAMS_OPT = cli_option("-e", "--ext-params", dest="ext_params", 668 default={}, type="keyval", 669 help="Parameters for ExtStorage template" 670 " conversions in the format:" 671 " provider=prvdr[,param1=val1,param2=val2,...]") 672 673 NONICS_OPT = cli_option("--no-nics", default=False, action="store_true", 674 help="Do not create any network cards for" 675 " the instance") 676 677 FILESTORE_DIR_OPT = cli_option("--file-storage-dir", dest="file_storage_dir", 678 help="Relative path under default cluster-wide" 679 " file storage dir to store file-based disks", 680 default=None, metavar="<DIR>") 681 682 FILESTORE_DRIVER_OPT = cli_option("--file-driver", dest="file_driver", 683 help="Driver to use for image files", 684 default=None, metavar="<DRIVER>", 685 choices=list(constants.FILE_DRIVER)) 686 687 IALLOCATOR_OPT = cli_option("-I", "--iallocator", metavar="<NAME>", 688 help="Select nodes for the instance automatically" 689 " using the <NAME> iallocator plugin", 690 default=None, type="string", 691 completion_suggest=OPT_COMPL_ONE_IALLOCATOR) 692 693 DEFAULT_IALLOCATOR_OPT = cli_option("-I", "--default-iallocator", 694 metavar="<NAME>", 695 help="Set the default instance" 696 " allocator plugin", 697 default=None, type="string", 698 completion_suggest=OPT_COMPL_ONE_IALLOCATOR) 699 700 DEFAULT_IALLOCATOR_PARAMS_OPT = cli_option("--default-iallocator-params", 701 dest="default_iallocator_params", 702 help="iallocator template" 703 " parameters, in the format" 704 " template:option=value," 705 " option=value,...", 706 type="keyval", 707 default=None) 708 709 OS_OPT = cli_option("-o", "--os-type", dest="os", help="What OS to run", 710 metavar="<os>", 711 completion_suggest=OPT_COMPL_ONE_OS) 712 713 OSPARAMS_OPT = cli_option("-O", "--os-parameters", dest="osparams", 714 type="keyval", default={}, 715 help="OS parameters") 716 717 OSPARAMS_PRIVATE_OPT = cli_option("--os-parameters-private", 718 dest="osparams_private", 719 type="keyprivateval", 720 default=serializer.PrivateDict(), 721 help="Private OS parameters" 722 " (won't be logged)") 723 724 OSPARAMS_SECRET_OPT = cli_option("--os-parameters-secret", 725 dest="osparams_secret", 726 type="keyprivateval", 727 default=serializer.PrivateDict(), 728 help="Secret OS parameters (won't be logged or" 729 " saved; you must supply these for every" 730 " operation.)") 731 732 FORCE_VARIANT_OPT = cli_option("--force-variant", dest="force_variant", 733 action="store_true", default=False, 734 help="Force an unknown variant") 735 736 NO_INSTALL_OPT = cli_option("--no-install", dest="no_install", 737 action="store_true", default=False, 738 help="Do not install the OS (will" 739 " enable no-start)") 740 741 NORUNTIME_CHGS_OPT = cli_option("--no-runtime-changes", 742 dest="allow_runtime_chgs", 743 default=True, action="store_false", 744 help="Don't allow runtime changes") 745 746 BACKEND_OPT = cli_option("-B", "--backend-parameters", dest="beparams", 747 type="keyval", default={}, 748 help="Backend parameters") 749 750 HVOPTS_OPT = cli_option("-H", "--hypervisor-parameters", type="keyval", 751 default={}, dest="hvparams", 752 help="Hypervisor parameters") 753 754 DISK_PARAMS_OPT = cli_option("-D", "--disk-parameters", dest="diskparams", 755 help="Disk template parameters, in the format" 756 " template:option=value,option=value,...", 757 type="identkeyval", action="append", default=[]) 758 759 SPECS_MEM_SIZE_OPT = cli_option("--specs-mem-size", dest="ispecs_mem_size", 760 type="keyval", default={}, 761 help="Memory size specs: list of key=value," 762 " where key is one of min, max, std" 763 " (in MB or using a unit)") 764 765 SPECS_CPU_COUNT_OPT = cli_option("--specs-cpu-count", dest="ispecs_cpu_count", 766 type="keyval", default={}, 767 help="CPU count specs: list of key=value," 768 " where key is one of min, max, std") 769 770 SPECS_DISK_COUNT_OPT = cli_option("--specs-disk-count", 771 dest="ispecs_disk_count", 772 type="keyval", default={}, 773 help="Disk count specs: list of key=value," 774 " where key is one of min, max, std") 775 776 SPECS_DISK_SIZE_OPT = cli_option("--specs-disk-size", dest="ispecs_disk_size", 777 type="keyval", default={}, 778 help="Disk size specs: list of key=value," 779 " where key is one of min, max, std" 780 " (in MB or using a unit)") 781 782 SPECS_NIC_COUNT_OPT = cli_option("--specs-nic-count", dest="ispecs_nic_count", 783 type="keyval", default={}, 784 help="NIC count specs: list of key=value," 785 " where key is one of min, max, std") 786 787 IPOLICY_BOUNDS_SPECS_STR = "--ipolicy-bounds-specs" 788 IPOLICY_BOUNDS_SPECS_OPT = cli_option(IPOLICY_BOUNDS_SPECS_STR, 789 dest="ipolicy_bounds_specs", 790 type="multilistidentkeyval", default=None, 791 help="Complete instance specs limits") 792 793 IPOLICY_STD_SPECS_STR = "--ipolicy-std-specs" 794 IPOLICY_STD_SPECS_OPT = cli_option(IPOLICY_STD_SPECS_STR, 795 dest="ipolicy_std_specs", 796 type="keyval", default=None, 797 help="Complete standard instance specs") 798 799 IPOLICY_DISK_TEMPLATES = cli_option("--ipolicy-disk-templates", 800 dest="ipolicy_disk_templates", 801 type="list", default=None, 802 help="Comma-separated list of" 803 " enabled disk templates") 804 805 IPOLICY_VCPU_RATIO = cli_option("--ipolicy-vcpu-ratio", 806 dest="ipolicy_vcpu_ratio", 807 type="maybefloat", default=None, 808 help="The maximum allowed vcpu-to-cpu ratio") 809 810 IPOLICY_SPINDLE_RATIO = cli_option("--ipolicy-spindle-ratio", 811 dest="ipolicy_spindle_ratio", 812 type="maybefloat", default=None, 813 help=("The maximum allowed instances to" 814 " spindle ratio")) 815 816 IPOLICY_MEMORY_RATIO = cli_option("--ipolicy-memory-ratio", 817 dest="ipolicy_memory_ratio", 818 type="maybefloat", default=None, 819 help=("The maximum allowed used memory to" 820 " physicall memory ratio (in terms of" 821 " memory overcommitment)")) 822 823 HYPERVISOR_OPT = cli_option("-H", "--hypervisor-parameters", dest="hypervisor", 824 help="Hypervisor and hypervisor options, in the" 825 " format hypervisor:option=value,option=value,...", 826 default=None, type="identkeyval") 827 828 HVLIST_OPT = cli_option("-H", "--hypervisor-parameters", dest="hvparams", 829 help="Hypervisor and hypervisor options, in the" 830 " format hypervisor:option=value,option=value,...", 831 default=[], action="append", type="identkeyval") 832 833 NOIPCHECK_OPT = cli_option("--no-ip-check", dest="ip_check", default=True, 834 action="store_false", 835 help="Don't check that the instance's IP" 836 " is alive") 837 838 NONAMECHECK_OPT = cli_option("--no-name-check", dest="name_check", 839 default=True, action="store_false", 840 help="Don't check that the instance's name" 841 " is resolvable") 842 843 NET_OPT = cli_option("--net", 844 help="NIC parameters", default=[], 845 dest="nics", action="append", type="identkeyval") 846 847 DISK_OPT = cli_option("--disk", help="Disk parameters", default=[], 848 dest="disks", action="append", type="identkeyval") 849 850 DISKIDX_OPT = cli_option("--disks", dest="disks", default=None, 851 help="Comma-separated list of disks" 852 " indices to act on (e.g. 0,2) (optional," 853 " defaults to all disks)") 854 855 OS_SIZE_OPT = cli_option("-s", "--os-size", dest="sd_size", 856 help="Enforces a single-disk configuration using the" 857 " given disk size, in MiB unless a suffix is used", 858 default=None, type="unit", metavar="<size>") 859 860 IGNORE_CONSIST_OPT = cli_option("--ignore-consistency", 861 dest="ignore_consistency", 862 action="store_true", default=False, 863 help="Ignore the consistency of the disks on" 864 " the secondary") 865 866 IGNORE_HVVERSIONS_OPT = cli_option("--ignore-hvversions", 867 dest="ignore_hvversions", 868 action="store_true", default=False, 869 help="Ignore imcompatible hypervisor" 870 " versions between source and target") 871 872 ALLOW_FAILOVER_OPT = cli_option("--allow-failover", 873 dest="allow_failover", 874 action="store_true", default=False, 875 help="If migration is not possible fallback to" 876 " failover") 877 878 FORCE_FAILOVER_OPT = cli_option("--force-failover", 879 dest="force_failover", 880 action="store_true", default=False, 881 help="Do not use migration, always use" 882 " failover") 883 884 NONLIVE_OPT = cli_option("--non-live", dest="live", 885 default=True, action="store_false", 886 help="Do a non-live migration (this usually means" 887 " freeze the instance, save the state, transfer and" 888 " only then resume running on the secondary node)") 889 890 MIGRATION_MODE_OPT = cli_option("--migration-mode", dest="migration_mode", 891 default=None, 892 choices=list(constants.HT_MIGRATION_MODES), 893 help="Override default migration mode (choose" 894 " either live or non-live") 895 896 NODE_PLACEMENT_OPT = cli_option("-n", "--node", dest="node", 897 help="Target node and optional secondary node", 898 metavar="<pnode>[:<snode>]", 899 completion_suggest=OPT_COMPL_INST_ADD_NODES) 900 901 NODE_LIST_OPT = cli_option("-n", "--node", dest="nodes", default=[], 902 action="append", metavar="<node>", 903 help="Use only this node (can be used multiple" 904 " times, if not given defaults to all nodes)", 905 completion_suggest=OPT_COMPL_ONE_NODE) 906 907 NODEGROUP_OPT_NAME = "--node-group" 908 NODEGROUP_OPT = cli_option("-g", NODEGROUP_OPT_NAME, 909 dest="nodegroup", 910 help="Node group (name or uuid)", 911 metavar="<nodegroup>", 912 default=None, type="string", 913 completion_suggest=OPT_COMPL_ONE_NODEGROUP) 914 915 SINGLE_NODE_OPT = cli_option("-n", "--node", dest="node", help="Target node", 916 metavar="<node>", 917 completion_suggest=OPT_COMPL_ONE_NODE) 918 919 NOSTART_OPT = cli_option("--no-start", dest="start", default=True, 920 action="store_false", 921 help="Don't start the instance after creation") 922 923 FORTHCOMING_OPT = cli_option("--forthcoming", dest="forthcoming", 924 action="store_true", default=False, 925 help="Only reserve resources, but do not" 926 " create the instance yet") 927 928 COMMIT_OPT = cli_option("--commit", dest="commit", 929 action="store_true", default=False, 930 help="The instance is already reserved and should" 931 " be committed now") 932 933 SHOWCMD_OPT = cli_option("--show-cmd", dest="show_command", 934 action="store_true", default=False, 935 help="Show command instead of executing it") 936 937 CLEANUP_OPT = cli_option("--cleanup", dest="cleanup", 938 default=False, action="store_true", 939 help="Instead of performing the migration/failover," 940 " try to recover from a failed cleanup. This is safe" 941 " to run even if the instance is healthy, but it" 942 " will create extra replication traffic and " 943 " disrupt briefly the replication (like during the" 944 " migration/failover") 945 946 STATIC_OPT = cli_option("-s", "--static", dest="static", 947 action="store_true", default=False, 948 help="Only show configuration data, not runtime data") 949 950 ALL_OPT = cli_option("--all", dest="show_all", 951 default=False, action="store_true", 952 help="Show info on all instances on the cluster." 953 " This can take a long time to run, use wisely") 954 955 SELECT_OS_OPT = cli_option("--select-os", dest="select_os", 956 action="store_true", default=False, 957 help="Interactive OS reinstall, lists available" 958 " OS templates for selection") 959 960 IGNORE_FAILURES_OPT = cli_option("--ignore-failures", dest="ignore_failures", 961 action="store_true", default=False, 962 help="Remove the instance from the cluster" 963 " configuration even if there are failures" 964 " during the removal process") 965 966 IGNORE_REMOVE_FAILURES_OPT = cli_option("--ignore-remove-failures", 967 dest="ignore_remove_failures", 968 action="store_true", default=False, 969 help="Remove the instance from the" 970 " cluster configuration even if there" 971 " are failures during the removal" 972 " process") 973 974 REMOVE_INSTANCE_OPT = cli_option("--remove-instance", dest="remove_instance", 975 action="store_true", default=False, 976 help="Remove the instance from the cluster") 977 978 DST_NODE_OPT = cli_option("-n", "--target-node", dest="dst_node", 979 help="Specifies the new node for the instance", 980 metavar="NODE", default=None, 981 completion_suggest=OPT_COMPL_ONE_NODE) 982 983 NEW_SECONDARY_OPT = cli_option("-n", "--new-secondary", dest="dst_node", 984 help="Specifies the new secondary node", 985 metavar="NODE", default=None, 986 completion_suggest=OPT_COMPL_ONE_NODE) 987 988 NEW_PRIMARY_OPT = cli_option("--new-primary", dest="new_primary_node", 989 help="Specifies the new primary node", 990 metavar="<node>", default=None, 991 completion_suggest=OPT_COMPL_ONE_NODE) 992 993 ON_PRIMARY_OPT = cli_option("-p", "--on-primary", dest="on_primary", 994 default=False, action="store_true", 995 help="Replace the disk(s) on the primary" 996 " node (applies only to internally mirrored" 997 " disk templates, e.g. %s)" % 998 utils.CommaJoin(constants.DTS_INT_MIRROR)) 999 1000 ON_SECONDARY_OPT = cli_option("-s", "--on-secondary", dest="on_secondary", 1001 default=False, action="store_true", 1002 help="Replace the disk(s) on the secondary" 1003 " node (applies only to internally mirrored" 1004 " disk templates, e.g. %s)" % 1005 utils.CommaJoin(constants.DTS_INT_MIRROR)) 1006 1007 AUTO_PROMOTE_OPT = cli_option("--auto-promote", dest="auto_promote", 1008 default=False, action="store_true", 1009 help="Lock all nodes and auto-promote as needed" 1010 " to MC status") 1011 1012 AUTO_REPLACE_OPT = cli_option("-a", "--auto", dest="auto", 1013 default=False, action="store_true", 1014 help="Automatically replace faulty disks" 1015 " (applies only to internally mirrored" 1016 " disk templates, e.g. %s)" % 1017 utils.CommaJoin(constants.DTS_INT_MIRROR)) 1018 1019 IGNORE_SIZE_OPT = cli_option("--ignore-size", dest="ignore_size", 1020 default=False, action="store_true", 1021 help="Ignore current recorded size" 1022 " (useful for forcing activation when" 1023 " the recorded size is wrong)") 1024 1025 SRC_NODE_OPT = cli_option("--src-node", dest="src_node", help="Source node", 1026 metavar="<node>", 1027 completion_suggest=OPT_COMPL_ONE_NODE) 1028 1029 SRC_DIR_OPT = cli_option("--src-dir", dest="src_dir", help="Source directory", 1030 metavar="<dir>") 1031 1032 SECONDARY_IP_OPT = cli_option("-s", "--secondary-ip", dest="secondary_ip", 1033 help="Specify the secondary ip for the node", 1034 metavar="ADDRESS", default=None) 1035 1036 READD_OPT = cli_option("--readd", dest="readd", 1037 default=False, action="store_true", 1038 help="Readd old node after replacing it") 1039 1040 NOSSH_KEYCHECK_OPT = cli_option("--no-ssh-key-check", dest="ssh_key_check", 1041 default=True, action="store_false", 1042 help="Disable SSH key fingerprint checking") 1043 1044 NODE_FORCE_JOIN_OPT = cli_option("--force-join", dest="force_join", 1045 default=False, action="store_true", 1046 help="Force the joining of a node") 1047 1048 MC_OPT = cli_option("-C", "--master-candidate", dest="master_candidate", 1049 type="bool", default=None, metavar=_YORNO, 1050 help="Set the master_candidate flag on the node") 1051 1052 OFFLINE_OPT = cli_option("-O", "--offline", dest="offline", metavar=_YORNO, 1053 type="bool", default=None, 1054 help=("Set the offline flag on the node" 1055 " (cluster does not communicate with offline" 1056 " nodes)")) 1057 1058 DRAINED_OPT = cli_option("-D", "--drained", dest="drained", metavar=_YORNO, 1059 type="bool", default=None, 1060 help=("Set the drained flag on the node" 1061 " (excluded from allocation operations)")) 1062 1063 CAPAB_MASTER_OPT = cli_option("--master-capable", dest="master_capable", 1064 type="bool", default=None, metavar=_YORNO, 1065 help="Set the master_capable flag on the node") 1066 1067 CAPAB_VM_OPT = cli_option("--vm-capable", dest="vm_capable", 1068 type="bool", default=None, metavar=_YORNO, 1069 help="Set the vm_capable flag on the node") 1070 1071 ALLOCATABLE_OPT = cli_option("--allocatable", dest="allocatable", 1072 type="bool", default=None, metavar=_YORNO, 1073 help="Set the allocatable flag on a volume") 1074 1075 ENABLED_HV_OPT = cli_option("--enabled-hypervisors", 1076 dest="enabled_hypervisors", 1077 help="Comma-separated list of hypervisors", 1078 type="string", default=None) 1079 1080 ENABLED_DISK_TEMPLATES_OPT = cli_option("--enabled-disk-templates", 1081 dest="enabled_disk_templates", 1082 help="Comma-separated list of " 1083 "disk templates", 1084 type="string", default=None) 1085 1086 ENABLED_USER_SHUTDOWN_OPT = cli_option("--user-shutdown", 1087 default=None, 1088 dest="enabled_user_shutdown", 1089 help="Whether user shutdown is enabled", 1090 type="bool") 1091 1092 NIC_PARAMS_OPT = cli_option("-N", "--nic-parameters", dest="nicparams", 1093 type="keyval", default={}, 1094 help="NIC parameters") 1095 1096 CP_SIZE_OPT = cli_option("-C", "--candidate-pool-size", default=None, 1097 dest="candidate_pool_size", type="int", 1098 help="Set the candidate pool size") 1099 1100 RQL_OPT = cli_option("--max-running-jobs", dest="max_running_jobs", 1101 type="int", help="Set the maximal number of jobs to " 1102 "run simultaneously") 1103 1104 MAX_TRACK_OPT = cli_option("--max-tracked-jobs", dest="max_tracked_jobs", 1105 type="int", help="Set the maximal number of jobs to " 1106 "be tracked simultaneously for " 1107 "scheduling") 1108 1109 COMPRESSION_TOOLS_OPT = \ 1110 cli_option("--compression-tools", 1111 dest="compression_tools", type="string", default=None, 1112 help="Comma-separated list of compression tools which are" 1113 " allowed to be used by Ganeti in various operations") 1114 1115 MAINT_INTERVAL_OPT = \ 1116 cli_option("--maintenance-interval", dest="maint_round_delay", type="int", 1117 default=None, help="Minimal time in seconds, the maintenance" 1118 " daemon waits between rounds") 1119 1120 MAINT_BALANCE_OPT = \ 1121 cli_option("--auto-balance-cluster", dest="maint_balance", type="bool", 1122 default=None, metavar=_YORNO, help="Whether the maintenance" 1123 " daemon should balance the cluster") 1124 1125 MAINT_BALANCE_THRESHOLD_OPT = \ 1126 cli_option("--auto-balance-threshold", dest="maint_balance_threshold", 1127 type="float", default=None, metavar="CLUSTERSCORE", 1128 help="Minimal gain for an auto-balancing step to be taken") 1129 1130 VG_NAME_OPT = cli_option("--vg-name", dest="vg_name", 1131 help=("Enables LVM and specifies the volume group" 1132 " name (cluster-wide) for disk allocation" 1133 " [%s]" % constants.DEFAULT_VG), 1134 metavar="VG", default=None) 1135 1136 YES_DOIT_OPT = cli_option("--yes-do-it", "--ya-rly", dest="yes_do_it", 1137 help="Destroy cluster", action="store_true") 1138 1139 NOVOTING_OPT = cli_option("--no-voting", dest="no_voting", 1140 help="Skip node agreement check (dangerous)", 1141 action="store_true", default=False) 1142 1143 MAC_PREFIX_OPT = cli_option("-m", "--mac-prefix", dest="mac_prefix", 1144 help="Specify the mac prefix for the instance IP" 1145 " addresses, in the format XX:XX:XX", 1146 metavar="PREFIX", 1147 default=None) 1148 1149 MASTER_NETDEV_OPT = cli_option("--master-netdev", dest="master_netdev", 1150 help="Specify the node interface (cluster-wide)" 1151 " on which the master IP address will be added" 1152 " (cluster init default: %s)" % 1153 constants.DEFAULT_BRIDGE, 1154 metavar="NETDEV", 1155 default=None) 1156 1157 MASTER_NETMASK_OPT = cli_option("--master-netmask", dest="master_netmask", 1158 help="Specify the netmask of the master IP", 1159 metavar="NETMASK", 1160 default=None) 1161 1162 USE_EXTERNAL_MIP_SCRIPT = cli_option("--use-external-mip-script", 1163 dest="use_external_mip_script", 1164 help="Specify whether to run a" 1165 " user-provided script for the master" 1166 " IP address turnup and" 1167 " turndown operations", 1168 type="bool", metavar=_YORNO, default=None) 1169 1170 GLOBAL_FILEDIR_OPT = cli_option("--file-storage-dir", dest="file_storage_dir", 1171 help="Specify the default directory (cluster-" 1172 "wide) for storing the file-based disks [%s]" % 1173 pathutils.DEFAULT_FILE_STORAGE_DIR, 1174 metavar="DIR", 1175 default=None) 1176 1177 GLOBAL_SHARED_FILEDIR_OPT = cli_option( 1178 "--shared-file-storage-dir", 1179 dest="shared_file_storage_dir", 1180 help="Specify the default directory (cluster-wide) for storing the" 1181 " shared file-based disks [%s]" % 1182 pathutils.DEFAULT_SHARED_FILE_STORAGE_DIR, 1183 metavar="SHAREDDIR", default=None) 1184 1185 GLOBAL_GLUSTER_FILEDIR_OPT = cli_option( 1186 "--gluster-storage-dir", 1187 dest="gluster_storage_dir", 1188 help="Specify the default directory (cluster-wide) for mounting Gluster" 1189 " file systems [%s]" % 1190 pathutils.DEFAULT_GLUSTER_STORAGE_DIR, 1191 metavar="GLUSTERDIR", 1192 default=pathutils.DEFAULT_GLUSTER_STORAGE_DIR) 1193 1194 NOMODIFY_ETCHOSTS_OPT = cli_option("--no-etc-hosts", dest="modify_etc_hosts", 1195 help="Don't modify %s" % pathutils.ETC_HOSTS, 1196 action="store_false", default=True) 1197 1198 MODIFY_ETCHOSTS_OPT = \ 1199 cli_option("--modify-etc-hosts", dest="modify_etc_hosts", metavar=_YORNO, 1200 default=None, type="bool", 1201 help="Defines whether the cluster should autonomously modify" 1202 " and keep in sync the /etc/hosts file of the nodes") 1203 1204 NOMODIFY_SSH_SETUP_OPT = cli_option("--no-ssh-init", dest="modify_ssh_setup", 1205 help="Don't initialize SSH keys", 1206 action="store_false", default=True) 1207 1208 ERROR_CODES_OPT = cli_option("--error-codes", dest="error_codes", 1209 help="Enable parseable error messages", 1210 action="store_true", default=False) 1211 1212 NONPLUS1_OPT = cli_option("--no-nplus1-mem", dest="skip_nplusone_mem", 1213 help="Skip N+1 memory redundancy tests", 1214 action="store_true", default=False) 1215 1216 REBOOT_TYPE_OPT = cli_option("-t", "--type", dest="reboot_type", 1217 help="Type of reboot: soft/hard/full", 1218 default=constants.INSTANCE_REBOOT_HARD, 1219 metavar="<REBOOT>", 1220 choices=list(constants.REBOOT_TYPES)) 1221 1222 IGNORE_SECONDARIES_OPT = cli_option("--ignore-secondaries", 1223 dest="ignore_secondaries", 1224 default=False, action="store_true", 1225 help="Ignore errors from secondaries") 1226 1227 NOSHUTDOWN_OPT = cli_option("--noshutdown", dest="shutdown", 1228 action="store_false", default=True, 1229 help="Don't shutdown the instance (unsafe)") 1230 1231 TIMEOUT_OPT = cli_option("--timeout", dest="timeout", type="int", 1232 default=constants.DEFAULT_SHUTDOWN_TIMEOUT, 1233 help="Maximum time to wait") 1234 1235 COMPRESS_OPT = cli_option("--compress", dest="compress", 1236 type="string", default=constants.IEC_NONE, 1237 help="The compression mode to use") 1238 1239 TRANSPORT_COMPRESSION_OPT = \ 1240 cli_option("--transport-compression", dest="transport_compression", 1241 type="string", default=constants.IEC_NONE, 1242 help="The compression mode to use during transport") 1243 1244 SHUTDOWN_TIMEOUT_OPT = cli_option("--shutdown-timeout", 1245 dest="shutdown_timeout", type="int", 1246 default=constants.DEFAULT_SHUTDOWN_TIMEOUT, 1247 help="Maximum time to wait for instance" 1248 " shutdown") 1249 1250 INTERVAL_OPT = cli_option("--interval", dest="interval", type="int", 1251 default=None, 1252 help=("Number of seconds between repetions of the" 1253 " command")) 1254 1255 EARLY_RELEASE_OPT = cli_option("--early-release", 1256 dest="early_release", default=False, 1257 action="store_true", 1258 help="Release the locks on the secondary" 1259 " node(s) early") 1260 1261 NEW_CLUSTER_CERT_OPT = cli_option("--new-cluster-certificate", 1262 dest="new_cluster_cert", 1263 default=False, action="store_true", 1264 help="Generate a new cluster certificate") 1265 1266 NEW_NODE_CERT_OPT = cli_option( 1267 "--new-node-certificates", dest="new_node_cert", default=False, 1268 action="store_true", help="Generate new node certificates (for all nodes)") 1269 1270 NEW_SSH_KEY_OPT = cli_option( 1271 "--new-ssh-keys", dest="new_ssh_keys", default=False, 1272 action="store_true", help="Generate new node SSH keys (for all nodes)") 1273 1274 RAPI_CERT_OPT = cli_option("--rapi-certificate", dest="rapi_cert", 1275 default=None, 1276 help="File containing new RAPI certificate") 1277 1278 NEW_RAPI_CERT_OPT = cli_option("--new-rapi-certificate", dest="new_rapi_cert", 1279 default=None, action="store_true", 1280 help=("Generate a new self-signed RAPI" 1281 " certificate")) 1282 1283 SPICE_CERT_OPT = cli_option("--spice-certificate", dest="spice_cert", 1284 default=None, 1285 help="File containing new SPICE certificate") 1286 1287 SPICE_CACERT_OPT = cli_option("--spice-ca-certificate", dest="spice_cacert", 1288 default=None, 1289 help="File containing the certificate of the CA" 1290 " which signed the SPICE certificate") 1291 1292 NEW_SPICE_CERT_OPT = cli_option("--new-spice-certificate", 1293 dest="new_spice_cert", default=None, 1294 action="store_true", 1295 help=("Generate a new self-signed SPICE" 1296 " certificate")) 1297 1298 NEW_CONFD_HMAC_KEY_OPT = cli_option("--new-confd-hmac-key", 1299 dest="new_confd_hmac_key", 1300 default=False, action="store_true", 1301 help=("Create a new HMAC key for %s" % 1302 constants.CONFD)) 1303 1304 CLUSTER_DOMAIN_SECRET_OPT = cli_option("--cluster-domain-secret", 1305 dest="cluster_domain_secret", 1306 default=None, 1307 help=("Load new new cluster domain" 1308 " secret from file")) 1309 1310 NEW_CLUSTER_DOMAIN_SECRET_OPT = cli_option("--new-cluster-domain-secret", 1311 dest="new_cluster_domain_secret", 1312 default=False, action="store_true", 1313 help=("Create a new cluster domain" 1314 " secret")) 1315 1316 USE_REPL_NET_OPT = cli_option("--use-replication-network", 1317 dest="use_replication_network", 1318 help="Whether to use the replication network" 1319 " for talking to the nodes", 1320 action="store_true", default=False) 1321 1322 MAINTAIN_NODE_HEALTH_OPT = \ 1323 cli_option("--maintain-node-health", dest="maintain_node_health", 1324 metavar=_YORNO, default=None, type="bool", 1325 help="Configure the cluster to automatically maintain node" 1326 " health, by shutting down unknown instances, shutting down" 1327 " unknown DRBD devices, etc.") 1328 1329 IDENTIFY_DEFAULTS_OPT = \ 1330 cli_option("--identify-defaults", dest="identify_defaults", 1331 default=False, action="store_true", 1332 help="Identify which saved instance parameters are equal to" 1333 " the current cluster defaults and set them as such, instead" 1334 " of marking them as overridden") 1335 1336 UIDPOOL_OPT = cli_option("--uid-pool", default=None, 1337 action="store", dest="uid_pool", 1338 help=("A list of user-ids or user-id" 1339 " ranges separated by commas")) 1340 1341 ADD_UIDS_OPT = cli_option("--add-uids", default=None, 1342 action="store", dest="add_uids", 1343 help=("A list of user-ids or user-id" 1344 " ranges separated by commas, to be" 1345 " added to the user-id pool")) 1346 1347 REMOVE_UIDS_OPT = cli_option("--remove-uids", default=None, 1348 action="store", dest="remove_uids", 1349 help=("A list of user-ids or user-id" 1350 " ranges separated by commas, to be" 1351 " removed from the user-id pool")) 1352 1353 RESERVED_LVS_OPT = cli_option("--reserved-lvs", default=None, 1354 action="store", dest="reserved_lvs", 1355 help=("A comma-separated list of reserved" 1356 " logical volumes names, that will be" 1357 " ignored by cluster verify")) 1358 1359 ROMAN_OPT = cli_option("--roman", 1360 dest="roman_integers", default=False, 1361 action="store_true", 1362 help="Use roman numbers for positive integers") 1363 1364 DRBD_HELPER_OPT = cli_option("--drbd-usermode-helper", dest="drbd_helper", 1365 action="store", default=None, 1366 help="Specifies usermode helper for DRBD") 1367 1368 PRIMARY_IP_VERSION_OPT = \ 1369 cli_option("--primary-ip-version", default=constants.IP4_VERSION, 1370 action="store", dest="primary_ip_version", 1371 metavar="%d|%d" % (constants.IP4_VERSION, 1372 constants.IP6_VERSION), 1373 help="Cluster-wide IP version for primary IP") 1374 1375 SHOW_MACHINE_OPT = cli_option("-M", "--show-machine-names", default=False, 1376 action="store_true", 1377 help="Show machine name for every line in output") 1378 1379 FAILURE_ONLY_OPT = cli_option("--failure-only", default=False, 1380 action="store_true", 1381 help=("Hide successful results and show failures" 1382 " only (determined by the exit code)")) 1383 1384 REASON_OPT = cli_option("--reason", default=[], 1385 help="The reason for executing the command") 1386 1387
1388 -def _PriorityOptionCb(option, _, value, parser):
1389 """Callback for processing C{--priority} option. 1390 1391 """ 1392 value = _PRIONAME_TO_VALUE[value] 1393 1394 setattr(parser.values, option.dest, value)
1395 1396 1397 PRIORITY_OPT = cli_option("--priority", default=None, dest="priority", 1398 metavar="|".join(name for name, _ in _PRIORITY_NAMES), 1399 choices=_PRIONAME_TO_VALUE.keys(), 1400 action="callback", type="choice", 1401 callback=_PriorityOptionCb, 1402 help="Priority for opcode processing") 1403 1404 OPPORTUNISTIC_OPT = cli_option("--opportunistic-locking", 1405 dest="opportunistic_locking", 1406 action="store_true", default=False, 1407 help="Opportunistically acquire locks") 1408 1409 HID_OS_OPT = cli_option("--hidden", dest="hidden", 1410 type="bool", default=None, metavar=_YORNO, 1411 help="Sets the hidden flag on the OS") 1412 1413 BLK_OS_OPT = cli_option("--blacklisted", dest="blacklisted", 1414 type="bool", default=None, metavar=_YORNO, 1415 help="Sets the blacklisted flag on the OS") 1416 1417 PREALLOC_WIPE_DISKS_OPT = cli_option("--prealloc-wipe-disks", default=None, 1418 type="bool", metavar=_YORNO, 1419 dest="prealloc_wipe_disks", 1420 help=("Wipe disks prior to instance" 1421 " creation")) 1422 1423 NODE_PARAMS_OPT = cli_option("--node-parameters", dest="ndparams", 1424 type="keyval", default=None, 1425 help="Node parameters") 1426 1427 ALLOC_POLICY_OPT = cli_option("--alloc-policy", dest="alloc_policy", 1428 action="store", metavar="POLICY", default=None, 1429 help="Allocation policy for the node group") 1430 1431 NODE_POWERED_OPT = cli_option("--node-powered", default=None, 1432 type="bool", metavar=_YORNO, 1433 dest="node_powered", 1434 help="Specify if the SoR for node is powered") 1435 1436 OOB_TIMEOUT_OPT = cli_option("--oob-timeout", dest="oob_timeout", type="int", 1437 default=constants.OOB_TIMEOUT, 1438 help="Maximum time to wait for out-of-band helper") 1439 1440 POWER_DELAY_OPT = cli_option("--power-delay", dest="power_delay", type="float", 1441 default=constants.OOB_POWER_DELAY, 1442 help="Time in seconds to wait between power-ons") 1443 1444 FORCE_FILTER_OPT = cli_option("-F", "--filter", dest="force_filter", 1445 action="store_true", default=False, 1446 help=("Whether command argument should be treated" 1447 " as filter")) 1448 1449 NO_REMEMBER_OPT = cli_option("--no-remember", 1450 dest="no_remember", 1451 action="store_true", default=False, 1452 help="Perform but do not record the change" 1453 " in the configuration") 1454 1455 PRIMARY_ONLY_OPT = cli_option("-p", "--primary-only", 1456 default=False, action="store_true", 1457 help="Evacuate primary instances only") 1458 1459 SECONDARY_ONLY_OPT = cli_option("-s", "--secondary-only", 1460 default=False, action="store_true", 1461 help="Evacuate secondary instances only" 1462 " (applies only to internally mirrored" 1463 " disk templates, e.g. %s)" % 1464 utils.CommaJoin(constants.DTS_INT_MIRROR)) 1465 1466 STARTUP_PAUSED_OPT = cli_option("--paused", dest="startup_paused", 1467 action="store_true", default=False, 1468 help="Pause instance at startup") 1469 1470 TO_GROUP_OPT = cli_option("--to", dest="to", metavar="<group>", 1471 help="Destination node group (name or uuid)", 1472 default=None, action="append", 1473 completion_suggest=OPT_COMPL_ONE_NODEGROUP) 1474 1475 IGNORE_ERRORS_OPT = cli_option("-I", "--ignore-errors", default=[], 1476 action="append", dest="ignore_errors", 1477 choices=list(constants.CV_ALL_ECODES_STRINGS), 1478 help="Error code to be ignored") 1479 1480 DISK_STATE_OPT = cli_option("--disk-state", default=[], dest="disk_state", 1481 action="append", 1482 help=("Specify disk state information in the" 1483 " format" 1484 " storage_type/identifier:option=value,...;" 1485 " note this is unused for now"), 1486 type="identkeyval") 1487 1488 HV_STATE_OPT = cli_option("--hypervisor-state", default=[], dest="hv_state", 1489 action="append", 1490 help=("Specify hypervisor state information in the" 1491 " format hypervisor:option=value,...;" 1492 " note this is unused for now"), 1493 type="identkeyval") 1494 1495 IGNORE_IPOLICY_OPT = cli_option("--ignore-ipolicy", dest="ignore_ipolicy", 1496 action="store_true", default=False, 1497 help="Ignore instance policy violations") 1498 1499 RUNTIME_MEM_OPT = cli_option("-m", "--runtime-memory", dest="runtime_mem", 1500 help="Sets the instance's runtime memory," 1501 " ballooning it up or down to the new value", 1502 default=None, type="unit", metavar="<size>") 1503 1504 ABSOLUTE_OPT = cli_option("--absolute", dest="absolute", 1505 action="store_true", default=False, 1506 help="Marks the grow as absolute instead of the" 1507 " (default) relative mode") 1508 1509 NETWORK_OPT = cli_option("--network", 1510 action="store", default=None, dest="network", 1511 help="IP network in CIDR notation") 1512 1513 GATEWAY_OPT = cli_option("--gateway", 1514 action="store", default=None, dest="gateway", 1515 help="IP address of the router (gateway)") 1516 1517 ADD_RESERVED_IPS_OPT = cli_option("--add-reserved-ips", 1518 action="store", default=None, 1519 dest="add_reserved_ips", 1520 help="Comma-separated list of" 1521 " reserved IPs to add") 1522 1523 REMOVE_RESERVED_IPS_OPT = cli_option("--remove-reserved-ips", 1524 action="store", default=None, 1525 dest="remove_reserved_ips", 1526 help="Comma-delimited list of" 1527 " reserved IPs to remove") 1528 1529 NETWORK6_OPT = cli_option("--network6", 1530 action="store", default=None, dest="network6", 1531 help="IP network in CIDR notation") 1532 1533 GATEWAY6_OPT = cli_option("--gateway6", 1534 action="store", default=None, dest="gateway6", 1535 help="IP6 address of the router (gateway)") 1536 1537 NOCONFLICTSCHECK_OPT = cli_option("--no-conflicts-check", 1538 dest="conflicts_check", 1539 default=True, 1540 action="store_false", 1541 help="Don't check for conflicting IPs") 1542 1543 INCLUDEDEFAULTS_OPT = cli_option("--include-defaults", dest="include_defaults", 1544 default=False, action="store_true", 1545 help="Include default values") 1546 1547 HOTPLUG_OPT = cli_option("--hotplug", dest="hotplug", 1548 action="store_true", default=False, 1549 help="Hotplug supported devices (NICs and Disks)") 1550 1551 HOTPLUG_IF_POSSIBLE_OPT = cli_option("--hotplug-if-possible", 1552 dest="hotplug_if_possible", 1553 action="store_true", default=False, 1554 help="Hotplug devices in case" 1555 " hotplug is supported") 1556 1557 INSTALL_IMAGE_OPT = \ 1558 cli_option("--install-image", 1559 dest="install_image", 1560 action="store", 1561 type="string", 1562 default=None, 1563 help="The OS image to use for running the OS scripts safely") 1564 1565 INSTANCE_COMMUNICATION_OPT = \ 1566 cli_option("-c", "--communication", 1567 dest="instance_communication", 1568 help=constants.INSTANCE_COMMUNICATION_DOC, 1569 type="bool") 1570 1571 INSTANCE_COMMUNICATION_NETWORK_OPT = \ 1572 cli_option("--instance-communication-network", 1573 dest="instance_communication_network", 1574 type="string", 1575 help="Set the network name for instance communication") 1576 1577 ZEROING_IMAGE_OPT = \ 1578 cli_option("--zeroing-image", 1579 dest="zeroing_image", action="store", default=None, 1580 help="The OS image to use to zero instance disks") 1581 1582 ZERO_FREE_SPACE_OPT = \ 1583 cli_option("--zero-free-space", 1584 dest="zero_free_space", action="store_true", default=False, 1585 help="Whether to zero the free space on the disks of the " 1586 "instance prior to the export") 1587 1588 HELPER_STARTUP_TIMEOUT_OPT = \ 1589 cli_option("--helper-startup-timeout", 1590 dest="helper_startup_timeout", action="store", type="int", 1591 help="Startup timeout for the helper VM") 1592 1593 HELPER_SHUTDOWN_TIMEOUT_OPT = \ 1594 cli_option("--helper-shutdown-timeout", 1595 dest="helper_shutdown_timeout", action="store", type="int", 1596 help="Shutdown timeout for the helper VM") 1597 1598 ZEROING_TIMEOUT_FIXED_OPT = \ 1599 cli_option("--zeroing-timeout-fixed", 1600 dest="zeroing_timeout_fixed", action="store", type="int", 1601 help="The fixed amount of time to wait before assuming that the " 1602 "zeroing failed") 1603 1604 ZEROING_TIMEOUT_PER_MIB_OPT = \ 1605 cli_option("--zeroing-timeout-per-mib", 1606 dest="zeroing_timeout_per_mib", action="store", type="float", 1607 help="The amount of time to wait per MiB of data to zero, in " 1608 "addition to the fixed timeout") 1609 1610 ENABLED_DATA_COLLECTORS_OPT = \ 1611 cli_option("--enabled-data-collectors", 1612 dest="enabled_data_collectors", type="keyval", 1613 default={}, 1614 help="Deactivate or reactivate a data collector for reporting, " 1615 "in the format collector=bool, where collector is one of %s." 1616 % ", ".join(constants.DATA_COLLECTOR_NAMES)) 1617 1618 DIAGNOSE_DATA_COLLECTOR_FILENAME_OPT = \ 1619 cli_option("--diagnose-data-collector-filename", 1620 dest="diagnose_data_collector_filename", 1621 help=("Set's the file name of the script" 1622 " diagnose data collector should run" 1623 " If this value is empty string, the collector" 1624 " will return a success value" 1625 " without running anything"), 1626 type="string") 1627 1628 1629 VERIFY_CLUTTER_OPT = cli_option( 1630 "--verify-ssh-clutter", default=False, dest="verify_clutter", 1631 help="Verify that Ganeti did not clutter" 1632 " up the 'authorized_keys' file", action="store_true") 1633 1634 LONG_SLEEP_OPT = cli_option( 1635 "--long-sleep", default=False, dest="long_sleep", 1636 help="Allow long shutdowns when backing up instances", action="store_true") 1637 1638 INPUT_OPT = cli_option("--input", dest="input", default=None, 1639 help=("input to be passed as stdin" 1640 " to the repair command"), 1641 type="string") 1642 1643 SSH_KEY_TYPE_OPT = \ 1644 cli_option("--ssh-key-type", default=None, 1645 choices=list(constants.SSHK_ALL), dest="ssh_key_type", 1646 help="Type of SSH key deployed by Ganeti for cluster actions") 1647 1648 SSH_KEY_BITS_OPT = \ 1649 cli_option("--ssh-key-bits", default=None, 1650 type="int", dest="ssh_key_bits", 1651 help="Length of SSH keys generated by Ganeti, in bits") 1652 1653 1654 #: Options provided by all commands 1655 COMMON_OPTS = [DEBUG_OPT, REASON_OPT] 1656 1657 # options related to asynchronous job handling 1658 1659 SUBMIT_OPTS = [ 1660 SUBMIT_OPT, 1661 PRINT_JOBID_OPT, 1662 ] 1663 1664 # common options for creating instances. add and import then add their own 1665 # specific ones. 1666 COMMON_CREATE_OPTS = [ 1667 BACKEND_OPT, 1668 DISK_OPT, 1669 DISK_TEMPLATE_OPT, 1670 FILESTORE_DIR_OPT, 1671 FILESTORE_DRIVER_OPT, 1672 HYPERVISOR_OPT, 1673 IALLOCATOR_OPT, 1674 NET_OPT, 1675 NODE_PLACEMENT_OPT, 1676 NODEGROUP_OPT, 1677 NOIPCHECK_OPT, 1678 NOCONFLICTSCHECK_OPT, 1679 NONAMECHECK_OPT, 1680 NONICS_OPT, 1681 NWSYNC_OPT, 1682 OSPARAMS_OPT, 1683 OSPARAMS_PRIVATE_OPT, 1684 OSPARAMS_SECRET_OPT, 1685 OS_SIZE_OPT, 1686 OPPORTUNISTIC_OPT, 1687 SUBMIT_OPT, 1688 PRINT_JOBID_OPT, 1689 TAG_ADD_OPT, 1690 DRY_RUN_OPT, 1691 PRIORITY_OPT, 1692 ] 1693 1694 # common instance policy options 1695 INSTANCE_POLICY_OPTS = [ 1696 IPOLICY_BOUNDS_SPECS_OPT, 1697 IPOLICY_DISK_TEMPLATES, 1698 IPOLICY_VCPU_RATIO, 1699 IPOLICY_SPINDLE_RATIO, 1700 IPOLICY_MEMORY_RATIO, 1701 ] 1702 1703 # instance policy split specs options 1704 SPLIT_ISPECS_OPTS = [ 1705 SPECS_CPU_COUNT_OPT, 1706 SPECS_DISK_COUNT_OPT, 1707 SPECS_DISK_SIZE_OPT, 1708 SPECS_MEM_SIZE_OPT, 1709 SPECS_NIC_COUNT_OPT, 1710 ] 1711