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", default=None) 1192 1193 NOMODIFY_ETCHOSTS_OPT = cli_option("--no-etc-hosts", dest="modify_etc_hosts", 1194 help="Don't modify %s" % pathutils.ETC_HOSTS, 1195 action="store_false", default=True) 1196 1197 MODIFY_ETCHOSTS_OPT = \ 1198 cli_option("--modify-etc-hosts", dest="modify_etc_hosts", metavar=_YORNO, 1199 default=None, type="bool", 1200 help="Defines whether the cluster should autonomously modify" 1201 " and keep in sync the /etc/hosts file of the nodes") 1202 1203 NOMODIFY_SSH_SETUP_OPT = cli_option("--no-ssh-init", dest="modify_ssh_setup", 1204 help="Don't initialize SSH keys", 1205 action="store_false", default=True) 1206 1207 ERROR_CODES_OPT = cli_option("--error-codes", dest="error_codes", 1208 help="Enable parseable error messages", 1209 action="store_true", default=False) 1210 1211 NONPLUS1_OPT = cli_option("--no-nplus1-mem", dest="skip_nplusone_mem", 1212 help="Skip N+1 memory redundancy tests", 1213 action="store_true", default=False) 1214 1215 REBOOT_TYPE_OPT = cli_option("-t", "--type", dest="reboot_type", 1216 help="Type of reboot: soft/hard/full", 1217 default=constants.INSTANCE_REBOOT_HARD, 1218 metavar="<REBOOT>", 1219 choices=list(constants.REBOOT_TYPES)) 1220 1221 IGNORE_SECONDARIES_OPT = cli_option("--ignore-secondaries", 1222 dest="ignore_secondaries", 1223 default=False, action="store_true", 1224 help="Ignore errors from secondaries") 1225 1226 NOSHUTDOWN_OPT = cli_option("--noshutdown", dest="shutdown", 1227 action="store_false", default=True, 1228 help="Don't shutdown the instance (unsafe)") 1229 1230 TIMEOUT_OPT = cli_option("--timeout", dest="timeout", type="int", 1231 default=constants.DEFAULT_SHUTDOWN_TIMEOUT, 1232 help="Maximum time to wait") 1233 1234 COMPRESS_OPT = cli_option("--compress", dest="compress", 1235 type="string", default=constants.IEC_NONE, 1236 help="The compression mode to use") 1237 1238 TRANSPORT_COMPRESSION_OPT = \ 1239 cli_option("--transport-compression", dest="transport_compression", 1240 type="string", default=constants.IEC_NONE, 1241 help="The compression mode to use during transport") 1242 1243 SHUTDOWN_TIMEOUT_OPT = cli_option("--shutdown-timeout", 1244 dest="shutdown_timeout", type="int", 1245 default=constants.DEFAULT_SHUTDOWN_TIMEOUT, 1246 help="Maximum time to wait for instance" 1247 " shutdown") 1248 1249 INTERVAL_OPT = cli_option("--interval", dest="interval", type="int", 1250 default=None, 1251 help=("Number of seconds between repetions of the" 1252 " command")) 1253 1254 EARLY_RELEASE_OPT = cli_option("--early-release", 1255 dest="early_release", default=False, 1256 action="store_true", 1257 help="Release the locks on the secondary" 1258 " node(s) early") 1259 1260 NEW_CLUSTER_CERT_OPT = cli_option("--new-cluster-certificate", 1261 dest="new_cluster_cert", 1262 default=False, action="store_true", 1263 help="Generate a new cluster certificate") 1264 1265 NEW_NODE_CERT_OPT = cli_option( 1266 "--new-node-certificates", dest="new_node_cert", default=False, 1267 action="store_true", help="Generate new node certificates (for all nodes)") 1268 1269 NEW_SSH_KEY_OPT = cli_option( 1270 "--new-ssh-keys", dest="new_ssh_keys", default=False, 1271 action="store_true", help="Generate new node SSH keys (for all nodes)") 1272 1273 RAPI_CERT_OPT = cli_option("--rapi-certificate", dest="rapi_cert", 1274 default=None, 1275 help="File containing new RAPI certificate") 1276 1277 NEW_RAPI_CERT_OPT = cli_option("--new-rapi-certificate", dest="new_rapi_cert", 1278 default=None, action="store_true", 1279 help=("Generate a new self-signed RAPI" 1280 " certificate")) 1281 1282 SPICE_CERT_OPT = cli_option("--spice-certificate", dest="spice_cert", 1283 default=None, 1284 help="File containing new SPICE certificate") 1285 1286 SPICE_CACERT_OPT = cli_option("--spice-ca-certificate", dest="spice_cacert", 1287 default=None, 1288 help="File containing the certificate of the CA" 1289 " which signed the SPICE certificate") 1290 1291 NEW_SPICE_CERT_OPT = cli_option("--new-spice-certificate", 1292 dest="new_spice_cert", default=None, 1293 action="store_true", 1294 help=("Generate a new self-signed SPICE" 1295 " certificate")) 1296 1297 NEW_CONFD_HMAC_KEY_OPT = cli_option("--new-confd-hmac-key", 1298 dest="new_confd_hmac_key", 1299 default=False, action="store_true", 1300 help=("Create a new HMAC key for %s" % 1301 constants.CONFD)) 1302 1303 CLUSTER_DOMAIN_SECRET_OPT = cli_option("--cluster-domain-secret", 1304 dest="cluster_domain_secret", 1305 default=None, 1306 help=("Load new new cluster domain" 1307 " secret from file")) 1308 1309 NEW_CLUSTER_DOMAIN_SECRET_OPT = cli_option("--new-cluster-domain-secret", 1310 dest="new_cluster_domain_secret", 1311 default=False, action="store_true", 1312 help=("Create a new cluster domain" 1313 " secret")) 1314 1315 USE_REPL_NET_OPT = cli_option("--use-replication-network", 1316 dest="use_replication_network", 1317 help="Whether to use the replication network" 1318 " for talking to the nodes", 1319 action="store_true", default=False) 1320 1321 MAINTAIN_NODE_HEALTH_OPT = \ 1322 cli_option("--maintain-node-health", dest="maintain_node_health", 1323 metavar=_YORNO, default=None, type="bool", 1324 help="Configure the cluster to automatically maintain node" 1325 " health, by shutting down unknown instances, shutting down" 1326 " unknown DRBD devices, etc.") 1327 1328 IDENTIFY_DEFAULTS_OPT = \ 1329 cli_option("--identify-defaults", dest="identify_defaults", 1330 default=False, action="store_true", 1331 help="Identify which saved instance parameters are equal to" 1332 " the current cluster defaults and set them as such, instead" 1333 " of marking them as overridden") 1334 1335 UIDPOOL_OPT = cli_option("--uid-pool", default=None, 1336 action="store", dest="uid_pool", 1337 help=("A list of user-ids or user-id" 1338 " ranges separated by commas")) 1339 1340 ADD_UIDS_OPT = cli_option("--add-uids", default=None, 1341 action="store", dest="add_uids", 1342 help=("A list of user-ids or user-id" 1343 " ranges separated by commas, to be" 1344 " added to the user-id pool")) 1345 1346 REMOVE_UIDS_OPT = cli_option("--remove-uids", default=None, 1347 action="store", dest="remove_uids", 1348 help=("A list of user-ids or user-id" 1349 " ranges separated by commas, to be" 1350 " removed from the user-id pool")) 1351 1352 RESERVED_LVS_OPT = cli_option("--reserved-lvs", default=None, 1353 action="store", dest="reserved_lvs", 1354 help=("A comma-separated list of reserved" 1355 " logical volumes names, that will be" 1356 " ignored by cluster verify")) 1357 1358 ROMAN_OPT = cli_option("--roman", 1359 dest="roman_integers", default=False, 1360 action="store_true", 1361 help="Use roman numbers for positive integers") 1362 1363 DRBD_HELPER_OPT = cli_option("--drbd-usermode-helper", dest="drbd_helper", 1364 action="store", default=None, 1365 help="Specifies usermode helper for DRBD") 1366 1367 PRIMARY_IP_VERSION_OPT = \ 1368 cli_option("--primary-ip-version", default=constants.IP4_VERSION, 1369 action="store", dest="primary_ip_version", 1370 metavar="%d|%d" % (constants.IP4_VERSION, 1371 constants.IP6_VERSION), 1372 help="Cluster-wide IP version for primary IP") 1373 1374 SHOW_MACHINE_OPT = cli_option("-M", "--show-machine-names", default=False, 1375 action="store_true", 1376 help="Show machine name for every line in output") 1377 1378 FAILURE_ONLY_OPT = cli_option("--failure-only", default=False, 1379 action="store_true", 1380 help=("Hide successful results and show failures" 1381 " only (determined by the exit code)")) 1382 1383 REASON_OPT = cli_option("--reason", default=[], 1384 help="The reason for executing the command") 1385 1386
1387 -def _PriorityOptionCb(option, _, value, parser):
1388 """Callback for processing C{--priority} option. 1389 1390 """ 1391 value = _PRIONAME_TO_VALUE[value] 1392 1393 setattr(parser.values, option.dest, value)
1394 1395 1396 PRIORITY_OPT = cli_option("--priority", default=None, dest="priority", 1397 metavar="|".join(name for name, _ in _PRIORITY_NAMES), 1398 choices=_PRIONAME_TO_VALUE.keys(), 1399 action="callback", type="choice", 1400 callback=_PriorityOptionCb, 1401 help="Priority for opcode processing") 1402 1403 OPPORTUNISTIC_OPT = cli_option("--opportunistic-locking", 1404 dest="opportunistic_locking", 1405 action="store_true", default=False, 1406 help="Opportunistically acquire locks") 1407 1408 HID_OS_OPT = cli_option("--hidden", dest="hidden", 1409 type="bool", default=None, metavar=_YORNO, 1410 help="Sets the hidden flag on the OS") 1411 1412 BLK_OS_OPT = cli_option("--blacklisted", dest="blacklisted", 1413 type="bool", default=None, metavar=_YORNO, 1414 help="Sets the blacklisted flag on the OS") 1415 1416 PREALLOC_WIPE_DISKS_OPT = cli_option("--prealloc-wipe-disks", default=None, 1417 type="bool", metavar=_YORNO, 1418 dest="prealloc_wipe_disks", 1419 help=("Wipe disks prior to instance" 1420 " creation")) 1421 1422 NODE_PARAMS_OPT = cli_option("--node-parameters", dest="ndparams", 1423 type="keyval", default=None, 1424 help="Node parameters") 1425 1426 ALLOC_POLICY_OPT = cli_option("--alloc-policy", dest="alloc_policy", 1427 action="store", metavar="POLICY", default=None, 1428 help="Allocation policy for the node group") 1429 1430 NODE_POWERED_OPT = cli_option("--node-powered", default=None, 1431 type="bool", metavar=_YORNO, 1432 dest="node_powered", 1433 help="Specify if the SoR for node is powered") 1434 1435 OOB_TIMEOUT_OPT = cli_option("--oob-timeout", dest="oob_timeout", type="int", 1436 default=constants.OOB_TIMEOUT, 1437 help="Maximum time to wait for out-of-band helper") 1438 1439 POWER_DELAY_OPT = cli_option("--power-delay", dest="power_delay", type="float", 1440 default=constants.OOB_POWER_DELAY, 1441 help="Time in seconds to wait between power-ons") 1442 1443 FORCE_FILTER_OPT = cli_option("-F", "--filter", dest="force_filter", 1444 action="store_true", default=False, 1445 help=("Whether command argument should be treated" 1446 " as filter")) 1447 1448 NO_REMEMBER_OPT = cli_option("--no-remember", 1449 dest="no_remember", 1450 action="store_true", default=False, 1451 help="Perform but do not record the change" 1452 " in the configuration") 1453 1454 PRIMARY_ONLY_OPT = cli_option("-p", "--primary-only", 1455 default=False, action="store_true", 1456 help="Evacuate primary instances only") 1457 1458 SECONDARY_ONLY_OPT = cli_option("-s", "--secondary-only", 1459 default=False, action="store_true", 1460 help="Evacuate secondary instances only" 1461 " (applies only to internally mirrored" 1462 " disk templates, e.g. %s)" % 1463 utils.CommaJoin(constants.DTS_INT_MIRROR)) 1464 1465 STARTUP_PAUSED_OPT = cli_option("--paused", dest="startup_paused", 1466 action="store_true", default=False, 1467 help="Pause instance at startup") 1468 1469 TO_GROUP_OPT = cli_option("--to", dest="to", metavar="<group>", 1470 help="Destination node group (name or uuid)", 1471 default=None, action="append", 1472 completion_suggest=OPT_COMPL_ONE_NODEGROUP) 1473 1474 IGNORE_ERRORS_OPT = cli_option("-I", "--ignore-errors", default=[], 1475 action="append", dest="ignore_errors", 1476 choices=list(constants.CV_ALL_ECODES_STRINGS), 1477 help="Error code to be ignored") 1478 1479 DISK_STATE_OPT = cli_option("--disk-state", default=[], dest="disk_state", 1480 action="append", 1481 help=("Specify disk state information in the" 1482 " format" 1483 " storage_type/identifier:option=value,...;" 1484 " note this is unused for now"), 1485 type="identkeyval") 1486 1487 HV_STATE_OPT = cli_option("--hypervisor-state", default=[], dest="hv_state", 1488 action="append", 1489 help=("Specify hypervisor state information in the" 1490 " format hypervisor:option=value,...;" 1491 " note this is unused for now"), 1492 type="identkeyval") 1493 1494 IGNORE_IPOLICY_OPT = cli_option("--ignore-ipolicy", dest="ignore_ipolicy", 1495 action="store_true", default=False, 1496 help="Ignore instance policy violations") 1497 1498 RUNTIME_MEM_OPT = cli_option("-m", "--runtime-memory", dest="runtime_mem", 1499 help="Sets the instance's runtime memory," 1500 " ballooning it up or down to the new value", 1501 default=None, type="unit", metavar="<size>") 1502 1503 ABSOLUTE_OPT = cli_option("--absolute", dest="absolute", 1504 action="store_true", default=False, 1505 help="Marks the grow as absolute instead of the" 1506 " (default) relative mode") 1507 1508 NETWORK_OPT = cli_option("--network", 1509 action="store", default=None, dest="network", 1510 help="IP network in CIDR notation") 1511 1512 GATEWAY_OPT = cli_option("--gateway", 1513 action="store", default=None, dest="gateway", 1514 help="IP address of the router (gateway)") 1515 1516 ADD_RESERVED_IPS_OPT = cli_option("--add-reserved-ips", 1517 action="store", default=None, 1518 dest="add_reserved_ips", 1519 help="Comma-separated list of" 1520 " reserved IPs to add") 1521 1522 REMOVE_RESERVED_IPS_OPT = cli_option("--remove-reserved-ips", 1523 action="store", default=None, 1524 dest="remove_reserved_ips", 1525 help="Comma-delimited list of" 1526 " reserved IPs to remove") 1527 1528 NETWORK6_OPT = cli_option("--network6", 1529 action="store", default=None, dest="network6", 1530 help="IP network in CIDR notation") 1531 1532 GATEWAY6_OPT = cli_option("--gateway6", 1533 action="store", default=None, dest="gateway6", 1534 help="IP6 address of the router (gateway)") 1535 1536 NOCONFLICTSCHECK_OPT = cli_option("--no-conflicts-check", 1537 dest="conflicts_check", 1538 default=True, 1539 action="store_false", 1540 help="Don't check for conflicting IPs") 1541 1542 INCLUDEDEFAULTS_OPT = cli_option("--include-defaults", dest="include_defaults", 1543 default=False, action="store_true", 1544 help="Include default values") 1545 1546 HOTPLUG_OPT = cli_option("--hotplug", dest="hotplug", 1547 action="store_true", default=False, 1548 help="Hotplug supported devices (NICs and Disks)") 1549 1550 HOTPLUG_IF_POSSIBLE_OPT = cli_option("--hotplug-if-possible", 1551 dest="hotplug_if_possible", 1552 action="store_true", default=False, 1553 help="Hotplug devices in case" 1554 " hotplug is supported") 1555 1556 INSTALL_IMAGE_OPT = \ 1557 cli_option("--install-image", 1558 dest="install_image", 1559 action="store", 1560 type="string", 1561 default=None, 1562 help="The OS image to use for running the OS scripts safely") 1563 1564 INSTANCE_COMMUNICATION_OPT = \ 1565 cli_option("-c", "--communication", 1566 dest="instance_communication", 1567 help=constants.INSTANCE_COMMUNICATION_DOC, 1568 type="bool") 1569 1570 INSTANCE_COMMUNICATION_NETWORK_OPT = \ 1571 cli_option("--instance-communication-network", 1572 dest="instance_communication_network", 1573 type="string", 1574 help="Set the network name for instance communication") 1575 1576 ZEROING_IMAGE_OPT = \ 1577 cli_option("--zeroing-image", 1578 dest="zeroing_image", action="store", default=None, 1579 help="The OS image to use to zero instance disks") 1580 1581 ZERO_FREE_SPACE_OPT = \ 1582 cli_option("--zero-free-space", 1583 dest="zero_free_space", action="store_true", default=False, 1584 help="Whether to zero the free space on the disks of the " 1585 "instance prior to the export") 1586 1587 HELPER_STARTUP_TIMEOUT_OPT = \ 1588 cli_option("--helper-startup-timeout", 1589 dest="helper_startup_timeout", action="store", type="int", 1590 help="Startup timeout for the helper VM") 1591 1592 HELPER_SHUTDOWN_TIMEOUT_OPT = \ 1593 cli_option("--helper-shutdown-timeout", 1594 dest="helper_shutdown_timeout", action="store", type="int", 1595 help="Shutdown timeout for the helper VM") 1596 1597 ZEROING_TIMEOUT_FIXED_OPT = \ 1598 cli_option("--zeroing-timeout-fixed", 1599 dest="zeroing_timeout_fixed", action="store", type="int", 1600 help="The fixed amount of time to wait before assuming that the " 1601 "zeroing failed") 1602 1603 ZEROING_TIMEOUT_PER_MIB_OPT = \ 1604 cli_option("--zeroing-timeout-per-mib", 1605 dest="zeroing_timeout_per_mib", action="store", type="float", 1606 help="The amount of time to wait per MiB of data to zero, in " 1607 "addition to the fixed timeout") 1608 1609 ENABLED_DATA_COLLECTORS_OPT = \ 1610 cli_option("--enabled-data-collectors", 1611 dest="enabled_data_collectors", type="keyval", 1612 default={}, 1613 help="Deactivate or reactivate a data collector for reporting, " 1614 "in the format collector=bool, where collector is one of %s." 1615 % ", ".join(constants.DATA_COLLECTOR_NAMES)) 1616 1617 DIAGNOSE_DATA_COLLECTOR_FILENAME_OPT = \ 1618 cli_option("--diagnose-data-collector-filename", 1619 dest="diagnose_data_collector_filename", 1620 help=("Set's the file name of the script" 1621 " diagnose data collector should run" 1622 " If this value is empty string, the collector" 1623 " will return a success value" 1624 " without running anything"), 1625 type="string") 1626 1627 1628 VERIFY_CLUTTER_OPT = cli_option( 1629 "--verify-ssh-clutter", default=False, dest="verify_clutter", 1630 help="Verify that Ganeti did not clutter" 1631 " up the 'authorized_keys' file", action="store_true") 1632 1633 LONG_SLEEP_OPT = cli_option( 1634 "--long-sleep", default=False, dest="long_sleep", 1635 help="Allow long shutdowns when backing up instances", action="store_true") 1636 1637 INPUT_OPT = cli_option("--input", dest="input", default=None, 1638 help=("input to be passed as stdin" 1639 " to the repair command"), 1640 type="string") 1641 1642 SSH_KEY_TYPE_OPT = \ 1643 cli_option("--ssh-key-type", default=None, 1644 choices=list(constants.SSHK_ALL), dest="ssh_key_type", 1645 help="Type of SSH key deployed by Ganeti for cluster actions") 1646 1647 SSH_KEY_BITS_OPT = \ 1648 cli_option("--ssh-key-bits", default=None, 1649 type="int", dest="ssh_key_bits", 1650 help="Length of SSH keys generated by Ganeti, in bits") 1651 1652 1653 #: Options provided by all commands 1654 COMMON_OPTS = [DEBUG_OPT, REASON_OPT] 1655 1656 # options related to asynchronous job handling 1657 1658 SUBMIT_OPTS = [ 1659 SUBMIT_OPT, 1660 PRINT_JOBID_OPT, 1661 ] 1662 1663 # common options for creating instances. add and import then add their own 1664 # specific ones. 1665 COMMON_CREATE_OPTS = [ 1666 BACKEND_OPT, 1667 DISK_OPT, 1668 DISK_TEMPLATE_OPT, 1669 FILESTORE_DIR_OPT, 1670 FILESTORE_DRIVER_OPT, 1671 HYPERVISOR_OPT, 1672 IALLOCATOR_OPT, 1673 NET_OPT, 1674 NODE_PLACEMENT_OPT, 1675 NODEGROUP_OPT, 1676 NOIPCHECK_OPT, 1677 NOCONFLICTSCHECK_OPT, 1678 NONAMECHECK_OPT, 1679 NONICS_OPT, 1680 NWSYNC_OPT, 1681 OSPARAMS_OPT, 1682 OSPARAMS_PRIVATE_OPT, 1683 OSPARAMS_SECRET_OPT, 1684 OS_SIZE_OPT, 1685 OPPORTUNISTIC_OPT, 1686 SUBMIT_OPT, 1687 PRINT_JOBID_OPT, 1688 TAG_ADD_OPT, 1689 DRY_RUN_OPT, 1690 PRIORITY_OPT, 1691 ] 1692 1693 # common instance policy options 1694 INSTANCE_POLICY_OPTS = [ 1695 IPOLICY_BOUNDS_SPECS_OPT, 1696 IPOLICY_DISK_TEMPLATES, 1697 IPOLICY_VCPU_RATIO, 1698 IPOLICY_SPINDLE_RATIO, 1699 IPOLICY_MEMORY_RATIO, 1700 ] 1701 1702 # instance policy split specs options 1703 SPLIT_ISPECS_OPTS = [ 1704 SPECS_CPU_COUNT_OPT, 1705 SPECS_DISK_COUNT_OPT, 1706 SPECS_DISK_SIZE_OPT, 1707 SPECS_MEM_SIZE_OPT, 1708 SPECS_NIC_COUNT_OPT, 1709 ] 1710