4 # Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 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
44 # Common opcode attributes
46 #: output fields for a query operation
47 _POutputFields = ("output_fields", ht.NoDefault, ht.TListOf(ht.TNonEmptyString),
48 "Selected output fields")
50 #: the shutdown timeout
52 ("shutdown_timeout", constants.DEFAULT_SHUTDOWN_TIMEOUT, ht.TPositiveInt,
53 "How long to wait for instance to shut down")
55 #: the force parameter
56 _PForce = ("force", False, ht.TBool, "Whether to force the operation")
58 #: a required instance name (for single-instance LUs)
59 _PInstanceName = ("instance_name", ht.NoDefault, ht.TNonEmptyString,
62 #: Whether to ignore offline nodes
63 _PIgnoreOfflineNodes = ("ignore_offline_nodes", False, ht.TBool,
64 "Whether to ignore offline nodes")
66 #: a required node name (for single-node LUs)
67 _PNodeName = ("node_name", ht.NoDefault, ht.TNonEmptyString, "Node name")
69 #: a required node group name (for single-group LUs)
70 _PGroupName = ("group_name", ht.NoDefault, ht.TNonEmptyString, "Group name")
72 #: Migration type (live/non-live)
73 _PMigrationMode = ("mode", None,
74 ht.TOr(ht.TNone, ht.TElemOf(constants.HT_MIGRATION_MODES)),
77 #: Obsolete 'live' migration mode (boolean)
78 _PMigrationLive = ("live", None, ht.TMaybeBool,
79 "Legacy setting for live migration, do not use")
82 _PTagKind = ("kind", ht.NoDefault, ht.TElemOf(constants.VALID_TAG_TYPES), None)
84 #: List of tag strings
85 _PTags = ("tags", ht.NoDefault, ht.TListOf(ht.TNonEmptyString), None)
87 _PForceVariant = ("force_variant", False, ht.TBool,
88 "Whether to force an unknown OS variant")
90 _PWaitForSync = ("wait_for_sync", True, ht.TBool,
91 "Whether to wait for the disk to synchronize")
93 _PIgnoreConsistency = ("ignore_consistency", False, ht.TBool,
94 "Whether to ignore disk consistency")
96 _PStorageName = ("name", ht.NoDefault, ht.TMaybeString, "Storage name")
98 _PUseLocking = ("use_locking", False, ht.TBool,
99 "Whether to use synchronization")
101 _PNameCheck = ("name_check", True, ht.TBool, "Whether to check name")
103 _PNodeGroupAllocPolicy = \
104 ("alloc_policy", None,
105 ht.TOr(ht.TNone, ht.TElemOf(constants.VALID_ALLOC_POLICIES)),
106 "Instance allocation policy")
108 _PGroupNodeParams = ("ndparams", None, ht.TMaybeDict,
109 "Default node parameters for group")
111 _PQueryWhat = ("what", ht.NoDefault, ht.TElemOf(constants.QR_VIA_OP),
112 "Resource(s) to query for")
114 _PEarlyRelease = ("early_release", False, ht.TBool,
115 "Whether to release locks as soon as possible")
117 _PIpCheckDoc = "Whether to ensure instance's IP address is inactive"
119 #: Do not remember instance state changes
120 _PNoRemember = ("no_remember", False, ht.TBool,
121 "Do not remember the state change")
123 #: Target node for instance migration/failover
124 _PMigrationTargetNode = ("target_node", None, ht.TMaybeString,
125 "Target node for shared-storage instances")
127 _PStartupPaused = ("startup_paused", False, ht.TBool,
128 "Pause instance at startup")
130 _PVerbose = ("verbose", False, ht.TBool, "Verbose mode")
132 # Parameters for cluster verification
133 _PDebugSimulateErrors = ("debug_simulate_errors", False, ht.TBool,
134 "Whether to simulate errors (useful for debugging)")
135 _PErrorCodes = ("error_codes", False, ht.TBool, "Error codes")
136 _PSkipChecks = ("skip_checks", ht.EmptyList,
137 ht.TListOf(ht.TElemOf(constants.VERIFY_OPTIONAL_CHECKS)),
138 "Which checks to skip")
139 _PIgnoreErrors = ("ignore_errors", ht.EmptyList,
140 ht.TListOf(ht.TElemOf(constants.CV_ALL_ECODES_STRINGS)),
141 "List of error codes that should be treated as warnings")
144 _PDiskParams = ("diskparams", None,
146 ht.TDictOf(ht.TElemOf(constants.DISK_TEMPLATES), ht.TDict),
148 "Disk templates' parameter defaults")
150 # Parameters for node resource model
151 _PHvState = ("hv_state", None, ht.TMaybeDict, "Set hypervisor states")
152 _PDiskState = ("disk_state", None, ht.TMaybeDict, "Set disk states")
155 _PIgnoreIpolicy = ("ignore_ipolicy", False, ht.TBool,
156 "Whether to ignore ipolicy violations")
158 # Allow runtime changes while migrating
159 _PAllowRuntimeChgs = ("allow_runtime_changes", True, ht.TBool,
160 "Allow runtime changes (eg. memory ballooning)")
163 #: OP_ID conversion regular expression
164 _OPID_RE = re.compile("([a-z])([A-Z])")
166 #: Utility function for L{OpClusterSetParams}
167 _TestClusterOsListItem = \
168 ht.TAnd(ht.TIsLength(2), ht.TItems([
169 ht.TElemOf(constants.DDMS_VALUES),
173 _TestClusterOsList = ht.TMaybeListOf(_TestClusterOsListItem)
175 # TODO: Generate check from constants.INIC_PARAMS_TYPES
176 #: Utility function for testing NIC definitions
178 ht.Comment("NIC parameters")(ht.TDictOf(ht.TElemOf(constants.INIC_PARAMS),
179 ht.TOr(ht.TNone, ht.TNonEmptyString)))
181 _TSetParamsResultItemItems = [
182 ht.Comment("name of changed parameter")(ht.TNonEmptyString),
183 ht.Comment("new value")(ht.TAny),
186 _TSetParamsResult = \
187 ht.TListOf(ht.TAnd(ht.TIsLength(len(_TSetParamsResultItemItems)),
188 ht.TItems(_TSetParamsResultItemItems)))
190 # TODO: Generate check from constants.IDISK_PARAMS_TYPES (however, not all users
191 # of this check support all parameters)
193 ht.Comment("Disk parameters")(ht.TDictOf(ht.TElemOf(constants.IDISK_PARAMS),
194 ht.TOr(ht.TNonEmptyString, ht.TInt)))
203 #: Attribute name for dependencies
204 DEPEND_ATTR = "depends"
206 #: Attribute name for comment
207 COMMENT_ATTR = "comment"
211 """Convert an opcode class name to an OP_ID.
214 @param name: the class name, as OpXxxYyy
216 @return: the name in the OP_XXXX_YYYY format
219 if not name.startswith("Op"):
221 # Note: (?<=[a-z])(?=[A-Z]) would be ideal, since it wouldn't
222 # consume any input, and hence we would just have all the elements
223 # in the list, one by one; but it seems that split doesn't work on
224 # non-consuming input, hence we have to process the input string a
226 name = _OPID_RE.sub(r"\1,\2", name)
227 elems = name.split(",")
228 return "_".join(n.upper() for n in elems)
231 def RequireFileStorage():
232 """Checks that file storage is enabled.
234 While it doesn't really fit into this module, L{utils} was deemed too large
235 of a dependency to be imported for just one or two functions.
237 @raise errors.OpPrereqError: when file storage is disabled
240 if not constants.ENABLE_FILE_STORAGE:
241 raise errors.OpPrereqError("File storage disabled at configure time",
245 def RequireSharedFileStorage():
246 """Checks that shared file storage is enabled.
248 While it doesn't really fit into this module, L{utils} was deemed too large
249 of a dependency to be imported for just one or two functions.
251 @raise errors.OpPrereqError: when shared file storage is disabled
254 if not constants.ENABLE_SHARED_FILE_STORAGE:
255 raise errors.OpPrereqError("Shared file storage disabled at"
256 " configure time", errors.ECODE_INVAL)
259 @ht.WithDesc("CheckFileStorage")
260 def _CheckFileStorage(value):
261 """Ensures file storage is enabled if used.
264 if value == constants.DT_FILE:
266 elif value == constants.DT_SHARED_FILE:
267 RequireSharedFileStorage()
271 def _BuildDiskTemplateCheck(accept_none):
272 """Builds check for disk template.
274 @type accept_none: bool
275 @param accept_none: whether to accept None as a correct value
279 template_check = ht.TElemOf(constants.DISK_TEMPLATES)
282 template_check = ht.TOr(template_check, ht.TNone)
284 return ht.TAnd(template_check, _CheckFileStorage)
287 def _CheckStorageType(storage_type):
288 """Ensure a given storage type is valid.
291 if storage_type not in constants.VALID_STORAGE_TYPES:
292 raise errors.OpPrereqError("Unknown storage type: %s" % storage_type,
294 if storage_type == constants.ST_FILE:
299 #: Storage type parameter
300 _PStorageType = ("storage_type", ht.NoDefault, _CheckStorageType,
304 class _AutoOpParamSlots(type):
305 """Meta class for opcode definitions.
308 def __new__(mcs, name, bases, attrs):
309 """Called when a class should be created.
311 @param mcs: The meta class
312 @param name: Name of created class
313 @param bases: Base classes
315 @param attrs: Class attributes
318 assert "__slots__" not in attrs, \
319 "Class '%s' defines __slots__ when it should use OP_PARAMS" % name
320 assert "OP_ID" not in attrs, "Class '%s' defining OP_ID" % name
322 attrs["OP_ID"] = _NameToId(name)
324 # Always set OP_PARAMS to avoid duplicates in BaseOpCode.GetAllParams
325 params = attrs.setdefault("OP_PARAMS", [])
327 # Use parameter names as slots
328 slots = [pname for (pname, _, _, _) in params]
330 assert "OP_DSC_FIELD" not in attrs or attrs["OP_DSC_FIELD"] in slots, \
331 "Class '%s' uses unknown field in OP_DSC_FIELD" % name
333 attrs["__slots__"] = slots
335 return type.__new__(mcs, name, bases, attrs)
338 class BaseOpCode(object):
339 """A simple serializable object.
341 This object serves as a parent class for OpCode without any custom
345 # pylint: disable=E1101
346 # as OP_ID is dynamically defined
347 __metaclass__ = _AutoOpParamSlots
349 def __init__(self, **kwargs):
350 """Constructor for BaseOpCode.
352 The constructor takes only keyword arguments and will set
353 attributes on this object based on the passed arguments. As such,
354 it means that you should not pass arguments which are not in the
355 __slots__ attribute for this class.
358 slots = self._all_slots()
361 raise TypeError("Object %s doesn't support the parameter '%s'" %
362 (self.__class__.__name__, key))
363 setattr(self, key, kwargs[key])
365 def __getstate__(self):
366 """Generic serializer.
368 This method just returns the contents of the instance as a
372 @return: the instance attributes and their values
376 for name in self._all_slots():
377 if hasattr(self, name):
378 state[name] = getattr(self, name)
381 def __setstate__(self, state):
382 """Generic unserializer.
384 This method just restores from the serialized state the attributes
385 of the current instance.
387 @param state: the serialized opcode data
391 if not isinstance(state, dict):
392 raise ValueError("Invalid data to __setstate__: expected dict, got %s" %
395 for name in self._all_slots():
396 if name not in state and hasattr(self, name):
400 setattr(self, name, state[name])
404 """Compute the list of all declared slots for a class.
408 for parent in cls.__mro__:
409 slots.extend(getattr(parent, "__slots__", []))
413 def GetAllParams(cls):
414 """Compute list of all parameters for an opcode.
418 for parent in cls.__mro__:
419 slots.extend(getattr(parent, "OP_PARAMS", []))
422 def Validate(self, set_defaults):
423 """Validate opcode parameters, optionally setting default values.
425 @type set_defaults: bool
426 @param set_defaults: Whether to set default values
427 @raise errors.OpPrereqError: When a parameter value doesn't match
431 for (attr_name, default, test, _) in self.GetAllParams():
432 assert test == ht.NoType or callable(test)
434 if not hasattr(self, attr_name):
435 if default == ht.NoDefault:
436 raise errors.OpPrereqError("Required parameter '%s.%s' missing" %
437 (self.OP_ID, attr_name),
440 if callable(default):
444 setattr(self, attr_name, dval)
446 if test == ht.NoType:
450 if set_defaults or hasattr(self, attr_name):
451 attr_val = getattr(self, attr_name)
452 if not test(attr_val):
453 logging.error("OpCode %s, parameter %s, has invalid type %s/value %s",
454 self.OP_ID, attr_name, type(attr_val), attr_val)
455 raise errors.OpPrereqError("Parameter '%s.%s' fails validation" %
456 (self.OP_ID, attr_name),
460 def _BuildJobDepCheck(relative):
461 """Builds check for job dependencies (L{DEPEND_ATTR}).
464 @param relative: Whether to accept relative job IDs (negative)
469 job_id = ht.TOr(ht.TJobId, ht.TRelativeJobId)
474 ht.TAnd(ht.TIsLength(2),
476 ht.TListOf(ht.TElemOf(constants.JOBS_FINALIZED))]))
478 return ht.TMaybeListOf(job_dep)
481 TNoRelativeJobDependencies = _BuildJobDepCheck(False)
483 #: List of submission status and job ID as returned by C{SubmitManyJobs}
485 ht.TAnd(ht.TIsLength(2),
486 ht.TItems([ht.Comment("success")(ht.TBool),
487 ht.Comment("Job ID if successful, error message"
488 " otherwise")(ht.TOr(ht.TString,
490 TJobIdList = ht.TListOf(_TJobIdListItem)
492 #: Result containing only list of submitted jobs
493 TJobIdListOnly = ht.TStrictDict(True, True, {
494 constants.JOB_IDS_KEY: ht.Comment("List of submitted jobs")(TJobIdList),
498 class OpCode(BaseOpCode):
501 This is the root of the actual OpCode hierarchy. All clases derived
502 from this class should override OP_ID.
504 @cvar OP_ID: The ID of this opcode. This should be unique amongst all
505 children of this class.
506 @cvar OP_DSC_FIELD: The name of a field whose value will be included in the
507 string returned by Summary(); see the docstring of that
509 @cvar OP_PARAMS: List of opcode attributes, the default values they should
510 get if not already defined, and types they must match.
511 @cvar OP_RESULT: Callable to verify opcode result
512 @cvar WITH_LU: Boolean that specifies whether this should be included in
513 mcpu's dispatch table
514 @ivar dry_run: Whether the LU should be run in dry-run mode, i.e. just
516 @ivar priority: Opcode priority for queue
519 # pylint: disable=E1101
520 # as OP_ID is dynamically defined
523 ("dry_run", None, ht.TMaybeBool, "Run checks only, don't execute"),
524 ("debug_level", None, ht.TOr(ht.TNone, ht.TPositiveInt), "Debug level"),
525 ("priority", constants.OP_PRIO_DEFAULT,
526 ht.TElemOf(constants.OP_PRIO_SUBMIT_VALID), "Opcode priority"),
527 (DEPEND_ATTR, None, _BuildJobDepCheck(True),
528 "Job dependencies; if used through ``SubmitManyJobs`` relative (negative)"
529 " job IDs can be used; see :doc:`design document <design-chained-jobs>`"
531 (COMMENT_ATTR, None, ht.TMaybeString,
532 "Comment describing the purpose of the opcode"),
536 def __getstate__(self):
537 """Specialized getstate for opcodes.
539 This method adds to the state dictionary the OP_ID of the class,
540 so that on unload we can identify the correct class for
541 instantiating the opcode.
544 @return: the state as a dictionary
547 data = BaseOpCode.__getstate__(self)
548 data["OP_ID"] = self.OP_ID
552 def LoadOpCode(cls, data):
553 """Generic load opcode method.
555 The method identifies the correct opcode class from the dict-form
556 by looking for a OP_ID key, if this is not found, or its value is
557 not available in this module as a child of this class, we fail.
560 @param data: the serialized opcode
563 if not isinstance(data, dict):
564 raise ValueError("Invalid data to LoadOpCode (%s)" % type(data))
565 if "OP_ID" not in data:
566 raise ValueError("Invalid data to LoadOpcode, missing OP_ID")
567 op_id = data["OP_ID"]
569 if op_id in OP_MAPPING:
570 op_class = OP_MAPPING[op_id]
572 raise ValueError("Invalid data to LoadOpCode: OP_ID %s unsupported" %
575 new_data = data.copy()
576 del new_data["OP_ID"]
577 op.__setstate__(new_data)
581 """Generates a summary description of this opcode.
583 The summary is the value of the OP_ID attribute (without the "OP_"
584 prefix), plus the value of the OP_DSC_FIELD attribute, if one was
585 defined; this field should allow to easily identify the operation
586 (for an instance creation job, e.g., it would be the instance
590 assert self.OP_ID is not None and len(self.OP_ID) > 3
591 # all OP_ID start with OP_, we remove that
593 field_name = getattr(self, "OP_DSC_FIELD", None)
595 field_value = getattr(self, field_name, None)
596 if isinstance(field_value, (list, tuple)):
597 field_value = ",".join(str(i) for i in field_value)
598 txt = "%s(%s)" % (txt, field_value)
601 def TinySummary(self):
602 """Generates a compact summary description of the opcode.
605 assert self.OP_ID.startswith("OP_")
607 text = self.OP_ID[3:]
609 for (prefix, supplement) in _SUMMARY_PREFIX.items():
610 if text.startswith(prefix):
611 return supplement + text[len(prefix):]
618 class OpClusterPostInit(OpCode):
619 """Post cluster initialization.
621 This opcode does not touch the cluster at all. Its purpose is to run hooks
622 after the cluster has been initialized.
627 class OpClusterDestroy(OpCode):
628 """Destroy the cluster.
630 This opcode has no other parameters. All the state is irreversibly
631 lost after the execution of this opcode.
636 class OpClusterQuery(OpCode):
637 """Query cluster information."""
640 class OpClusterVerify(OpCode):
641 """Submits all jobs necessary to verify the cluster.
645 _PDebugSimulateErrors,
650 ("group_name", None, ht.TMaybeString, "Group to verify")
652 OP_RESULT = TJobIdListOnly
655 class OpClusterVerifyConfig(OpCode):
656 """Verify the cluster config.
660 _PDebugSimulateErrors,
668 class OpClusterVerifyGroup(OpCode):
669 """Run verify on a node group from the cluster.
671 @type skip_checks: C{list}
672 @ivar skip_checks: steps to be skipped from the verify process; this
673 needs to be a subset of
674 L{constants.VERIFY_OPTIONAL_CHECKS}; currently
675 only L{constants.VERIFY_NPLUSONE_MEM} can be passed
678 OP_DSC_FIELD = "group_name"
681 _PDebugSimulateErrors,
690 class OpClusterVerifyDisks(OpCode):
691 """Verify the cluster disks.
694 OP_RESULT = TJobIdListOnly
697 class OpGroupVerifyDisks(OpCode):
698 """Verifies the status of all disks in a node group.
700 Result: a tuple of three elements:
701 - dict of node names with issues (values: error msg)
702 - list of instances with degraded disks (that should be activated)
703 - dict of instances with missing logical volumes (values: (node, vol)
704 pairs with details about the missing volumes)
706 In normal operation, all lists should be empty. A non-empty instance
707 list (3rd element of the result) is still ok (errors were fixed) but
708 non-empty node list means some node is down, and probably there are
709 unfixable drbd errors.
711 Note that only instances that are drbd-based are taken into
712 consideration. This might need to be revisited in the future.
715 OP_DSC_FIELD = "group_name"
720 ht.TAnd(ht.TIsLength(3),
721 ht.TItems([ht.TDictOf(ht.TString, ht.TString),
722 ht.TListOf(ht.TString),
723 ht.TDictOf(ht.TString,
724 ht.TListOf(ht.TListOf(ht.TString)))]))
727 class OpClusterRepairDiskSizes(OpCode):
728 """Verify the disk sizes of the instances and fixes configuration
731 Parameters: optional instances list, in case we want to restrict the
732 checks to only a subset of the instances.
734 Result: a list of tuples, (instance, disk, new-size) for changed
737 In normal operation, the list should be empty.
739 @type instances: list
740 @ivar instances: the list of instances to check, or empty for all instances
744 ("instances", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), None),
748 class OpClusterConfigQuery(OpCode):
749 """Query cluster configuration values."""
755 class OpClusterRename(OpCode):
756 """Rename the cluster.
759 @ivar name: The new name of the cluster. The name and/or the master IP
760 address will be changed to match the new name and its IP
764 OP_DSC_FIELD = "name"
766 ("name", ht.NoDefault, ht.TNonEmptyString, None),
770 class OpClusterSetParams(OpCode):
771 """Change the parameters of the cluster.
773 @type vg_name: C{str} or C{None}
774 @ivar vg_name: The new volume group name or None to disable LVM usage.
780 ("vg_name", None, ht.TMaybeString, "Volume group name"),
781 ("enabled_hypervisors", None,
782 ht.TOr(ht.TAnd(ht.TListOf(ht.TElemOf(constants.HYPER_TYPES)), ht.TTrue),
784 "List of enabled hypervisors"),
785 ("hvparams", None, ht.TOr(ht.TDictOf(ht.TNonEmptyString, ht.TDict),
787 "Cluster-wide hypervisor parameter defaults, hypervisor-dependent"),
788 ("beparams", None, ht.TOr(ht.TDict, ht.TNone),
789 "Cluster-wide backend parameter defaults"),
790 ("os_hvp", None, ht.TOr(ht.TDictOf(ht.TNonEmptyString, ht.TDict),
792 "Cluster-wide per-OS hypervisor parameter defaults"),
793 ("osparams", None, ht.TOr(ht.TDictOf(ht.TNonEmptyString, ht.TDict),
795 "Cluster-wide OS parameter defaults"),
797 ("candidate_pool_size", None, ht.TOr(ht.TStrictPositiveInt, ht.TNone),
798 "Master candidate pool size"),
799 ("uid_pool", None, ht.NoType,
800 "Set UID pool, must be list of lists describing UID ranges (two items,"
801 " start and end inclusive)"),
802 ("add_uids", None, ht.NoType,
803 "Extend UID pool, must be list of lists describing UID ranges (two"
804 " items, start and end inclusive) to be added"),
805 ("remove_uids", None, ht.NoType,
806 "Shrink UID pool, must be list of lists describing UID ranges (two"
807 " items, start and end inclusive) to be removed"),
808 ("maintain_node_health", None, ht.TMaybeBool,
809 "Whether to automatically maintain node health"),
810 ("prealloc_wipe_disks", None, ht.TMaybeBool,
811 "Whether to wipe disks before allocating them to instances"),
812 ("nicparams", None, ht.TMaybeDict, "Cluster-wide NIC parameter defaults"),
813 ("ndparams", None, ht.TMaybeDict, "Cluster-wide node parameter defaults"),
814 ("ipolicy", None, ht.TMaybeDict,
815 "Cluster-wide :ref:`instance policy <rapi-ipolicy>` specs"),
816 ("drbd_helper", None, ht.TOr(ht.TString, ht.TNone), "DRBD helper program"),
817 ("default_iallocator", None, ht.TOr(ht.TString, ht.TNone),
818 "Default iallocator for cluster"),
819 ("master_netdev", None, ht.TOr(ht.TString, ht.TNone),
820 "Master network device"),
821 ("master_netmask", None, ht.TOr(ht.TInt, ht.TNone),
822 "Netmask of the master IP"),
823 ("reserved_lvs", None, ht.TMaybeListOf(ht.TNonEmptyString),
824 "List of reserved LVs"),
825 ("hidden_os", None, _TestClusterOsList,
826 "Modify list of hidden operating systems. Each modification must have"
827 " two items, the operation and the OS name. The operation can be"
828 " ``%s`` or ``%s``." % (constants.DDM_ADD, constants.DDM_REMOVE)),
829 ("blacklisted_os", None, _TestClusterOsList,
830 "Modify list of blacklisted operating systems. Each modification must have"
831 " two items, the operation and the OS name. The operation can be"
832 " ``%s`` or ``%s``." % (constants.DDM_ADD, constants.DDM_REMOVE)),
833 ("use_external_mip_script", None, ht.TMaybeBool,
834 "Whether to use an external master IP address setup script"),
838 class OpClusterRedistConf(OpCode):
839 """Force a full push of the cluster configuration.
844 class OpClusterActivateMasterIp(OpCode):
845 """Activate the master IP on the master node.
850 class OpClusterDeactivateMasterIp(OpCode):
851 """Deactivate the master IP on the master node.
856 class OpQuery(OpCode):
857 """Query for resources/items.
859 @ivar what: Resources to query for, must be one of L{constants.QR_VIA_OP}
860 @ivar fields: List of fields to retrieve
861 @ivar qfilter: Query filter
864 OP_DSC_FIELD = "what"
868 ("fields", ht.NoDefault, ht.TListOf(ht.TNonEmptyString),
870 ("qfilter", None, ht.TOr(ht.TNone, ht.TListOf),
875 class OpQueryFields(OpCode):
876 """Query for available resource/item fields.
878 @ivar what: Resources to query for, must be one of L{constants.QR_VIA_OP}
879 @ivar fields: List of fields to retrieve
882 OP_DSC_FIELD = "what"
885 ("fields", None, ht.TMaybeListOf(ht.TNonEmptyString),
886 "Requested fields; if not given, all are returned"),
890 class OpOobCommand(OpCode):
891 """Interact with OOB."""
893 ("node_names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
894 "List of nodes to run the OOB command against"),
895 ("command", None, ht.TElemOf(constants.OOB_COMMANDS),
896 "OOB command to be run"),
897 ("timeout", constants.OOB_TIMEOUT, ht.TInt,
898 "Timeout before the OOB helper will be terminated"),
899 ("ignore_status", False, ht.TBool,
900 "Ignores the node offline status for power off"),
901 ("power_delay", constants.OOB_POWER_DELAY, ht.TPositiveFloat,
902 "Time in seconds to wait between powering on nodes"),
908 class OpNodeRemove(OpCode):
911 @type node_name: C{str}
912 @ivar node_name: The name of the node to remove. If the node still has
913 instances on it, the operation will fail.
916 OP_DSC_FIELD = "node_name"
922 class OpNodeAdd(OpCode):
923 """Add a node to the cluster.
925 @type node_name: C{str}
926 @ivar node_name: The name of the node to add. This can be a short name,
927 but it will be expanded to the FQDN.
928 @type primary_ip: IP address
929 @ivar primary_ip: The primary IP of the node. This will be ignored when the
930 opcode is submitted, but will be filled during the node
931 add (so it will be visible in the job query).
932 @type secondary_ip: IP address
933 @ivar secondary_ip: The secondary IP of the node. This needs to be passed
934 if the cluster has been initialized in 'dual-network'
935 mode, otherwise it must not be given.
937 @ivar readd: Whether to re-add an existing node to the cluster. If
938 this is not passed, then the operation will abort if the node
939 name is already in the cluster; use this parameter to 'repair'
940 a node that had its configuration broken, or was reinstalled
941 without removal from the cluster.
943 @ivar group: The node group to which this node will belong.
944 @type vm_capable: C{bool}
945 @ivar vm_capable: The vm_capable node attribute
946 @type master_capable: C{bool}
947 @ivar master_capable: The master_capable node attribute
950 OP_DSC_FIELD = "node_name"
955 ("primary_ip", None, ht.NoType, "Primary IP address"),
956 ("secondary_ip", None, ht.TMaybeString, "Secondary IP address"),
957 ("readd", False, ht.TBool, "Whether node is re-added to cluster"),
958 ("group", None, ht.TMaybeString, "Initial node group"),
959 ("master_capable", None, ht.TMaybeBool,
960 "Whether node can become master or master candidate"),
961 ("vm_capable", None, ht.TMaybeBool,
962 "Whether node can host instances"),
963 ("ndparams", None, ht.TMaybeDict, "Node parameters"),
967 class OpNodeQuery(OpCode):
968 """Compute the list of nodes."""
972 ("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
973 "Empty list to query all nodes, node names otherwise"),
977 class OpNodeQueryvols(OpCode):
978 """Get list of volumes on node."""
981 ("nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
982 "Empty list to query all nodes, node names otherwise"),
986 class OpNodeQueryStorage(OpCode):
987 """Get information on storage for node(s)."""
991 ("nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), "List of nodes"),
992 ("name", None, ht.TMaybeString, "Storage name"),
996 class OpNodeModifyStorage(OpCode):
997 """Modifies the properies of a storage unit"""
1002 ("changes", ht.NoDefault, ht.TDict, "Requested changes"),
1006 class OpRepairNodeStorage(OpCode):
1007 """Repairs the volume group on a node."""
1008 OP_DSC_FIELD = "node_name"
1013 _PIgnoreConsistency,
1017 class OpNodeSetParams(OpCode):
1018 """Change the parameters of a node."""
1019 OP_DSC_FIELD = "node_name"
1025 ("master_candidate", None, ht.TMaybeBool,
1026 "Whether the node should become a master candidate"),
1027 ("offline", None, ht.TMaybeBool,
1028 "Whether the node should be marked as offline"),
1029 ("drained", None, ht.TMaybeBool,
1030 "Whether the node should be marked as drained"),
1031 ("auto_promote", False, ht.TBool,
1032 "Whether node(s) should be promoted to master candidate if necessary"),
1033 ("master_capable", None, ht.TMaybeBool,
1034 "Denote whether node can become master or master candidate"),
1035 ("vm_capable", None, ht.TMaybeBool,
1036 "Denote whether node can host instances"),
1037 ("secondary_ip", None, ht.TMaybeString,
1038 "Change node's secondary IP address"),
1039 ("ndparams", None, ht.TMaybeDict, "Set node parameters"),
1040 ("powered", None, ht.TMaybeBool,
1041 "Whether the node should be marked as powered"),
1043 OP_RESULT = _TSetParamsResult
1046 class OpNodePowercycle(OpCode):
1047 """Tries to powercycle a node."""
1048 OP_DSC_FIELD = "node_name"
1055 class OpNodeMigrate(OpCode):
1056 """Migrate all instances from a node."""
1057 OP_DSC_FIELD = "node_name"
1062 _PMigrationTargetNode,
1065 ("iallocator", None, ht.TMaybeString,
1066 "Iallocator for deciding the target node for shared-storage instances"),
1068 OP_RESULT = TJobIdListOnly
1071 class OpNodeEvacuate(OpCode):
1072 """Evacuate instances off a number of nodes."""
1073 OP_DSC_FIELD = "node_name"
1077 ("remote_node", None, ht.TMaybeString, "New secondary node"),
1078 ("iallocator", None, ht.TMaybeString, "Iallocator for computing solution"),
1079 ("mode", ht.NoDefault, ht.TElemOf(constants.NODE_EVAC_MODES),
1080 "Node evacuation mode"),
1082 OP_RESULT = TJobIdListOnly
1087 class OpInstanceCreate(OpCode):
1088 """Create an instance.
1090 @ivar instance_name: Instance name
1091 @ivar mode: Instance creation mode (one of L{constants.INSTANCE_CREATE_MODES})
1092 @ivar source_handshake: Signed handshake from source (remote import only)
1093 @ivar source_x509_ca: Source X509 CA in PEM format (remote import only)
1094 @ivar source_instance_name: Previous name of instance (remote import only)
1095 @ivar source_shutdown_timeout: Shutdown timeout used for source instance
1096 (remote import only)
1099 OP_DSC_FIELD = "instance_name"
1106 ("beparams", ht.EmptyDict, ht.TDict, "Backend parameters for instance"),
1107 ("disks", ht.NoDefault, ht.TListOf(_TDiskParams),
1108 "Disk descriptions, for example ``[{\"%s\": 100}, {\"%s\": 5}]``;"
1109 " each disk definition must contain a ``%s`` value and"
1110 " can contain an optional ``%s`` value denoting the disk access mode"
1112 (constants.IDISK_SIZE, constants.IDISK_SIZE, constants.IDISK_SIZE,
1113 constants.IDISK_MODE,
1114 " or ".join("``%s``" % i for i in sorted(constants.DISK_ACCESS_SET)))),
1115 ("disk_template", ht.NoDefault, _BuildDiskTemplateCheck(True),
1117 ("file_driver", None, ht.TOr(ht.TNone, ht.TElemOf(constants.FILE_DRIVER)),
1118 "Driver for file-backed disks"),
1119 ("file_storage_dir", None, ht.TMaybeString,
1120 "Directory for storing file-backed disks"),
1121 ("hvparams", ht.EmptyDict, ht.TDict,
1122 "Hypervisor parameters for instance, hypervisor-dependent"),
1123 ("hypervisor", None, ht.TMaybeString, "Hypervisor"),
1124 ("iallocator", None, ht.TMaybeString,
1125 "Iallocator for deciding which node(s) to use"),
1126 ("identify_defaults", False, ht.TBool,
1127 "Reset instance parameters to default if equal"),
1128 ("ip_check", True, ht.TBool, _PIpCheckDoc),
1129 ("mode", ht.NoDefault, ht.TElemOf(constants.INSTANCE_CREATE_MODES),
1130 "Instance creation mode"),
1131 ("nics", ht.NoDefault, ht.TListOf(_TestNicDef),
1132 "List of NIC (network interface) definitions, for example"
1133 " ``[{}, {}, {\"%s\": \"198.51.100.4\"}]``; each NIC definition can"
1134 " contain the optional values %s" %
1136 ", ".join("``%s``" % i for i in sorted(constants.INIC_PARAMS)))),
1137 ("no_install", None, ht.TMaybeBool,
1138 "Do not install the OS (will disable automatic start)"),
1139 ("osparams", ht.EmptyDict, ht.TDict, "OS parameters for instance"),
1140 ("os_type", None, ht.TMaybeString, "Operating system"),
1141 ("pnode", None, ht.TMaybeString, "Primary node"),
1142 ("snode", None, ht.TMaybeString, "Secondary node"),
1143 ("source_handshake", None, ht.TOr(ht.TList, ht.TNone),
1144 "Signed handshake from source (remote import only)"),
1145 ("source_instance_name", None, ht.TMaybeString,
1146 "Source instance name (remote import only)"),
1147 ("source_shutdown_timeout", constants.DEFAULT_SHUTDOWN_TIMEOUT,
1149 "How long source instance was given to shut down (remote import only)"),
1150 ("source_x509_ca", None, ht.TMaybeString,
1151 "Source X509 CA in PEM format (remote import only)"),
1152 ("src_node", None, ht.TMaybeString, "Source node for import"),
1153 ("src_path", None, ht.TMaybeString, "Source directory for import"),
1154 ("start", True, ht.TBool, "Whether to start instance after creation"),
1155 ("tags", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), "Instance tags"),
1157 OP_RESULT = ht.Comment("instance nodes")(ht.TListOf(ht.TNonEmptyString))
1160 class OpInstanceReinstall(OpCode):
1161 """Reinstall an instance's OS."""
1162 OP_DSC_FIELD = "instance_name"
1166 ("os_type", None, ht.TMaybeString, "Instance operating system"),
1167 ("osparams", None, ht.TMaybeDict, "Temporary OS parameters"),
1171 class OpInstanceRemove(OpCode):
1172 """Remove an instance."""
1173 OP_DSC_FIELD = "instance_name"
1177 ("ignore_failures", False, ht.TBool,
1178 "Whether to ignore failures during removal"),
1182 class OpInstanceRename(OpCode):
1183 """Rename an instance."""
1187 ("new_name", ht.NoDefault, ht.TNonEmptyString, "New instance name"),
1188 ("ip_check", False, ht.TBool, _PIpCheckDoc),
1190 OP_RESULT = ht.Comment("New instance name")(ht.TNonEmptyString)
1193 class OpInstanceStartup(OpCode):
1194 """Startup an instance."""
1195 OP_DSC_FIELD = "instance_name"
1199 _PIgnoreOfflineNodes,
1200 ("hvparams", ht.EmptyDict, ht.TDict,
1201 "Temporary hypervisor parameters, hypervisor-dependent"),
1202 ("beparams", ht.EmptyDict, ht.TDict, "Temporary backend parameters"),
1208 class OpInstanceShutdown(OpCode):
1209 """Shutdown an instance."""
1210 OP_DSC_FIELD = "instance_name"
1213 _PIgnoreOfflineNodes,
1214 ("timeout", constants.DEFAULT_SHUTDOWN_TIMEOUT, ht.TPositiveInt,
1215 "How long to wait for instance to shut down"),
1220 class OpInstanceReboot(OpCode):
1221 """Reboot an instance."""
1222 OP_DSC_FIELD = "instance_name"
1226 ("ignore_secondaries", False, ht.TBool,
1227 "Whether to start the instance even if secondary disks are failing"),
1228 ("reboot_type", ht.NoDefault, ht.TElemOf(constants.REBOOT_TYPES),
1229 "How to reboot instance"),
1233 class OpInstanceReplaceDisks(OpCode):
1234 """Replace the disks of an instance."""
1235 OP_DSC_FIELD = "instance_name"
1240 ("mode", ht.NoDefault, ht.TElemOf(constants.REPLACE_MODES),
1241 "Replacement mode"),
1242 ("disks", ht.EmptyList, ht.TListOf(ht.TPositiveInt),
1244 ("remote_node", None, ht.TMaybeString, "New secondary node"),
1245 ("iallocator", None, ht.TMaybeString,
1246 "Iallocator for deciding new secondary node"),
1250 class OpInstanceFailover(OpCode):
1251 """Failover an instance."""
1252 OP_DSC_FIELD = "instance_name"
1256 _PIgnoreConsistency,
1257 _PMigrationTargetNode,
1259 ("iallocator", None, ht.TMaybeString,
1260 "Iallocator for deciding the target node for shared-storage instances"),
1264 class OpInstanceMigrate(OpCode):
1265 """Migrate an instance.
1267 This migrates (without shutting down an instance) to its secondary
1270 @ivar instance_name: the name of the instance
1271 @ivar mode: the migration mode (live, non-live or None for auto)
1274 OP_DSC_FIELD = "instance_name"
1279 _PMigrationTargetNode,
1282 ("cleanup", False, ht.TBool,
1283 "Whether a previously failed migration should be cleaned up"),
1284 ("iallocator", None, ht.TMaybeString,
1285 "Iallocator for deciding the target node for shared-storage instances"),
1286 ("allow_failover", False, ht.TBool,
1287 "Whether we can fallback to failover if migration is not possible"),
1291 class OpInstanceMove(OpCode):
1292 """Move an instance.
1294 This move (with shutting down an instance and data copying) to an
1297 @ivar instance_name: the name of the instance
1298 @ivar target_node: the destination node
1301 OP_DSC_FIELD = "instance_name"
1306 ("target_node", ht.NoDefault, ht.TNonEmptyString, "Target node"),
1307 _PIgnoreConsistency,
1311 class OpInstanceConsole(OpCode):
1312 """Connect to an instance's console."""
1313 OP_DSC_FIELD = "instance_name"
1319 class OpInstanceActivateDisks(OpCode):
1320 """Activate an instance's disks."""
1321 OP_DSC_FIELD = "instance_name"
1324 ("ignore_size", False, ht.TBool, "Whether to ignore recorded size"),
1328 class OpInstanceDeactivateDisks(OpCode):
1329 """Deactivate an instance's disks."""
1330 OP_DSC_FIELD = "instance_name"
1337 class OpInstanceRecreateDisks(OpCode):
1338 """Recreate an instance's disks."""
1340 ht.TAnd(ht.TIsLength(2),
1341 ht.TItems([ht.Comment("Disk index")(ht.TPositiveInt),
1342 ht.Comment("Parameters")(_TDiskParams)]))
1344 OP_DSC_FIELD = "instance_name"
1347 ("disks", ht.EmptyList,
1348 ht.TOr(ht.TListOf(ht.TPositiveInt), ht.TListOf(_TDiskChanges)),
1349 "List of disk indexes (deprecated) or a list of tuples containing a disk"
1350 " index and a possibly empty dictionary with disk parameter changes"),
1351 ("nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
1352 "New instance nodes, if relocation is desired"),
1356 class OpInstanceQuery(OpCode):
1357 """Compute the list of instances."""
1361 ("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
1362 "Empty list to query all instances, instance names otherwise"),
1366 class OpInstanceQueryData(OpCode):
1367 """Compute the run-time status of instances."""
1370 ("instances", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
1372 ("static", False, ht.TBool,
1373 "Whether to only return configuration data without querying"
1378 def _TestInstSetParamsModList(fn):
1379 """Generates a check for modification lists.
1383 # TODO: Remove in version 2.8 including support in LUInstanceSetParams
1385 ht.TAnd(ht.TIsLength(2), ht.TItems([
1386 ht.TOr(ht.TElemOf(constants.DDMS_VALUES), ht.TPositiveInt),
1390 # New format, supporting adding/removing disks/NICs at arbitrary indices
1392 ht.TAnd(ht.TIsLength(3), ht.TItems([
1393 ht.TElemOf(constants.DDMS_VALUES_WITH_MODIFY),
1394 ht.Comment("Disk index, can be negative, e.g. -1 for last disk")(ht.TInt),
1398 return ht.TOr(ht.Comment("Recommended")(ht.TListOf(mod_item_fn)),
1399 ht.Comment("Deprecated")(ht.TListOf(old_mod_item_fn)))
1402 class OpInstanceSetParams(OpCode):
1403 """Change the parameters of an instance.
1406 TestNicModifications = _TestInstSetParamsModList(_TestNicDef)
1407 TestDiskModifications = _TestInstSetParamsModList(_TDiskParams)
1409 OP_DSC_FIELD = "instance_name"
1415 ("nics", ht.EmptyList, TestNicModifications,
1416 "List of NIC changes. Each item is of the form ``(op, index, settings)``."
1417 " ``op`` is one of ``%s``, ``%s`` or ``%s``. ``index`` can be either -1 to"
1418 " refer to the last position, or a zero-based index number. A deprecated"
1419 " version of this parameter used the form ``(op, settings)``, where "
1420 " ``op`` can be ``%s`` to add a new NIC with the specified settings,"
1421 " ``%s`` to remove the last NIC or a number to modify the settings"
1422 " of the NIC with that index." %
1423 (constants.DDM_ADD, constants.DDM_MODIFY, constants.DDM_REMOVE,
1424 constants.DDM_ADD, constants.DDM_REMOVE)),
1425 ("disks", ht.EmptyList, TestDiskModifications,
1426 "List of disk changes. See ``nics``."),
1427 ("beparams", ht.EmptyDict, ht.TDict, "Per-instance backend parameters"),
1428 ("runtime_mem", None, ht.TMaybeStrictPositiveInt, "New runtime memory"),
1429 ("hvparams", ht.EmptyDict, ht.TDict,
1430 "Per-instance hypervisor parameters, hypervisor-dependent"),
1431 ("disk_template", None, ht.TOr(ht.TNone, _BuildDiskTemplateCheck(False)),
1432 "Disk template for instance"),
1433 ("remote_node", None, ht.TMaybeString,
1434 "Secondary node (used when changing disk template)"),
1435 ("os_name", None, ht.TMaybeString,
1436 "Change instance's OS name. Does not reinstall the instance."),
1437 ("osparams", None, ht.TMaybeDict, "Per-instance OS parameters"),
1438 ("wait_for_sync", True, ht.TBool,
1439 "Whether to wait for the disk to synchronize, when changing template"),
1440 ("offline", None, ht.TMaybeBool, "Whether to mark instance as offline"),
1442 OP_RESULT = _TSetParamsResult
1445 class OpInstanceGrowDisk(OpCode):
1446 """Grow a disk of an instance."""
1447 OP_DSC_FIELD = "instance_name"
1451 ("disk", ht.NoDefault, ht.TInt, "Disk index"),
1452 ("amount", ht.NoDefault, ht.TInt,
1453 "Amount of disk space to add (megabytes)"),
1457 class OpInstanceChangeGroup(OpCode):
1458 """Moves an instance to another node group."""
1459 OP_DSC_FIELD = "instance_name"
1463 ("iallocator", None, ht.TMaybeString, "Iallocator for computing solution"),
1464 ("target_groups", None, ht.TMaybeListOf(ht.TNonEmptyString),
1465 "Destination group names or UUIDs (defaults to \"all but current group\""),
1467 OP_RESULT = TJobIdListOnly
1470 # Node group opcodes
1472 class OpGroupAdd(OpCode):
1473 """Add a node group to the cluster."""
1474 OP_DSC_FIELD = "group_name"
1477 _PNodeGroupAllocPolicy,
1482 ("ipolicy", None, ht.TMaybeDict,
1483 "Group-wide :ref:`instance policy <rapi-ipolicy>` specs"),
1487 class OpGroupAssignNodes(OpCode):
1488 """Assign nodes to a node group."""
1489 OP_DSC_FIELD = "group_name"
1493 ("nodes", ht.NoDefault, ht.TListOf(ht.TNonEmptyString),
1494 "List of nodes to assign"),
1498 class OpGroupQuery(OpCode):
1499 """Compute the list of node groups."""
1502 ("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
1503 "Empty list to query all groups, group names otherwise"),
1507 class OpGroupSetParams(OpCode):
1508 """Change the parameters of a node group."""
1509 OP_DSC_FIELD = "group_name"
1512 _PNodeGroupAllocPolicy,
1517 ("ipolicy", None, ht.TMaybeDict, "Group-wide instance policy specs"),
1519 OP_RESULT = _TSetParamsResult
1522 class OpGroupRemove(OpCode):
1523 """Remove a node group from the cluster."""
1524 OP_DSC_FIELD = "group_name"
1530 class OpGroupRename(OpCode):
1531 """Rename a node group in the cluster."""
1534 ("new_name", ht.NoDefault, ht.TNonEmptyString, "New group name"),
1536 OP_RESULT = ht.Comment("New group name")(ht.TNonEmptyString)
1539 class OpGroupEvacuate(OpCode):
1540 """Evacuate a node group in the cluster."""
1541 OP_DSC_FIELD = "group_name"
1545 ("iallocator", None, ht.TMaybeString, "Iallocator for computing solution"),
1546 ("target_groups", None, ht.TMaybeListOf(ht.TNonEmptyString),
1547 "Destination group names or UUIDs"),
1549 OP_RESULT = TJobIdListOnly
1553 class OpOsDiagnose(OpCode):
1554 """Compute the list of guest operating systems."""
1557 ("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
1558 "Which operating systems to diagnose"),
1563 class OpBackupQuery(OpCode):
1564 """Compute the list of exported images."""
1567 ("nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
1568 "Empty list to query all nodes, node names otherwise"),
1572 class OpBackupPrepare(OpCode):
1573 """Prepares an instance export.
1575 @ivar instance_name: Instance name
1576 @ivar mode: Export mode (one of L{constants.EXPORT_MODES})
1579 OP_DSC_FIELD = "instance_name"
1582 ("mode", ht.NoDefault, ht.TElemOf(constants.EXPORT_MODES),
1587 class OpBackupExport(OpCode):
1588 """Export an instance.
1590 For local exports, the export destination is the node name. For remote
1591 exports, the export destination is a list of tuples, each consisting of
1592 hostname/IP address, port, HMAC and HMAC salt. The HMAC is calculated using
1593 the cluster domain secret over the value "${index}:${hostname}:${port}". The
1594 destination X509 CA must be a signed certificate.
1596 @ivar mode: Export mode (one of L{constants.EXPORT_MODES})
1597 @ivar target_node: Export destination
1598 @ivar x509_key_name: X509 key to use (remote export only)
1599 @ivar destination_x509_ca: Destination X509 CA in PEM format (remote export
1603 OP_DSC_FIELD = "instance_name"
1607 # TODO: Rename target_node as it changes meaning for different export modes
1608 # (e.g. "destination")
1609 ("target_node", ht.NoDefault, ht.TOr(ht.TNonEmptyString, ht.TList),
1610 "Destination information, depends on export mode"),
1611 ("shutdown", True, ht.TBool, "Whether to shutdown instance before export"),
1612 ("remove_instance", False, ht.TBool,
1613 "Whether to remove instance after export"),
1614 ("ignore_remove_failures", False, ht.TBool,
1615 "Whether to ignore failures while removing instances"),
1616 ("mode", constants.EXPORT_MODE_LOCAL, ht.TElemOf(constants.EXPORT_MODES),
1618 ("x509_key_name", None, ht.TOr(ht.TList, ht.TNone),
1619 "Name of X509 key (remote export only)"),
1620 ("destination_x509_ca", None, ht.TMaybeString,
1621 "Destination X509 CA (remote export only)"),
1625 class OpBackupRemove(OpCode):
1626 """Remove an instance's export."""
1627 OP_DSC_FIELD = "instance_name"
1634 class OpTagsGet(OpCode):
1635 """Returns the tags of the given object."""
1636 OP_DSC_FIELD = "name"
1639 # Name is only meaningful for nodes and instances
1640 ("name", ht.NoDefault, ht.TMaybeString, None),
1644 class OpTagsSearch(OpCode):
1645 """Searches the tags in the cluster for a given pattern."""
1646 OP_DSC_FIELD = "pattern"
1648 ("pattern", ht.NoDefault, ht.TNonEmptyString, None),
1652 class OpTagsSet(OpCode):
1653 """Add a list of tags on a given object."""
1657 # Name is only meaningful for nodes and instances
1658 ("name", ht.NoDefault, ht.TMaybeString, None),
1662 class OpTagsDel(OpCode):
1663 """Remove a list of tags from a given object."""
1667 # Name is only meaningful for nodes and instances
1668 ("name", ht.NoDefault, ht.TMaybeString, None),
1673 class OpTestDelay(OpCode):
1674 """Sleeps for a configured amount of time.
1676 This is used just for debugging and testing.
1679 - duration: the time to sleep
1680 - on_master: if true, sleep on the master
1681 - on_nodes: list of nodes in which to sleep
1683 If the on_master parameter is true, it will execute a sleep on the
1684 master (before any node sleep).
1686 If the on_nodes list is not empty, it will sleep on those nodes
1687 (after the sleep on the master, if that is enabled).
1689 As an additional feature, the case of duration < 0 will be reported
1690 as an execution error, so this opcode can be used as a failure
1691 generator. The case of duration == 0 will not be treated specially.
1694 OP_DSC_FIELD = "duration"
1696 ("duration", ht.NoDefault, ht.TNumber, None),
1697 ("on_master", True, ht.TBool, None),
1698 ("on_nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), None),
1699 ("repeat", 0, ht.TPositiveInt, None),
1703 class OpTestAllocator(OpCode):
1704 """Allocator framework testing.
1706 This opcode has two modes:
1707 - gather and return allocator input for a given mode (allocate new
1708 or replace secondary) and a given instance definition (direction
1710 - run a selected allocator for a given operation (as above) and
1711 return the allocator output (direction 'out')
1714 OP_DSC_FIELD = "allocator"
1716 ("direction", ht.NoDefault,
1717 ht.TElemOf(constants.VALID_IALLOCATOR_DIRECTIONS), None),
1718 ("mode", ht.NoDefault, ht.TElemOf(constants.VALID_IALLOCATOR_MODES), None),
1719 ("name", ht.NoDefault, ht.TNonEmptyString, None),
1720 ("nics", ht.NoDefault,
1721 ht.TMaybeListOf(ht.TDictOf(ht.TElemOf([constants.INIC_MAC,
1724 ht.TOr(ht.TNone, ht.TNonEmptyString))),
1726 ("disks", ht.NoDefault, ht.TOr(ht.TNone, ht.TList), None),
1727 ("hypervisor", None, ht.TMaybeString, None),
1728 ("allocator", None, ht.TMaybeString, None),
1729 ("tags", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), None),
1730 ("memory", None, ht.TOr(ht.TNone, ht.TPositiveInt), None),
1731 ("vcpus", None, ht.TOr(ht.TNone, ht.TPositiveInt), None),
1732 ("os", None, ht.TMaybeString, None),
1733 ("disk_template", None, ht.TMaybeString, None),
1734 ("instances", None, ht.TMaybeListOf(ht.TNonEmptyString), None),
1736 ht.TOr(ht.TNone, ht.TElemOf(constants.IALLOCATOR_NEVAC_MODES)), None),
1737 ("target_groups", None, ht.TMaybeListOf(ht.TNonEmptyString), None),
1741 class OpTestJqueue(OpCode):
1742 """Utility opcode to test some aspects of the job queue.
1746 ("notify_waitlock", False, ht.TBool, None),
1747 ("notify_exec", False, ht.TBool, None),
1748 ("log_messages", ht.EmptyList, ht.TListOf(ht.TString), None),
1749 ("fail", False, ht.TBool, None),
1753 class OpTestDummy(OpCode):
1754 """Utility opcode used by unittests.
1758 ("result", ht.NoDefault, ht.NoType, None),
1759 ("messages", ht.NoDefault, ht.NoType, None),
1760 ("fail", ht.NoDefault, ht.NoType, None),
1761 ("submit_jobs", None, ht.NoType, None),
1767 """Returns list of all defined opcodes.
1769 Does not eliminate duplicates by C{OP_ID}.
1772 return [v for v in globals().values()
1773 if (isinstance(v, type) and issubclass(v, OpCode) and
1774 hasattr(v, "OP_ID") and v is not OpCode)]
1777 OP_MAPPING = dict((v.OP_ID, v) for v in _GetOpList())