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