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