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