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