4 # Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012 Google Inc.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 This module implements the data structures which define the cluster
25 operations - the so-called opcodes.
27 Every operation which modifies the cluster state is expressed via
32 # this are practically structures, so disable the message about too
34 # pylint: disable=R0903
39 from ganeti import constants
40 from ganeti import errors
42 from ganeti import objects
43 from ganeti import objectutils
46 # Common opcode attributes
48 #: output fields for a query operation
49 _POutputFields = ("output_fields", ht.NoDefault, ht.TListOf(ht.TNonEmptyString),
50 "Selected output fields")
52 #: the shutdown timeout
54 ("shutdown_timeout", constants.DEFAULT_SHUTDOWN_TIMEOUT, ht.TPositiveInt,
55 "How long to wait for instance to shut down")
57 #: the force parameter
58 _PForce = ("force", False, ht.TBool, "Whether to force the operation")
60 #: a required instance name (for single-instance LUs)
61 _PInstanceName = ("instance_name", ht.NoDefault, ht.TNonEmptyString,
64 #: Whether to ignore offline nodes
65 _PIgnoreOfflineNodes = ("ignore_offline_nodes", False, ht.TBool,
66 "Whether to ignore offline nodes")
68 #: a required node name (for single-node LUs)
69 _PNodeName = ("node_name", ht.NoDefault, ht.TNonEmptyString, "Node name")
71 #: a required node group name (for single-group LUs)
72 _PGroupName = ("group_name", ht.NoDefault, ht.TNonEmptyString, "Group name")
74 #: Migration type (live/non-live)
75 _PMigrationMode = ("mode", None,
76 ht.TOr(ht.TNone, ht.TElemOf(constants.HT_MIGRATION_MODES)),
79 #: Obsolete 'live' migration mode (boolean)
80 _PMigrationLive = ("live", None, ht.TMaybeBool,
81 "Legacy setting for live migration, do not use")
84 _PTagKind = ("kind", ht.NoDefault, ht.TElemOf(constants.VALID_TAG_TYPES),
87 #: List of tag strings
88 _PTags = ("tags", ht.NoDefault, ht.TListOf(ht.TNonEmptyString),
91 _PForceVariant = ("force_variant", False, ht.TBool,
92 "Whether to force an unknown OS variant")
94 _PWaitForSync = ("wait_for_sync", True, ht.TBool,
95 "Whether to wait for the disk to synchronize")
97 _PWaitForSyncFalse = ("wait_for_sync", False, ht.TBool,
98 "Whether to wait for the disk to synchronize"
99 " (defaults to false)")
101 _PIgnoreConsistency = ("ignore_consistency", False, ht.TBool,
102 "Whether to ignore disk consistency")
104 _PStorageName = ("name", ht.NoDefault, ht.TMaybeString, "Storage name")
106 _PUseLocking = ("use_locking", False, ht.TBool,
107 "Whether to use synchronization")
109 _PNameCheck = ("name_check", True, ht.TBool, "Whether to check name")
111 _PNodeGroupAllocPolicy = \
112 ("alloc_policy", None,
113 ht.TOr(ht.TNone, ht.TElemOf(constants.VALID_ALLOC_POLICIES)),
114 "Instance allocation policy")
116 _PGroupNodeParams = ("ndparams", None, ht.TMaybeDict,
117 "Default node parameters for group")
119 _PQueryWhat = ("what", ht.NoDefault, ht.TElemOf(constants.QR_VIA_OP),
120 "Resource(s) to query for")
122 _PEarlyRelease = ("early_release", False, ht.TBool,
123 "Whether to release locks as soon as possible")
125 _PIpCheckDoc = "Whether to ensure instance's IP address is inactive"
127 #: Do not remember instance state changes
128 _PNoRemember = ("no_remember", False, ht.TBool,
129 "Do not remember the state change")
131 #: Target node for instance migration/failover
132 _PMigrationTargetNode = ("target_node", None, ht.TMaybeString,
133 "Target node for shared-storage instances")
135 _PStartupPaused = ("startup_paused", False, ht.TBool,
136 "Pause instance at startup")
138 _PVerbose = ("verbose", False, ht.TBool, "Verbose mode")
140 # Parameters for cluster verification
141 _PDebugSimulateErrors = ("debug_simulate_errors", False, ht.TBool,
142 "Whether to simulate errors (useful for debugging)")
143 _PErrorCodes = ("error_codes", False, ht.TBool, "Error codes")
144 _PSkipChecks = ("skip_checks", ht.EmptyList,
145 ht.TListOf(ht.TElemOf(constants.VERIFY_OPTIONAL_CHECKS)),
146 "Which checks to skip")
147 _PIgnoreErrors = ("ignore_errors", ht.EmptyList,
148 ht.TListOf(ht.TElemOf(constants.CV_ALL_ECODES_STRINGS)),
149 "List of error codes that should be treated as warnings")
152 _PDiskParams = ("diskparams", None,
154 ht.TDictOf(ht.TElemOf(constants.DISK_TEMPLATES), ht.TDict),
156 "Disk templates' parameter defaults")
158 # Parameters for node resource model
159 _PHvState = ("hv_state", None, ht.TMaybeDict, "Set hypervisor states")
160 _PDiskState = ("disk_state", None, ht.TMaybeDict, "Set disk states")
163 _PIgnoreIpolicy = ("ignore_ipolicy", False, ht.TBool,
164 "Whether to ignore ipolicy violations")
166 # Allow runtime changes while migrating
167 _PAllowRuntimeChgs = ("allow_runtime_changes", True, ht.TBool,
168 "Allow runtime changes (eg. memory ballooning)")
171 #: OP_ID conversion regular expression
172 _OPID_RE = re.compile("([a-z])([A-Z])")
174 #: Utility function for L{OpClusterSetParams}
175 _TestClusterOsListItem = \
176 ht.TAnd(ht.TIsLength(2), ht.TItems([
177 ht.TElemOf(constants.DDMS_VALUES),
181 _TestClusterOsList = ht.TMaybeListOf(_TestClusterOsListItem)
183 # TODO: Generate check from constants.INIC_PARAMS_TYPES
184 #: Utility function for testing NIC definitions
186 ht.Comment("NIC parameters")(ht.TDictOf(ht.TElemOf(constants.INIC_PARAMS),
187 ht.TOr(ht.TNone, ht.TNonEmptyString)))
189 _TSetParamsResultItemItems = [
190 ht.Comment("name of changed parameter")(ht.TNonEmptyString),
191 ht.Comment("new value")(ht.TAny),
194 _TSetParamsResult = \
195 ht.TListOf(ht.TAnd(ht.TIsLength(len(_TSetParamsResultItemItems)),
196 ht.TItems(_TSetParamsResultItemItems)))
198 # TODO: Generate check from constants.IDISK_PARAMS_TYPES (however, not all users
199 # of this check support all parameters)
201 ht.Comment("Disk parameters")(ht.TDictOf(ht.TElemOf(constants.IDISK_PARAMS),
202 ht.TOr(ht.TNonEmptyString, ht.TInt)))
205 ht.TListOf(ht.TAnd(ht.TIsLength(2),
206 ht.TItems([ht.TElemOf(constants.RS_ALL),
209 _TQueryResult = ht.TListOf(_TQueryRow)
211 _TOldQueryRow = ht.TListOf(ht.TAny)
213 _TOldQueryResult = ht.TListOf(_TOldQueryRow)
223 #: Attribute name for dependencies
224 DEPEND_ATTR = "depends"
226 #: Attribute name for comment
227 COMMENT_ATTR = "comment"
231 """Convert an opcode class name to an OP_ID.
234 @param name: the class name, as OpXxxYyy
236 @return: the name in the OP_XXXX_YYYY format
239 if not name.startswith("Op"):
241 # Note: (?<=[a-z])(?=[A-Z]) would be ideal, since it wouldn't
242 # consume any input, and hence we would just have all the elements
243 # in the list, one by one; but it seems that split doesn't work on
244 # non-consuming input, hence we have to process the input string a
246 name = _OPID_RE.sub(r"\1,\2", name)
247 elems = name.split(",")
248 return "_".join(n.upper() for n in elems)
251 def _GenerateObjectTypeCheck(obj, fields_types):
252 """Helper to generate type checks for objects.
254 @param obj: The object to generate type checks
255 @param fields_types: The fields and their types as a dict
256 @return: A ht type check function
259 assert set(obj.GetAllSlots()) == set(fields_types.keys()), \
260 "%s != %s" % (set(obj.GetAllSlots()), set(fields_types.keys()))
261 return ht.TStrictDict(True, True, fields_types)
265 _GenerateObjectTypeCheck(objects.QueryFieldDefinition, {
266 "name": ht.TNonEmptyString,
267 "title": ht.TNonEmptyString,
268 "kind": ht.TElemOf(constants.QFT_ALL),
269 "doc": ht.TNonEmptyString,
273 def RequireFileStorage():
274 """Checks that file storage is enabled.
276 While it doesn't really fit into this module, L{utils} was deemed too large
277 of a dependency to be imported for just one or two functions.
279 @raise errors.OpPrereqError: when file storage is disabled
282 if not constants.ENABLE_FILE_STORAGE:
283 raise errors.OpPrereqError("File storage disabled at configure time",
287 def RequireSharedFileStorage():
288 """Checks that shared file storage is enabled.
290 While it doesn't really fit into this module, L{utils} was deemed too large
291 of a dependency to be imported for just one or two functions.
293 @raise errors.OpPrereqError: when shared file storage is disabled
296 if not constants.ENABLE_SHARED_FILE_STORAGE:
297 raise errors.OpPrereqError("Shared file storage disabled at"
298 " configure time", errors.ECODE_INVAL)
301 @ht.WithDesc("CheckFileStorage")
302 def _CheckFileStorage(value):
303 """Ensures file storage is enabled if used.
306 if value == constants.DT_FILE:
308 elif value == constants.DT_SHARED_FILE:
309 RequireSharedFileStorage()
313 def _BuildDiskTemplateCheck(accept_none):
314 """Builds check for disk template.
316 @type accept_none: bool
317 @param accept_none: whether to accept None as a correct value
321 template_check = ht.TElemOf(constants.DISK_TEMPLATES)
324 template_check = ht.TOr(template_check, ht.TNone)
326 return ht.TAnd(template_check, _CheckFileStorage)
329 def _CheckStorageType(storage_type):
330 """Ensure a given storage type is valid.
333 if storage_type not in constants.VALID_STORAGE_TYPES:
334 raise errors.OpPrereqError("Unknown storage type: %s" % storage_type,
336 if storage_type == constants.ST_FILE:
341 #: Storage type parameter
342 _PStorageType = ("storage_type", ht.NoDefault, _CheckStorageType,
346 class _AutoOpParamSlots(objectutils.AutoSlots):
347 """Meta class for opcode definitions.
350 def __new__(mcs, name, bases, attrs):
351 """Called when a class should be created.
353 @param mcs: The meta class
354 @param name: Name of created class
355 @param bases: Base classes
357 @param attrs: Class attributes
360 assert "OP_ID" not in attrs, "Class '%s' defining OP_ID" % name
362 slots = mcs._GetSlots(attrs)
363 assert "OP_DSC_FIELD" not in attrs or attrs["OP_DSC_FIELD"] in slots, \
364 "Class '%s' uses unknown field in OP_DSC_FIELD" % name
366 attrs["OP_ID"] = _NameToId(name)
368 return objectutils.AutoSlots.__new__(mcs, name, bases, attrs)
371 def _GetSlots(mcs, attrs):
372 """Build the slots out of OP_PARAMS.
375 # Always set OP_PARAMS to avoid duplicates in BaseOpCode.GetAllParams
376 params = attrs.setdefault("OP_PARAMS", [])
378 # Use parameter names as slots
379 return [pname for (pname, _, _, _) in params]
382 class BaseOpCode(objectutils.ValidatedSlots):
383 """A simple serializable object.
385 This object serves as a parent class for OpCode without any custom
389 # pylint: disable=E1101
390 # as OP_ID is dynamically defined
391 __metaclass__ = _AutoOpParamSlots
393 def __getstate__(self):
394 """Generic serializer.
396 This method just returns the contents of the instance as a
400 @return: the instance attributes and their values
404 for name in self.GetAllSlots():
405 if hasattr(self, name):
406 state[name] = getattr(self, name)
409 def __setstate__(self, state):
410 """Generic unserializer.
412 This method just restores from the serialized state the attributes
413 of the current instance.
415 @param state: the serialized opcode data
419 if not isinstance(state, dict):
420 raise ValueError("Invalid data to __setstate__: expected dict, got %s" %
423 for name in self.GetAllSlots():
424 if name not in state and hasattr(self, name):
428 setattr(self, name, state[name])
431 def GetAllParams(cls):
432 """Compute list of all parameters for an opcode.
436 for parent in cls.__mro__:
437 slots.extend(getattr(parent, "OP_PARAMS", []))
440 def Validate(self, set_defaults): # pylint: disable=W0221
441 """Validate opcode parameters, optionally setting default values.
443 @type set_defaults: bool
444 @param set_defaults: Whether to set default values
445 @raise errors.OpPrereqError: When a parameter value doesn't match
449 for (attr_name, default, test, _) in self.GetAllParams():
450 assert test == ht.NoType or callable(test)
452 if not hasattr(self, attr_name):
453 if default == ht.NoDefault:
454 raise errors.OpPrereqError("Required parameter '%s.%s' missing" %
455 (self.OP_ID, attr_name),
458 if callable(default):
462 setattr(self, attr_name, dval)
464 if test == ht.NoType:
468 if set_defaults or hasattr(self, attr_name):
469 attr_val = getattr(self, attr_name)
470 if not test(attr_val):
471 logging.error("OpCode %s, parameter %s, has invalid type %s/value %s",
472 self.OP_ID, attr_name, type(attr_val), attr_val)
473 raise errors.OpPrereqError("Parameter '%s.%s' fails validation" %
474 (self.OP_ID, attr_name),
478 def _BuildJobDepCheck(relative):
479 """Builds check for job dependencies (L{DEPEND_ATTR}).
482 @param relative: Whether to accept relative job IDs (negative)
487 job_id = ht.TOr(ht.TJobId, ht.TRelativeJobId)
492 ht.TAnd(ht.TIsLength(2),
494 ht.TListOf(ht.TElemOf(constants.JOBS_FINALIZED))]))
496 return ht.TMaybeListOf(job_dep)
499 TNoRelativeJobDependencies = _BuildJobDepCheck(False)
501 #: List of submission status and job ID as returned by C{SubmitManyJobs}
503 ht.TAnd(ht.TIsLength(2),
504 ht.TItems([ht.Comment("success")(ht.TBool),
505 ht.Comment("Job ID if successful, error message"
506 " otherwise")(ht.TOr(ht.TString,
508 TJobIdList = ht.TListOf(_TJobIdListItem)
510 #: Result containing only list of submitted jobs
511 TJobIdListOnly = ht.TStrictDict(True, True, {
512 constants.JOB_IDS_KEY: ht.Comment("List of submitted jobs")(TJobIdList),
516 class OpCode(BaseOpCode):
519 This is the root of the actual OpCode hierarchy. All clases derived
520 from this class should override OP_ID.
522 @cvar OP_ID: The ID of this opcode. This should be unique amongst all
523 children of this class.
524 @cvar OP_DSC_FIELD: The name of a field whose value will be included in the
525 string returned by Summary(); see the docstring of that
527 @cvar OP_PARAMS: List of opcode attributes, the default values they should
528 get if not already defined, and types they must match.
529 @cvar OP_RESULT: Callable to verify opcode result
530 @cvar WITH_LU: Boolean that specifies whether this should be included in
531 mcpu's dispatch table
532 @ivar dry_run: Whether the LU should be run in dry-run mode, i.e. just
534 @ivar priority: Opcode priority for queue
537 # pylint: disable=E1101
538 # as OP_ID is dynamically defined
541 ("dry_run", None, ht.TMaybeBool, "Run checks only, don't execute"),
542 ("debug_level", None, ht.TOr(ht.TNone, ht.TPositiveInt), "Debug level"),
543 ("priority", constants.OP_PRIO_DEFAULT,
544 ht.TElemOf(constants.OP_PRIO_SUBMIT_VALID), "Opcode priority"),
545 (DEPEND_ATTR, None, _BuildJobDepCheck(True),
546 "Job dependencies; if used through ``SubmitManyJobs`` relative (negative)"
547 " job IDs can be used; see :doc:`design document <design-chained-jobs>`"
549 (COMMENT_ATTR, None, ht.TMaybeString,
550 "Comment describing the purpose of the opcode"),
554 def __getstate__(self):
555 """Specialized getstate for opcodes.
557 This method adds to the state dictionary the OP_ID of the class,
558 so that on unload we can identify the correct class for
559 instantiating the opcode.
562 @return: the state as a dictionary
565 data = BaseOpCode.__getstate__(self)
566 data["OP_ID"] = self.OP_ID
570 def LoadOpCode(cls, data):
571 """Generic load opcode method.
573 The method identifies the correct opcode class from the dict-form
574 by looking for a OP_ID key, if this is not found, or its value is
575 not available in this module as a child of this class, we fail.
578 @param data: the serialized opcode
581 if not isinstance(data, dict):
582 raise ValueError("Invalid data to LoadOpCode (%s)" % type(data))
583 if "OP_ID" not in data:
584 raise ValueError("Invalid data to LoadOpcode, missing OP_ID")
585 op_id = data["OP_ID"]
587 if op_id in OP_MAPPING:
588 op_class = OP_MAPPING[op_id]
590 raise ValueError("Invalid data to LoadOpCode: OP_ID %s unsupported" %
593 new_data = data.copy()
594 del new_data["OP_ID"]
595 op.__setstate__(new_data)
599 """Generates a summary description of this opcode.
601 The summary is the value of the OP_ID attribute (without the "OP_"
602 prefix), plus the value of the OP_DSC_FIELD attribute, if one was
603 defined; this field should allow to easily identify the operation
604 (for an instance creation job, e.g., it would be the instance
608 assert self.OP_ID is not None and len(self.OP_ID) > 3
609 # all OP_ID start with OP_, we remove that
611 field_name = getattr(self, "OP_DSC_FIELD", None)
613 field_value = getattr(self, field_name, None)
614 if isinstance(field_value, (list, tuple)):
615 field_value = ",".join(str(i) for i in field_value)
616 txt = "%s(%s)" % (txt, field_value)
619 def TinySummary(self):
620 """Generates a compact summary description of the opcode.
623 assert self.OP_ID.startswith("OP_")
625 text = self.OP_ID[3:]
627 for (prefix, supplement) in _SUMMARY_PREFIX.items():
628 if text.startswith(prefix):
629 return supplement + text[len(prefix):]
636 class OpClusterPostInit(OpCode):
637 """Post cluster initialization.
639 This opcode does not touch the cluster at all. Its purpose is to run hooks
640 after the cluster has been initialized.
646 class OpClusterDestroy(OpCode):
647 """Destroy the cluster.
649 This opcode has no other parameters. All the state is irreversibly
650 lost after the execution of this opcode.
653 OP_RESULT = ht.TNonEmptyString
656 class OpClusterQuery(OpCode):
657 """Query cluster information."""
658 OP_RESULT = ht.TDictOf(ht.TNonEmptyString, ht.TAny)
661 class OpClusterVerify(OpCode):
662 """Submits all jobs necessary to verify the cluster.
666 _PDebugSimulateErrors,
671 ("group_name", None, ht.TMaybeString, "Group to verify")
673 OP_RESULT = TJobIdListOnly
676 class OpClusterVerifyConfig(OpCode):
677 """Verify the cluster config.
681 _PDebugSimulateErrors,
689 class OpClusterVerifyGroup(OpCode):
690 """Run verify on a node group from the cluster.
692 @type skip_checks: C{list}
693 @ivar skip_checks: steps to be skipped from the verify process; this
694 needs to be a subset of
695 L{constants.VERIFY_OPTIONAL_CHECKS}; currently
696 only L{constants.VERIFY_NPLUSONE_MEM} can be passed
699 OP_DSC_FIELD = "group_name"
702 _PDebugSimulateErrors,
711 class OpClusterVerifyDisks(OpCode):
712 """Verify the cluster disks.
715 OP_RESULT = TJobIdListOnly
718 class OpGroupVerifyDisks(OpCode):
719 """Verifies the status of all disks in a node group.
721 Result: a tuple of three elements:
722 - dict of node names with issues (values: error msg)
723 - list of instances with degraded disks (that should be activated)
724 - dict of instances with missing logical volumes (values: (node, vol)
725 pairs with details about the missing volumes)
727 In normal operation, all lists should be empty. A non-empty instance
728 list (3rd element of the result) is still ok (errors were fixed) but
729 non-empty node list means some node is down, and probably there are
730 unfixable drbd errors.
732 Note that only instances that are drbd-based are taken into
733 consideration. This might need to be revisited in the future.
736 OP_DSC_FIELD = "group_name"
741 ht.TAnd(ht.TIsLength(3),
742 ht.TItems([ht.TDictOf(ht.TString, ht.TString),
743 ht.TListOf(ht.TString),
744 ht.TDictOf(ht.TString,
745 ht.TListOf(ht.TListOf(ht.TString)))]))
748 class OpClusterRepairDiskSizes(OpCode):
749 """Verify the disk sizes of the instances and fixes configuration
752 Parameters: optional instances list, in case we want to restrict the
753 checks to only a subset of the instances.
755 Result: a list of tuples, (instance, disk, new-size) for changed
758 In normal operation, the list should be empty.
760 @type instances: list
761 @ivar instances: the list of instances to check, or empty for all instances
765 ("instances", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), None),
767 OP_RESULT = ht.TListOf(ht.TAnd(ht.TIsLength(3),
768 ht.TItems([ht.TNonEmptyString,
773 class OpClusterConfigQuery(OpCode):
774 """Query cluster configuration values."""
778 OP_RESULT = ht.TListOf(ht.TAny)
781 class OpClusterRename(OpCode):
782 """Rename the cluster.
785 @ivar name: The new name of the cluster. The name and/or the master IP
786 address will be changed to match the new name and its IP
790 OP_DSC_FIELD = "name"
792 ("name", ht.NoDefault, ht.TNonEmptyString, None),
794 OP_RESULT = ht.TNonEmptyString
797 class OpClusterSetParams(OpCode):
798 """Change the parameters of the cluster.
800 @type vg_name: C{str} or C{None}
801 @ivar vg_name: The new volume group name or None to disable LVM usage.
807 ("vg_name", None, ht.TMaybeString, "Volume group name"),
808 ("enabled_hypervisors", None,
809 ht.TOr(ht.TAnd(ht.TListOf(ht.TElemOf(constants.HYPER_TYPES)), ht.TTrue),
811 "List of enabled hypervisors"),
812 ("hvparams", None, ht.TOr(ht.TDictOf(ht.TNonEmptyString, ht.TDict),
814 "Cluster-wide hypervisor parameter defaults, hypervisor-dependent"),
815 ("beparams", None, ht.TOr(ht.TDict, ht.TNone),
816 "Cluster-wide backend parameter defaults"),
817 ("os_hvp", None, ht.TOr(ht.TDictOf(ht.TNonEmptyString, ht.TDict),
819 "Cluster-wide per-OS hypervisor parameter defaults"),
820 ("osparams", None, ht.TOr(ht.TDictOf(ht.TNonEmptyString, ht.TDict),
822 "Cluster-wide OS parameter defaults"),
824 ("candidate_pool_size", None, ht.TOr(ht.TStrictPositiveInt, ht.TNone),
825 "Master candidate pool size"),
826 ("uid_pool", None, ht.NoType,
827 "Set UID pool, must be list of lists describing UID ranges (two items,"
828 " start and end inclusive)"),
829 ("add_uids", None, ht.NoType,
830 "Extend UID pool, must be list of lists describing UID ranges (two"
831 " items, start and end inclusive) to be added"),
832 ("remove_uids", None, ht.NoType,
833 "Shrink UID pool, must be list of lists describing UID ranges (two"
834 " items, start and end inclusive) to be removed"),
835 ("maintain_node_health", None, ht.TMaybeBool,
836 "Whether to automatically maintain node health"),
837 ("prealloc_wipe_disks", None, ht.TMaybeBool,
838 "Whether to wipe disks before allocating them to instances"),
839 ("nicparams", None, ht.TMaybeDict, "Cluster-wide NIC parameter defaults"),
840 ("ndparams", None, ht.TMaybeDict, "Cluster-wide node parameter defaults"),
841 ("ipolicy", None, ht.TMaybeDict,
842 "Cluster-wide :ref:`instance policy <rapi-ipolicy>` specs"),
843 ("drbd_helper", None, ht.TOr(ht.TString, ht.TNone), "DRBD helper program"),
844 ("default_iallocator", None, ht.TOr(ht.TString, ht.TNone),
845 "Default iallocator for cluster"),
846 ("master_netdev", None, ht.TOr(ht.TString, ht.TNone),
847 "Master network device"),
848 ("master_netmask", None, ht.TOr(ht.TInt, ht.TNone),
849 "Netmask of the master IP"),
850 ("reserved_lvs", None, ht.TMaybeListOf(ht.TNonEmptyString),
851 "List of reserved LVs"),
852 ("hidden_os", None, _TestClusterOsList,
853 "Modify list of hidden operating systems: each modification must have"
854 " two items, the operation and the OS name; the operation can be"
855 " ``%s`` or ``%s``" % (constants.DDM_ADD, constants.DDM_REMOVE)),
856 ("blacklisted_os", None, _TestClusterOsList,
857 "Modify list of blacklisted operating systems: each modification must"
858 " have two items, the operation and the OS name; the operation can be"
859 " ``%s`` or ``%s``" % (constants.DDM_ADD, constants.DDM_REMOVE)),
860 ("use_external_mip_script", None, ht.TMaybeBool,
861 "Whether to use an external master IP address setup script"),
866 class OpClusterRedistConf(OpCode):
867 """Force a full push of the cluster configuration.
873 class OpClusterActivateMasterIp(OpCode):
874 """Activate the master IP on the master node.
880 class OpClusterDeactivateMasterIp(OpCode):
881 """Deactivate the master IP on the master node.
887 class OpQuery(OpCode):
888 """Query for resources/items.
890 @ivar what: Resources to query for, must be one of L{constants.QR_VIA_OP}
891 @ivar fields: List of fields to retrieve
892 @ivar qfilter: Query filter
895 OP_DSC_FIELD = "what"
899 ("fields", ht.NoDefault, ht.TListOf(ht.TNonEmptyString),
901 ("qfilter", None, ht.TOr(ht.TNone, ht.TList),
905 _GenerateObjectTypeCheck(objects.QueryResponse, {
906 "fields": ht.TListOf(_TQueryFieldDef),
907 "data": _TQueryResult,
911 class OpQueryFields(OpCode):
912 """Query for available resource/item fields.
914 @ivar what: Resources to query for, must be one of L{constants.QR_VIA_OP}
915 @ivar fields: List of fields to retrieve
918 OP_DSC_FIELD = "what"
921 ("fields", None, ht.TMaybeListOf(ht.TNonEmptyString),
922 "Requested fields; if not given, all are returned"),
925 _GenerateObjectTypeCheck(objects.QueryFieldsResponse, {
926 "fields": ht.TListOf(_TQueryFieldDef),
930 class OpOobCommand(OpCode):
931 """Interact with OOB."""
933 ("node_names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
934 "List of nodes to run the OOB command against"),
935 ("command", None, ht.TElemOf(constants.OOB_COMMANDS),
936 "OOB command to be run"),
937 ("timeout", constants.OOB_TIMEOUT, ht.TInt,
938 "Timeout before the OOB helper will be terminated"),
939 ("ignore_status", False, ht.TBool,
940 "Ignores the node offline status for power off"),
941 ("power_delay", constants.OOB_POWER_DELAY, ht.TPositiveFloat,
942 "Time in seconds to wait between powering on nodes"),
944 # Fixme: Make it more specific with all the special cases in LUOobCommand
945 OP_RESULT = _TQueryResult
950 class OpNodeRemove(OpCode):
953 @type node_name: C{str}
954 @ivar node_name: The name of the node to remove. If the node still has
955 instances on it, the operation will fail.
958 OP_DSC_FIELD = "node_name"
965 class OpNodeAdd(OpCode):
966 """Add a node to the cluster.
968 @type node_name: C{str}
969 @ivar node_name: The name of the node to add. This can be a short name,
970 but it will be expanded to the FQDN.
971 @type primary_ip: IP address
972 @ivar primary_ip: The primary IP of the node. This will be ignored when the
973 opcode is submitted, but will be filled during the node
974 add (so it will be visible in the job query).
975 @type secondary_ip: IP address
976 @ivar secondary_ip: The secondary IP of the node. This needs to be passed
977 if the cluster has been initialized in 'dual-network'
978 mode, otherwise it must not be given.
980 @ivar readd: Whether to re-add an existing node to the cluster. If
981 this is not passed, then the operation will abort if the node
982 name is already in the cluster; use this parameter to 'repair'
983 a node that had its configuration broken, or was reinstalled
984 without removal from the cluster.
986 @ivar group: The node group to which this node will belong.
987 @type vm_capable: C{bool}
988 @ivar vm_capable: The vm_capable node attribute
989 @type master_capable: C{bool}
990 @ivar master_capable: The master_capable node attribute
993 OP_DSC_FIELD = "node_name"
998 ("primary_ip", None, ht.NoType, "Primary IP address"),
999 ("secondary_ip", None, ht.TMaybeString, "Secondary IP address"),
1000 ("readd", False, ht.TBool, "Whether node is re-added to cluster"),
1001 ("group", None, ht.TMaybeString, "Initial node group"),
1002 ("master_capable", None, ht.TMaybeBool,
1003 "Whether node can become master or master candidate"),
1004 ("vm_capable", None, ht.TMaybeBool,
1005 "Whether node can host instances"),
1006 ("ndparams", None, ht.TMaybeDict, "Node parameters"),
1008 OP_RESULT = ht.TNone
1011 class OpNodeQuery(OpCode):
1012 """Compute the list of nodes."""
1016 ("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
1017 "Empty list to query all nodes, node names otherwise"),
1019 OP_RESULT = _TOldQueryResult
1022 class OpNodeQueryvols(OpCode):
1023 """Get list of volumes on node."""
1026 ("nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
1027 "Empty list to query all nodes, node names otherwise"),
1029 OP_RESULT = ht.TListOf(ht.TAny)
1032 class OpNodeQueryStorage(OpCode):
1033 """Get information on storage for node(s)."""
1037 ("nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), "List of nodes"),
1038 ("name", None, ht.TMaybeString, "Storage name"),
1040 OP_RESULT = _TOldQueryResult
1043 class OpNodeModifyStorage(OpCode):
1044 """Modifies the properies of a storage unit"""
1045 OP_DSC_FIELD = "node_name"
1050 ("changes", ht.NoDefault, ht.TDict, "Requested changes"),
1052 OP_RESULT = ht.TNone
1055 class OpRepairNodeStorage(OpCode):
1056 """Repairs the volume group on a node."""
1057 OP_DSC_FIELD = "node_name"
1062 _PIgnoreConsistency,
1064 OP_RESULT = ht.TNone
1067 class OpNodeSetParams(OpCode):
1068 """Change the parameters of a node."""
1069 OP_DSC_FIELD = "node_name"
1075 ("master_candidate", None, ht.TMaybeBool,
1076 "Whether the node should become a master candidate"),
1077 ("offline", None, ht.TMaybeBool,
1078 "Whether the node should be marked as offline"),
1079 ("drained", None, ht.TMaybeBool,
1080 "Whether the node should be marked as drained"),
1081 ("auto_promote", False, ht.TBool,
1082 "Whether node(s) should be promoted to master candidate if necessary"),
1083 ("master_capable", None, ht.TMaybeBool,
1084 "Denote whether node can become master or master candidate"),
1085 ("vm_capable", None, ht.TMaybeBool,
1086 "Denote whether node can host instances"),
1087 ("secondary_ip", None, ht.TMaybeString,
1088 "Change node's secondary IP address"),
1089 ("ndparams", None, ht.TMaybeDict, "Set node parameters"),
1090 ("powered", None, ht.TMaybeBool,
1091 "Whether the node should be marked as powered"),
1093 OP_RESULT = _TSetParamsResult
1096 class OpNodePowercycle(OpCode):
1097 """Tries to powercycle a node."""
1098 OP_DSC_FIELD = "node_name"
1103 OP_RESULT = ht.TMaybeString
1106 class OpNodeMigrate(OpCode):
1107 """Migrate all instances from a node."""
1108 OP_DSC_FIELD = "node_name"
1113 _PMigrationTargetNode,
1116 ("iallocator", None, ht.TMaybeString,
1117 "Iallocator for deciding the target node for shared-storage instances"),
1119 OP_RESULT = TJobIdListOnly
1122 class OpNodeEvacuate(OpCode):
1123 """Evacuate instances off a number of nodes."""
1124 OP_DSC_FIELD = "node_name"
1128 ("remote_node", None, ht.TMaybeString, "New secondary node"),
1129 ("iallocator", None, ht.TMaybeString, "Iallocator for computing solution"),
1130 ("mode", ht.NoDefault, ht.TElemOf(constants.NODE_EVAC_MODES),
1131 "Node evacuation mode"),
1133 OP_RESULT = TJobIdListOnly
1138 class OpInstanceCreate(OpCode):
1139 """Create an instance.
1141 @ivar instance_name: Instance name
1142 @ivar mode: Instance creation mode (one of L{constants.INSTANCE_CREATE_MODES})
1143 @ivar source_handshake: Signed handshake from source (remote import only)
1144 @ivar source_x509_ca: Source X509 CA in PEM format (remote import only)
1145 @ivar source_instance_name: Previous name of instance (remote import only)
1146 @ivar source_shutdown_timeout: Shutdown timeout used for source instance
1147 (remote import only)
1150 OP_DSC_FIELD = "instance_name"
1157 ("beparams", ht.EmptyDict, ht.TDict, "Backend parameters for instance"),
1158 ("disks", ht.NoDefault, ht.TListOf(_TDiskParams),
1159 "Disk descriptions, for example ``[{\"%s\": 100}, {\"%s\": 5}]``;"
1160 " each disk definition must contain a ``%s`` value and"
1161 " can contain an optional ``%s`` value denoting the disk access mode"
1163 (constants.IDISK_SIZE, constants.IDISK_SIZE, constants.IDISK_SIZE,
1164 constants.IDISK_MODE,
1165 " or ".join("``%s``" % i for i in sorted(constants.DISK_ACCESS_SET)))),
1166 ("disk_template", ht.NoDefault, _BuildDiskTemplateCheck(True),
1168 ("file_driver", None, ht.TOr(ht.TNone, ht.TElemOf(constants.FILE_DRIVER)),
1169 "Driver for file-backed disks"),
1170 ("file_storage_dir", None, ht.TMaybeString,
1171 "Directory for storing file-backed disks"),
1172 ("hvparams", ht.EmptyDict, ht.TDict,
1173 "Hypervisor parameters for instance, hypervisor-dependent"),
1174 ("hypervisor", None, ht.TMaybeString, "Hypervisor"),
1175 ("iallocator", None, ht.TMaybeString,
1176 "Iallocator for deciding which node(s) to use"),
1177 ("identify_defaults", False, ht.TBool,
1178 "Reset instance parameters to default if equal"),
1179 ("ip_check", True, ht.TBool, _PIpCheckDoc),
1180 ("mode", ht.NoDefault, ht.TElemOf(constants.INSTANCE_CREATE_MODES),
1181 "Instance creation mode"),
1182 ("nics", ht.NoDefault, ht.TListOf(_TestNicDef),
1183 "List of NIC (network interface) definitions, for example"
1184 " ``[{}, {}, {\"%s\": \"198.51.100.4\"}]``; each NIC definition can"
1185 " contain the optional values %s" %
1187 ", ".join("``%s``" % i for i in sorted(constants.INIC_PARAMS)))),
1188 ("no_install", None, ht.TMaybeBool,
1189 "Do not install the OS (will disable automatic start)"),
1190 ("osparams", ht.EmptyDict, ht.TDict, "OS parameters for instance"),
1191 ("os_type", None, ht.TMaybeString, "Operating system"),
1192 ("pnode", None, ht.TMaybeString, "Primary node"),
1193 ("snode", None, ht.TMaybeString, "Secondary node"),
1194 ("source_handshake", None, ht.TOr(ht.TList, ht.TNone),
1195 "Signed handshake from source (remote import only)"),
1196 ("source_instance_name", None, ht.TMaybeString,
1197 "Source instance name (remote import only)"),
1198 ("source_shutdown_timeout", constants.DEFAULT_SHUTDOWN_TIMEOUT,
1200 "How long source instance was given to shut down (remote import only)"),
1201 ("source_x509_ca", None, ht.TMaybeString,
1202 "Source X509 CA in PEM format (remote import only)"),
1203 ("src_node", None, ht.TMaybeString, "Source node for import"),
1204 ("src_path", None, ht.TMaybeString, "Source directory for import"),
1205 ("start", True, ht.TBool, "Whether to start instance after creation"),
1206 ("tags", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), "Instance tags"),
1208 OP_RESULT = ht.Comment("instance nodes")(ht.TListOf(ht.TNonEmptyString))
1211 class OpInstanceReinstall(OpCode):
1212 """Reinstall an instance's OS."""
1213 OP_DSC_FIELD = "instance_name"
1217 ("os_type", None, ht.TMaybeString, "Instance operating system"),
1218 ("osparams", None, ht.TMaybeDict, "Temporary OS parameters"),
1220 OP_RESULT = ht.TNone
1223 class OpInstanceRemove(OpCode):
1224 """Remove an instance."""
1225 OP_DSC_FIELD = "instance_name"
1229 ("ignore_failures", False, ht.TBool,
1230 "Whether to ignore failures during removal"),
1232 OP_RESULT = ht.TNone
1235 class OpInstanceRename(OpCode):
1236 """Rename an instance."""
1240 ("new_name", ht.NoDefault, ht.TNonEmptyString, "New instance name"),
1241 ("ip_check", False, ht.TBool, _PIpCheckDoc),
1243 OP_RESULT = ht.Comment("New instance name")(ht.TNonEmptyString)
1246 class OpInstanceStartup(OpCode):
1247 """Startup an instance."""
1248 OP_DSC_FIELD = "instance_name"
1252 _PIgnoreOfflineNodes,
1253 ("hvparams", ht.EmptyDict, ht.TDict,
1254 "Temporary hypervisor parameters, hypervisor-dependent"),
1255 ("beparams", ht.EmptyDict, ht.TDict, "Temporary backend parameters"),
1259 OP_RESULT = ht.TNone
1262 class OpInstanceShutdown(OpCode):
1263 """Shutdown an instance."""
1264 OP_DSC_FIELD = "instance_name"
1267 _PIgnoreOfflineNodes,
1268 ("timeout", constants.DEFAULT_SHUTDOWN_TIMEOUT, ht.TPositiveInt,
1269 "How long to wait for instance to shut down"),
1272 OP_RESULT = ht.TNone
1275 class OpInstanceReboot(OpCode):
1276 """Reboot an instance."""
1277 OP_DSC_FIELD = "instance_name"
1281 ("ignore_secondaries", False, ht.TBool,
1282 "Whether to start the instance even if secondary disks are failing"),
1283 ("reboot_type", ht.NoDefault, ht.TElemOf(constants.REBOOT_TYPES),
1284 "How to reboot instance"),
1286 OP_RESULT = ht.TNone
1289 class OpInstanceReplaceDisks(OpCode):
1290 """Replace the disks of an instance."""
1291 OP_DSC_FIELD = "instance_name"
1296 ("mode", ht.NoDefault, ht.TElemOf(constants.REPLACE_MODES),
1297 "Replacement mode"),
1298 ("disks", ht.EmptyList, ht.TListOf(ht.TPositiveInt),
1300 ("remote_node", None, ht.TMaybeString, "New secondary node"),
1301 ("iallocator", None, ht.TMaybeString,
1302 "Iallocator for deciding new secondary node"),
1304 OP_RESULT = ht.TNone
1307 class OpInstanceFailover(OpCode):
1308 """Failover an instance."""
1309 OP_DSC_FIELD = "instance_name"
1313 _PIgnoreConsistency,
1314 _PMigrationTargetNode,
1316 ("iallocator", None, ht.TMaybeString,
1317 "Iallocator for deciding the target node for shared-storage instances"),
1319 OP_RESULT = ht.TNone
1322 class OpInstanceMigrate(OpCode):
1323 """Migrate an instance.
1325 This migrates (without shutting down an instance) to its secondary
1328 @ivar instance_name: the name of the instance
1329 @ivar mode: the migration mode (live, non-live or None for auto)
1332 OP_DSC_FIELD = "instance_name"
1337 _PMigrationTargetNode,
1340 ("cleanup", False, ht.TBool,
1341 "Whether a previously failed migration should be cleaned up"),
1342 ("iallocator", None, ht.TMaybeString,
1343 "Iallocator for deciding the target node for shared-storage instances"),
1344 ("allow_failover", False, ht.TBool,
1345 "Whether we can fallback to failover if migration is not possible"),
1347 OP_RESULT = ht.TNone
1350 class OpInstanceMove(OpCode):
1351 """Move an instance.
1353 This move (with shutting down an instance and data copying) to an
1356 @ivar instance_name: the name of the instance
1357 @ivar target_node: the destination node
1360 OP_DSC_FIELD = "instance_name"
1365 ("target_node", ht.NoDefault, ht.TNonEmptyString, "Target node"),
1366 _PIgnoreConsistency,
1368 OP_RESULT = ht.TNone
1371 class OpInstanceConsole(OpCode):
1372 """Connect to an instance's console."""
1373 OP_DSC_FIELD = "instance_name"
1377 OP_RESULT = ht.TDict
1380 class OpInstanceActivateDisks(OpCode):
1381 """Activate an instance's disks."""
1382 OP_DSC_FIELD = "instance_name"
1385 ("ignore_size", False, ht.TBool, "Whether to ignore recorded size"),
1388 OP_RESULT = ht.TListOf(ht.TAnd(ht.TIsLength(3),
1389 ht.TItems([ht.TNonEmptyString,
1391 ht.TNonEmptyString])))
1394 class OpInstanceDeactivateDisks(OpCode):
1395 """Deactivate an instance's disks."""
1396 OP_DSC_FIELD = "instance_name"
1401 OP_RESULT = ht.TNone
1404 class OpInstanceRecreateDisks(OpCode):
1405 """Recreate an instance's disks."""
1407 ht.TAnd(ht.TIsLength(2),
1408 ht.TItems([ht.Comment("Disk index")(ht.TPositiveInt),
1409 ht.Comment("Parameters")(_TDiskParams)]))
1411 OP_DSC_FIELD = "instance_name"
1414 ("disks", ht.EmptyList,
1415 ht.TOr(ht.TListOf(ht.TPositiveInt), ht.TListOf(_TDiskChanges)),
1416 "List of disk indexes (deprecated) or a list of tuples containing a disk"
1417 " index and a possibly empty dictionary with disk parameter changes"),
1418 ("nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
1419 "New instance nodes, if relocation is desired"),
1420 ("iallocator", None, ht.TMaybeString,
1421 "Iallocator for deciding new nodes"),
1423 OP_RESULT = ht.TNone
1426 class OpInstanceQuery(OpCode):
1427 """Compute the list of instances."""
1431 ("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
1432 "Empty list to query all instances, instance names otherwise"),
1434 OP_RESULT = _TOldQueryResult
1437 class OpInstanceQueryData(OpCode):
1438 """Compute the run-time status of instances."""
1441 ("instances", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
1443 ("static", False, ht.TBool,
1444 "Whether to only return configuration data without querying"
1447 OP_RESULT = ht.TDictOf(ht.TNonEmptyString, ht.TDict)
1450 def _TestInstSetParamsModList(fn):
1451 """Generates a check for modification lists.
1455 # TODO: Remove in version 2.8 including support in LUInstanceSetParams
1457 ht.TAnd(ht.TIsLength(2), ht.TItems([
1458 ht.TOr(ht.TElemOf(constants.DDMS_VALUES), ht.TPositiveInt),
1462 # New format, supporting adding/removing disks/NICs at arbitrary indices
1464 ht.TAnd(ht.TIsLength(3), ht.TItems([
1465 ht.TElemOf(constants.DDMS_VALUES_WITH_MODIFY),
1466 ht.Comment("Disk index, can be negative, e.g. -1 for last disk")(ht.TInt),
1470 return ht.TOr(ht.Comment("Recommended")(ht.TListOf(mod_item_fn)),
1471 ht.Comment("Deprecated")(ht.TListOf(old_mod_item_fn)))
1474 class OpInstanceSetParams(OpCode):
1475 """Change the parameters of an instance.
1478 TestNicModifications = _TestInstSetParamsModList(_TestNicDef)
1479 TestDiskModifications = _TestInstSetParamsModList(_TDiskParams)
1481 OP_DSC_FIELD = "instance_name"
1487 ("nics", ht.EmptyList, TestNicModifications,
1488 "List of NIC changes: each item is of the form ``(op, index, settings)``,"
1489 " ``op`` is one of ``%s``, ``%s`` or ``%s``, ``index`` can be either -1"
1490 " to refer to the last position, or a zero-based index number; a"
1491 " deprecated version of this parameter used the form ``(op, settings)``,"
1492 " where ``op`` can be ``%s`` to add a new NIC with the specified"
1493 " settings, ``%s`` to remove the last NIC or a number to modify the"
1494 " settings of the NIC with that index" %
1495 (constants.DDM_ADD, constants.DDM_MODIFY, constants.DDM_REMOVE,
1496 constants.DDM_ADD, constants.DDM_REMOVE)),
1497 ("disks", ht.EmptyList, TestDiskModifications,
1498 "List of disk changes; see ``nics``"),
1499 ("beparams", ht.EmptyDict, ht.TDict, "Per-instance backend parameters"),
1500 ("runtime_mem", None, ht.TMaybeStrictPositiveInt, "New runtime memory"),
1501 ("hvparams", ht.EmptyDict, ht.TDict,
1502 "Per-instance hypervisor parameters, hypervisor-dependent"),
1503 ("disk_template", None, ht.TOr(ht.TNone, _BuildDiskTemplateCheck(False)),
1504 "Disk template for instance"),
1505 ("remote_node", None, ht.TMaybeString,
1506 "Secondary node (used when changing disk template)"),
1507 ("os_name", None, ht.TMaybeString,
1508 "Change the instance's OS without reinstalling the instance"),
1509 ("osparams", None, ht.TMaybeDict, "Per-instance OS parameters"),
1510 ("wait_for_sync", True, ht.TBool,
1511 "Whether to wait for the disk to synchronize, when changing template"),
1512 ("offline", None, ht.TMaybeBool, "Whether to mark instance as offline"),
1514 OP_RESULT = _TSetParamsResult
1517 class OpInstanceGrowDisk(OpCode):
1518 """Grow a disk of an instance."""
1519 OP_DSC_FIELD = "instance_name"
1523 ("disk", ht.NoDefault, ht.TInt, "Disk index"),
1524 ("amount", ht.NoDefault, ht.TPositiveInt,
1525 "Amount of disk space to add (megabytes)"),
1526 ("absolute", False, ht.TBool,
1527 "Whether the amount parameter is an absolute target or a relative one"),
1529 OP_RESULT = ht.TNone
1532 class OpInstanceChangeGroup(OpCode):
1533 """Moves an instance to another node group."""
1534 OP_DSC_FIELD = "instance_name"
1538 ("iallocator", None, ht.TMaybeString, "Iallocator for computing solution"),
1539 ("target_groups", None, ht.TMaybeListOf(ht.TNonEmptyString),
1540 "Destination group names or UUIDs (defaults to \"all but current group\""),
1542 OP_RESULT = TJobIdListOnly
1545 # Node group opcodes
1547 class OpGroupAdd(OpCode):
1548 """Add a node group to the cluster."""
1549 OP_DSC_FIELD = "group_name"
1552 _PNodeGroupAllocPolicy,
1557 ("ipolicy", None, ht.TMaybeDict,
1558 "Group-wide :ref:`instance policy <rapi-ipolicy>` specs"),
1560 OP_RESULT = ht.TNone
1563 class OpGroupAssignNodes(OpCode):
1564 """Assign nodes to a node group."""
1565 OP_DSC_FIELD = "group_name"
1569 ("nodes", ht.NoDefault, ht.TListOf(ht.TNonEmptyString),
1570 "List of nodes to assign"),
1572 OP_RESULT = ht.TNone
1575 class OpGroupQuery(OpCode):
1576 """Compute the list of node groups."""
1579 ("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
1580 "Empty list to query all groups, group names otherwise"),
1582 OP_RESULT = _TOldQueryResult
1585 class OpGroupSetParams(OpCode):
1586 """Change the parameters of a node group."""
1587 OP_DSC_FIELD = "group_name"
1590 _PNodeGroupAllocPolicy,
1595 ("ipolicy", None, ht.TMaybeDict, "Group-wide instance policy specs"),
1597 OP_RESULT = _TSetParamsResult
1600 class OpGroupRemove(OpCode):
1601 """Remove a node group from the cluster."""
1602 OP_DSC_FIELD = "group_name"
1606 OP_RESULT = ht.TNone
1609 class OpGroupRename(OpCode):
1610 """Rename a node group in the cluster."""
1613 ("new_name", ht.NoDefault, ht.TNonEmptyString, "New group name"),
1615 OP_RESULT = ht.Comment("New group name")(ht.TNonEmptyString)
1618 class OpGroupEvacuate(OpCode):
1619 """Evacuate a node group in the cluster."""
1620 OP_DSC_FIELD = "group_name"
1624 ("iallocator", None, ht.TMaybeString, "Iallocator for computing solution"),
1625 ("target_groups", None, ht.TMaybeListOf(ht.TNonEmptyString),
1626 "Destination group names or UUIDs"),
1628 OP_RESULT = TJobIdListOnly
1632 class OpOsDiagnose(OpCode):
1633 """Compute the list of guest operating systems."""
1636 ("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
1637 "Which operating systems to diagnose"),
1639 OP_RESULT = _TOldQueryResult
1643 class OpBackupQuery(OpCode):
1644 """Compute the list of exported images."""
1647 ("nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
1648 "Empty list to query all nodes, node names otherwise"),
1650 OP_RESULT = ht.TDictOf(ht.TNonEmptyString,
1651 ht.TOr(ht.Comment("False on error")(ht.TBool),
1652 ht.TListOf(ht.TNonEmptyString)))
1655 class OpBackupPrepare(OpCode):
1656 """Prepares an instance export.
1658 @ivar instance_name: Instance name
1659 @ivar mode: Export mode (one of L{constants.EXPORT_MODES})
1662 OP_DSC_FIELD = "instance_name"
1665 ("mode", ht.NoDefault, ht.TElemOf(constants.EXPORT_MODES),
1668 OP_RESULT = ht.TOr(ht.TNone, ht.TDict)
1671 class OpBackupExport(OpCode):
1672 """Export an instance.
1674 For local exports, the export destination is the node name. For remote
1675 exports, the export destination is a list of tuples, each consisting of
1676 hostname/IP address, port, HMAC and HMAC salt. The HMAC is calculated using
1677 the cluster domain secret over the value "${index}:${hostname}:${port}". The
1678 destination X509 CA must be a signed certificate.
1680 @ivar mode: Export mode (one of L{constants.EXPORT_MODES})
1681 @ivar target_node: Export destination
1682 @ivar x509_key_name: X509 key to use (remote export only)
1683 @ivar destination_x509_ca: Destination X509 CA in PEM format (remote export
1687 OP_DSC_FIELD = "instance_name"
1691 # TODO: Rename target_node as it changes meaning for different export modes
1692 # (e.g. "destination")
1693 ("target_node", ht.NoDefault, ht.TOr(ht.TNonEmptyString, ht.TList),
1694 "Destination information, depends on export mode"),
1695 ("shutdown", True, ht.TBool, "Whether to shutdown instance before export"),
1696 ("remove_instance", False, ht.TBool,
1697 "Whether to remove instance after export"),
1698 ("ignore_remove_failures", False, ht.TBool,
1699 "Whether to ignore failures while removing instances"),
1700 ("mode", constants.EXPORT_MODE_LOCAL, ht.TElemOf(constants.EXPORT_MODES),
1702 ("x509_key_name", None, ht.TOr(ht.TList, ht.TNone),
1703 "Name of X509 key (remote export only)"),
1704 ("destination_x509_ca", None, ht.TMaybeString,
1705 "Destination X509 CA (remote export only)"),
1708 ht.TAnd(ht.TIsLength(2), ht.TItems([
1709 ht.Comment("Finalizing status")(ht.TBool),
1710 ht.Comment("Status for every exported disk")(ht.TListOf(ht.TBool)),
1714 class OpBackupRemove(OpCode):
1715 """Remove an instance's export."""
1716 OP_DSC_FIELD = "instance_name"
1720 OP_RESULT = ht.TNone
1724 class OpTagsGet(OpCode):
1725 """Returns the tags of the given object."""
1726 OP_DSC_FIELD = "name"
1729 # Not using _PUseLocking as the default is different for historical reasons
1730 ("use_locking", True, ht.TBool, "Whether to use synchronization"),
1731 # Name is only meaningful for nodes and instances
1732 ("name", ht.NoDefault, ht.TMaybeString,
1733 "Name of object to retrieve tags from"),
1735 OP_RESULT = ht.TListOf(ht.TNonEmptyString)
1738 class OpTagsSearch(OpCode):
1739 """Searches the tags in the cluster for a given pattern."""
1740 OP_DSC_FIELD = "pattern"
1742 ("pattern", ht.NoDefault, ht.TNonEmptyString,
1743 "Search pattern (regular expression)"),
1745 OP_RESULT = ht.TListOf(ht.TAnd(ht.TIsLength(2), ht.TItems([
1751 class OpTagsSet(OpCode):
1752 """Add a list of tags on a given object."""
1756 # Name is only meaningful for nodes and instances
1757 ("name", ht.NoDefault, ht.TMaybeString,
1758 "Name of object where tag(s) should be added"),
1760 OP_RESULT = ht.TNone
1763 class OpTagsDel(OpCode):
1764 """Remove a list of tags from a given object."""
1768 # Name is only meaningful for nodes and instances
1769 ("name", ht.NoDefault, ht.TMaybeString,
1770 "Name of object where tag(s) should be deleted"),
1772 OP_RESULT = ht.TNone
1776 class OpTestDelay(OpCode):
1777 """Sleeps for a configured amount of time.
1779 This is used just for debugging and testing.
1782 - duration: the time to sleep
1783 - on_master: if true, sleep on the master
1784 - on_nodes: list of nodes in which to sleep
1786 If the on_master parameter is true, it will execute a sleep on the
1787 master (before any node sleep).
1789 If the on_nodes list is not empty, it will sleep on those nodes
1790 (after the sleep on the master, if that is enabled).
1792 As an additional feature, the case of duration < 0 will be reported
1793 as an execution error, so this opcode can be used as a failure
1794 generator. The case of duration == 0 will not be treated specially.
1797 OP_DSC_FIELD = "duration"
1799 ("duration", ht.NoDefault, ht.TNumber, None),
1800 ("on_master", True, ht.TBool, None),
1801 ("on_nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), None),
1802 ("repeat", 0, ht.TPositiveInt, None),
1806 class OpTestAllocator(OpCode):
1807 """Allocator framework testing.
1809 This opcode has two modes:
1810 - gather and return allocator input for a given mode (allocate new
1811 or replace secondary) and a given instance definition (direction
1813 - run a selected allocator for a given operation (as above) and
1814 return the allocator output (direction 'out')
1817 OP_DSC_FIELD = "allocator"
1819 ("direction", ht.NoDefault,
1820 ht.TElemOf(constants.VALID_IALLOCATOR_DIRECTIONS), None),
1821 ("mode", ht.NoDefault, ht.TElemOf(constants.VALID_IALLOCATOR_MODES), None),
1822 ("name", ht.NoDefault, ht.TNonEmptyString, None),
1823 ("nics", ht.NoDefault,
1824 ht.TMaybeListOf(ht.TDictOf(ht.TElemOf([constants.INIC_MAC,
1827 ht.TOr(ht.TNone, ht.TNonEmptyString))),
1829 ("disks", ht.NoDefault, ht.TOr(ht.TNone, ht.TList), None),
1830 ("hypervisor", None, ht.TMaybeString, None),
1831 ("allocator", None, ht.TMaybeString, None),
1832 ("tags", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), None),
1833 ("memory", None, ht.TOr(ht.TNone, ht.TPositiveInt), None),
1834 ("vcpus", None, ht.TOr(ht.TNone, ht.TPositiveInt), None),
1835 ("os", None, ht.TMaybeString, None),
1836 ("disk_template", None, ht.TMaybeString, None),
1837 ("instances", None, ht.TMaybeListOf(ht.TNonEmptyString), None),
1839 ht.TOr(ht.TNone, ht.TElemOf(constants.IALLOCATOR_NEVAC_MODES)), None),
1840 ("target_groups", None, ht.TMaybeListOf(ht.TNonEmptyString), None),
1841 ("spindle_use", 1, ht.TPositiveInt, None),
1842 ("count", 1, ht.TPositiveInt, None),
1846 class OpTestJqueue(OpCode):
1847 """Utility opcode to test some aspects of the job queue.
1851 ("notify_waitlock", False, ht.TBool, None),
1852 ("notify_exec", False, ht.TBool, None),
1853 ("log_messages", ht.EmptyList, ht.TListOf(ht.TString), None),
1854 ("fail", False, ht.TBool, None),
1858 class OpTestDummy(OpCode):
1859 """Utility opcode used by unittests.
1863 ("result", ht.NoDefault, ht.NoType, None),
1864 ("messages", ht.NoDefault, ht.NoType, None),
1865 ("fail", ht.NoDefault, ht.NoType, None),
1866 ("submit_jobs", None, ht.NoType, None),
1872 """Returns list of all defined opcodes.
1874 Does not eliminate duplicates by C{OP_ID}.
1877 return [v for v in globals().values()
1878 if (isinstance(v, type) and issubclass(v, OpCode) and
1879 hasattr(v, "OP_ID") and v is not OpCode)]
1882 OP_MAPPING = dict((v.OP_ID, v) for v in _GetOpList())