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