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