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 compat
40 from ganeti import constants
41 from ganeti import errors
45 # Common opcode attributes
47 #: output fields for a query operation
48 _POutputFields = ("output_fields", ht.NoDefault, ht.TListOf(ht.TNonEmptyString),
49 "Selected output fields")
51 #: the shutdown timeout
53 ("shutdown_timeout", constants.DEFAULT_SHUTDOWN_TIMEOUT, ht.TPositiveInt,
54 "How long to wait for instance to shut down")
56 #: the force parameter
57 _PForce = ("force", False, ht.TBool, "Whether to force the operation")
59 #: a required instance name (for single-instance LUs)
60 _PInstanceName = ("instance_name", ht.NoDefault, ht.TNonEmptyString,
63 #: Whether to ignore offline nodes
64 _PIgnoreOfflineNodes = ("ignore_offline_nodes", False, ht.TBool,
65 "Whether to ignore offline nodes")
67 #: a required node name (for single-node LUs)
68 _PNodeName = ("node_name", ht.NoDefault, ht.TNonEmptyString, "Node name")
70 #: a required node group name (for single-group LUs)
71 _PGroupName = ("group_name", ht.NoDefault, ht.TNonEmptyString, "Group name")
73 #: Migration type (live/non-live)
74 _PMigrationMode = ("mode", None,
75 ht.TOr(ht.TNone, ht.TElemOf(constants.HT_MIGRATION_MODES)),
78 #: Obsolete 'live' migration mode (boolean)
79 _PMigrationLive = ("live", None, ht.TMaybeBool,
80 "Legacy setting for live migration, do not use")
83 _PTagKind = ("kind", ht.NoDefault, ht.TElemOf(constants.VALID_TAG_TYPES), None)
85 #: List of tag strings
86 _PTags = ("tags", ht.NoDefault, ht.TListOf(ht.TNonEmptyString), None)
88 _PForceVariant = ("force_variant", False, ht.TBool,
89 "Whether to force an unknown OS variant")
91 _PWaitForSync = ("wait_for_sync", True, ht.TBool,
92 "Whether to wait for the disk to synchronize")
94 _PIgnoreConsistency = ("ignore_consistency", False, ht.TBool,
95 "Whether to ignore disk consistency")
97 _PStorageName = ("name", ht.NoDefault, ht.TMaybeString, "Storage name")
99 _PUseLocking = ("use_locking", False, ht.TBool,
100 "Whether to use synchronization")
102 _PNameCheck = ("name_check", True, ht.TBool, "Whether to check name")
104 _PNodeGroupAllocPolicy = \
105 ("alloc_policy", None,
106 ht.TOr(ht.TNone, ht.TElemOf(constants.VALID_ALLOC_POLICIES)),
107 "Instance allocation policy")
109 _PGroupNodeParams = ("ndparams", None, ht.TMaybeDict,
110 "Default node parameters for group")
112 _PQueryWhat = ("what", ht.NoDefault, ht.TElemOf(constants.QR_VIA_OP),
113 "Resource(s) to query for")
115 _PEarlyRelease = ("early_release", False, ht.TBool,
116 "Whether to release locks as soon as possible")
118 _PIpCheckDoc = "Whether to ensure instance's IP address is inactive"
120 #: Do not remember instance state changes
121 _PNoRemember = ("no_remember", False, ht.TBool,
122 "Do not remember the state change")
124 #: Target node for instance migration/failover
125 _PMigrationTargetNode = ("target_node", None, ht.TMaybeString,
126 "Target node for shared-storage instances")
128 _PStartupPaused = ("startup_paused", False, ht.TBool,
129 "Pause instance at startup")
131 _PVerbose = ("verbose", False, ht.TBool, "Verbose mode")
133 # Parameters for cluster verification
134 _PDebugSimulateErrors = ("debug_simulate_errors", False, ht.TBool,
135 "Whether to simulate errors (useful for debugging)")
136 _PErrorCodes = ("error_codes", False, ht.TBool, "Error codes")
137 _PSkipChecks = ("skip_checks", ht.EmptyList,
138 ht.TListOf(ht.TElemOf(constants.VERIFY_OPTIONAL_CHECKS)),
139 "Which checks to skip")
141 #: OP_ID conversion regular expression
142 _OPID_RE = re.compile("([a-z])([A-Z])")
144 #: Utility function for L{OpClusterSetParams}
145 _TestClusterOsList = ht.TOr(ht.TNone,
146 ht.TListOf(ht.TAnd(ht.TList, ht.TIsLength(2),
147 ht.TMap(ht.WithDesc("GetFirstItem")(compat.fst),
148 ht.TElemOf(constants.DDMS_VALUES)))))
151 # TODO: Generate check from constants.INIC_PARAMS_TYPES
152 #: Utility function for testing NIC definitions
153 _TestNicDef = ht.TDictOf(ht.TElemOf(constants.INIC_PARAMS),
154 ht.TOr(ht.TNone, ht.TNonEmptyString))
156 _TSetParamsResultItemItems = [
157 ht.Comment("name of changed parameter")(ht.TNonEmptyString),
161 _TSetParamsResult = \
162 ht.TListOf(ht.TAnd(ht.TIsLength(len(_TSetParamsResultItemItems)),
163 ht.TItems(_TSetParamsResultItemItems)))
172 #: Attribute name for dependencies
173 DEPEND_ATTR = "depends"
175 #: Attribute name for comment
176 COMMENT_ATTR = "comment"
180 """Convert an opcode class name to an OP_ID.
183 @param name: the class name, as OpXxxYyy
185 @return: the name in the OP_XXXX_YYYY format
188 if not name.startswith("Op"):
190 # Note: (?<=[a-z])(?=[A-Z]) would be ideal, since it wouldn't
191 # consume any input, and hence we would just have all the elements
192 # in the list, one by one; but it seems that split doesn't work on
193 # non-consuming input, hence we have to process the input string a
195 name = _OPID_RE.sub(r"\1,\2", name)
196 elems = name.split(",")
197 return "_".join(n.upper() for n in elems)
200 def RequireFileStorage():
201 """Checks that file storage is enabled.
203 While it doesn't really fit into this module, L{utils} was deemed too large
204 of a dependency to be imported for just one or two functions.
206 @raise errors.OpPrereqError: when file storage is disabled
209 if not constants.ENABLE_FILE_STORAGE:
210 raise errors.OpPrereqError("File storage disabled at configure time",
214 def RequireSharedFileStorage():
215 """Checks that shared file storage is enabled.
217 While it doesn't really fit into this module, L{utils} was deemed too large
218 of a dependency to be imported for just one or two functions.
220 @raise errors.OpPrereqError: when shared file storage is disabled
223 if not constants.ENABLE_SHARED_FILE_STORAGE:
224 raise errors.OpPrereqError("Shared file storage disabled at"
225 " configure time", errors.ECODE_INVAL)
228 @ht.WithDesc("CheckFileStorage")
229 def _CheckFileStorage(value):
230 """Ensures file storage is enabled if used.
233 if value == constants.DT_FILE:
235 elif value == constants.DT_SHARED_FILE:
236 RequireSharedFileStorage()
240 def _BuildDiskTemplateCheck(accept_none):
241 """Builds check for disk template.
243 @type accept_none: bool
244 @param accept_none: whether to accept None as a correct value
248 template_check = ht.TElemOf(constants.DISK_TEMPLATES)
251 template_check = ht.TOr(template_check, ht.TNone)
253 return ht.TAnd(template_check, _CheckFileStorage)
256 def _CheckStorageType(storage_type):
257 """Ensure a given storage type is valid.
260 if storage_type not in constants.VALID_STORAGE_TYPES:
261 raise errors.OpPrereqError("Unknown storage type: %s" % storage_type,
263 if storage_type == constants.ST_FILE:
268 #: Storage type parameter
269 _PStorageType = ("storage_type", ht.NoDefault, _CheckStorageType,
273 class _AutoOpParamSlots(type):
274 """Meta class for opcode definitions.
277 def __new__(mcs, name, bases, attrs):
278 """Called when a class should be created.
280 @param mcs: The meta class
281 @param name: Name of created class
282 @param bases: Base classes
284 @param attrs: Class attributes
287 assert "__slots__" not in attrs, \
288 "Class '%s' defines __slots__ when it should use OP_PARAMS" % name
289 assert "OP_ID" not in attrs, "Class '%s' defining OP_ID" % name
291 attrs["OP_ID"] = _NameToId(name)
293 # Always set OP_PARAMS to avoid duplicates in BaseOpCode.GetAllParams
294 params = attrs.setdefault("OP_PARAMS", [])
296 # Use parameter names as slots
297 slots = [pname for (pname, _, _, _) in params]
299 assert "OP_DSC_FIELD" not in attrs or attrs["OP_DSC_FIELD"] in slots, \
300 "Class '%s' uses unknown field in OP_DSC_FIELD" % name
302 attrs["__slots__"] = slots
304 return type.__new__(mcs, name, bases, attrs)
307 class BaseOpCode(object):
308 """A simple serializable object.
310 This object serves as a parent class for OpCode without any custom
314 # pylint: disable=E1101
315 # as OP_ID is dynamically defined
316 __metaclass__ = _AutoOpParamSlots
318 def __init__(self, **kwargs):
319 """Constructor for BaseOpCode.
321 The constructor takes only keyword arguments and will set
322 attributes on this object based on the passed arguments. As such,
323 it means that you should not pass arguments which are not in the
324 __slots__ attribute for this class.
327 slots = self._all_slots()
330 raise TypeError("Object %s doesn't support the parameter '%s'" %
331 (self.__class__.__name__, key))
332 setattr(self, key, kwargs[key])
334 def __getstate__(self):
335 """Generic serializer.
337 This method just returns the contents of the instance as a
341 @return: the instance attributes and their values
345 for name in self._all_slots():
346 if hasattr(self, name):
347 state[name] = getattr(self, name)
350 def __setstate__(self, state):
351 """Generic unserializer.
353 This method just restores from the serialized state the attributes
354 of the current instance.
356 @param state: the serialized opcode data
360 if not isinstance(state, dict):
361 raise ValueError("Invalid data to __setstate__: expected dict, got %s" %
364 for name in self._all_slots():
365 if name not in state and hasattr(self, name):
369 setattr(self, name, state[name])
373 """Compute the list of all declared slots for a class.
377 for parent in cls.__mro__:
378 slots.extend(getattr(parent, "__slots__", []))
382 def GetAllParams(cls):
383 """Compute list of all parameters for an opcode.
387 for parent in cls.__mro__:
388 slots.extend(getattr(parent, "OP_PARAMS", []))
391 def Validate(self, set_defaults):
392 """Validate opcode parameters, optionally setting default values.
394 @type set_defaults: bool
395 @param set_defaults: Whether to set default values
396 @raise errors.OpPrereqError: When a parameter value doesn't match
400 for (attr_name, default, test, _) in self.GetAllParams():
401 assert test == ht.NoType or callable(test)
403 if not hasattr(self, attr_name):
404 if default == ht.NoDefault:
405 raise errors.OpPrereqError("Required parameter '%s.%s' missing" %
406 (self.OP_ID, attr_name),
409 if callable(default):
413 setattr(self, attr_name, dval)
415 if test == ht.NoType:
419 if set_defaults or hasattr(self, attr_name):
420 attr_val = getattr(self, attr_name)
421 if not test(attr_val):
422 logging.error("OpCode %s, parameter %s, has invalid type %s/value %s",
423 self.OP_ID, attr_name, type(attr_val), attr_val)
424 raise errors.OpPrereqError("Parameter '%s.%s' fails validation" %
425 (self.OP_ID, attr_name),
429 def _BuildJobDepCheck(relative):
430 """Builds check for job dependencies (L{DEPEND_ATTR}).
433 @param relative: Whether to accept relative job IDs (negative)
438 job_id = ht.TOr(ht.TJobId, ht.TRelativeJobId)
443 ht.TAnd(ht.TIsLength(2),
445 ht.TListOf(ht.TElemOf(constants.JOBS_FINALIZED))]))
447 return ht.TOr(ht.TNone, ht.TListOf(job_dep))
450 TNoRelativeJobDependencies = _BuildJobDepCheck(False)
452 #: List of submission status and job ID as returned by C{SubmitManyJobs}
454 ht.TAnd(ht.TIsLength(2),
455 ht.TItems([ht.Comment("success")(ht.TBool),
456 ht.Comment("Job ID if successful, error message"
457 " otherwise")(ht.TOr(ht.TString,
459 TJobIdList = ht.TListOf(_TJobIdListItem)
461 #: Result containing only list of submitted jobs
462 TJobIdListOnly = ht.TStrictDict(True, True, {
463 constants.JOB_IDS_KEY: ht.Comment("List of submitted jobs")(TJobIdList),
467 class OpCode(BaseOpCode):
470 This is the root of the actual OpCode hierarchy. All clases derived
471 from this class should override OP_ID.
473 @cvar OP_ID: The ID of this opcode. This should be unique amongst all
474 children of this class.
475 @cvar OP_DSC_FIELD: The name of a field whose value will be included in the
476 string returned by Summary(); see the docstring of that
478 @cvar OP_PARAMS: List of opcode attributes, the default values they should
479 get if not already defined, and types they must match.
480 @cvar OP_RESULT: Callable to verify opcode result
481 @cvar WITH_LU: Boolean that specifies whether this should be included in
482 mcpu's dispatch table
483 @ivar dry_run: Whether the LU should be run in dry-run mode, i.e. just
485 @ivar priority: Opcode priority for queue
488 # pylint: disable=E1101
489 # as OP_ID is dynamically defined
492 ("dry_run", None, ht.TMaybeBool, "Run checks only, don't execute"),
493 ("debug_level", None, ht.TOr(ht.TNone, ht.TPositiveInt), "Debug level"),
494 ("priority", constants.OP_PRIO_DEFAULT,
495 ht.TElemOf(constants.OP_PRIO_SUBMIT_VALID), "Opcode priority"),
496 (DEPEND_ATTR, None, _BuildJobDepCheck(True),
497 "Job dependencies; if used through ``SubmitManyJobs`` relative (negative)"
498 " job IDs can be used"),
499 (COMMENT_ATTR, None, ht.TMaybeString,
500 "Comment describing the purpose of the opcode"),
504 def __getstate__(self):
505 """Specialized getstate for opcodes.
507 This method adds to the state dictionary the OP_ID of the class,
508 so that on unload we can identify the correct class for
509 instantiating the opcode.
512 @return: the state as a dictionary
515 data = BaseOpCode.__getstate__(self)
516 data["OP_ID"] = self.OP_ID
520 def LoadOpCode(cls, data):
521 """Generic load opcode method.
523 The method identifies the correct opcode class from the dict-form
524 by looking for a OP_ID key, if this is not found, or its value is
525 not available in this module as a child of this class, we fail.
528 @param data: the serialized opcode
531 if not isinstance(data, dict):
532 raise ValueError("Invalid data to LoadOpCode (%s)" % type(data))
533 if "OP_ID" not in data:
534 raise ValueError("Invalid data to LoadOpcode, missing OP_ID")
535 op_id = data["OP_ID"]
537 if op_id in OP_MAPPING:
538 op_class = OP_MAPPING[op_id]
540 raise ValueError("Invalid data to LoadOpCode: OP_ID %s unsupported" %
543 new_data = data.copy()
544 del new_data["OP_ID"]
545 op.__setstate__(new_data)
549 """Generates a summary description of this opcode.
551 The summary is the value of the OP_ID attribute (without the "OP_"
552 prefix), plus the value of the OP_DSC_FIELD attribute, if one was
553 defined; this field should allow to easily identify the operation
554 (for an instance creation job, e.g., it would be the instance
558 assert self.OP_ID is not None and len(self.OP_ID) > 3
559 # all OP_ID start with OP_, we remove that
561 field_name = getattr(self, "OP_DSC_FIELD", None)
563 field_value = getattr(self, field_name, None)
564 if isinstance(field_value, (list, tuple)):
565 field_value = ",".join(str(i) for i in field_value)
566 txt = "%s(%s)" % (txt, field_value)
569 def TinySummary(self):
570 """Generates a compact summary description of the opcode.
573 assert self.OP_ID.startswith("OP_")
575 text = self.OP_ID[3:]
577 for (prefix, supplement) in _SUMMARY_PREFIX.items():
578 if text.startswith(prefix):
579 return supplement + text[len(prefix):]
586 class OpClusterPostInit(OpCode):
587 """Post cluster initialization.
589 This opcode does not touch the cluster at all. Its purpose is to run hooks
590 after the cluster has been initialized.
595 class OpClusterDestroy(OpCode):
596 """Destroy the cluster.
598 This opcode has no other parameters. All the state is irreversibly
599 lost after the execution of this opcode.
604 class OpClusterQuery(OpCode):
605 """Query cluster information."""
608 class OpClusterVerify(OpCode):
609 """Submits all jobs necessary to verify the cluster.
613 _PDebugSimulateErrors,
617 ("group_name", None, ht.TMaybeString, "Group to verify")
619 OP_RESULT = TJobIdListOnly
622 class OpClusterVerifyConfig(OpCode):
623 """Verify the cluster config.
627 _PDebugSimulateErrors,
634 class OpClusterVerifyGroup(OpCode):
635 """Run verify on a node group from the cluster.
637 @type skip_checks: C{list}
638 @ivar skip_checks: steps to be skipped from the verify process; this
639 needs to be a subset of
640 L{constants.VERIFY_OPTIONAL_CHECKS}; currently
641 only L{constants.VERIFY_NPLUSONE_MEM} can be passed
644 OP_DSC_FIELD = "group_name"
647 _PDebugSimulateErrors,
655 class OpClusterVerifyDisks(OpCode):
656 """Verify the cluster disks.
659 OP_RESULT = TJobIdListOnly
662 class OpGroupVerifyDisks(OpCode):
663 """Verifies the status of all disks in a node group.
665 Result: a tuple of three elements:
666 - dict of node names with issues (values: error msg)
667 - list of instances with degraded disks (that should be activated)
668 - dict of instances with missing logical volumes (values: (node, vol)
669 pairs with details about the missing volumes)
671 In normal operation, all lists should be empty. A non-empty instance
672 list (3rd element of the result) is still ok (errors were fixed) but
673 non-empty node list means some node is down, and probably there are
674 unfixable drbd errors.
676 Note that only instances that are drbd-based are taken into
677 consideration. This might need to be revisited in the future.
680 OP_DSC_FIELD = "group_name"
685 ht.TAnd(ht.TIsLength(3),
686 ht.TItems([ht.TDictOf(ht.TString, ht.TString),
687 ht.TListOf(ht.TString),
688 ht.TDictOf(ht.TString, ht.TListOf(ht.TString))]))
691 class OpClusterRepairDiskSizes(OpCode):
692 """Verify the disk sizes of the instances and fixes configuration
695 Parameters: optional instances list, in case we want to restrict the
696 checks to only a subset of the instances.
698 Result: a list of tuples, (instance, disk, new-size) for changed
701 In normal operation, the list should be empty.
703 @type instances: list
704 @ivar instances: the list of instances to check, or empty for all instances
708 ("instances", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), None),
712 class OpClusterConfigQuery(OpCode):
713 """Query cluster configuration values."""
719 class OpClusterRename(OpCode):
720 """Rename the cluster.
723 @ivar name: The new name of the cluster. The name and/or the master IP
724 address will be changed to match the new name and its IP
728 OP_DSC_FIELD = "name"
730 ("name", ht.NoDefault, ht.TNonEmptyString, None),
734 class OpClusterSetParams(OpCode):
735 """Change the parameters of the cluster.
737 @type vg_name: C{str} or C{None}
738 @ivar vg_name: The new volume group name or None to disable LVM usage.
742 ("vg_name", None, ht.TMaybeString, "Volume group name"),
743 ("enabled_hypervisors", None,
744 ht.TOr(ht.TAnd(ht.TListOf(ht.TElemOf(constants.HYPER_TYPES)), ht.TTrue),
746 "List of enabled hypervisors"),
747 ("hvparams", None, ht.TOr(ht.TDictOf(ht.TNonEmptyString, ht.TDict),
749 "Cluster-wide hypervisor parameter defaults, hypervisor-dependent"),
750 ("beparams", None, ht.TOr(ht.TDict, ht.TNone),
751 "Cluster-wide backend parameter defaults"),
752 ("os_hvp", None, ht.TOr(ht.TDictOf(ht.TNonEmptyString, ht.TDict),
754 "Cluster-wide per-OS hypervisor parameter defaults"),
755 ("osparams", None, ht.TOr(ht.TDictOf(ht.TNonEmptyString, ht.TDict),
757 "Cluster-wide OS parameter defaults"),
758 ("candidate_pool_size", None, ht.TOr(ht.TStrictPositiveInt, ht.TNone),
759 "Master candidate pool size"),
760 ("uid_pool", None, ht.NoType,
761 "Set UID pool, must be list of lists describing UID ranges (two items,"
762 " start and end inclusive)"),
763 ("add_uids", None, ht.NoType,
764 "Extend UID pool, must be list of lists describing UID ranges (two"
765 " items, start and end inclusive) to be added"),
766 ("remove_uids", None, ht.NoType,
767 "Shrink UID pool, must be list of lists describing UID ranges (two"
768 " items, start and end inclusive) to be removed"),
769 ("maintain_node_health", None, ht.TMaybeBool,
770 "Whether to automatically maintain node health"),
771 ("prealloc_wipe_disks", None, ht.TMaybeBool,
772 "Whether to wipe disks before allocating them to instances"),
773 ("nicparams", None, ht.TMaybeDict, "Cluster-wide NIC parameter defaults"),
774 ("ndparams", None, ht.TMaybeDict, "Cluster-wide node parameter defaults"),
775 ("drbd_helper", None, ht.TOr(ht.TString, ht.TNone), "DRBD helper program"),
776 ("default_iallocator", None, ht.TOr(ht.TString, ht.TNone),
777 "Default iallocator for cluster"),
778 ("master_netdev", None, ht.TOr(ht.TString, ht.TNone),
779 "Master network device"),
780 ("reserved_lvs", None, ht.TOr(ht.TListOf(ht.TNonEmptyString), ht.TNone),
781 "List of reserved LVs"),
782 ("hidden_os", None, _TestClusterOsList,
783 "Modify list of hidden operating systems. Each modification must have"
784 " two items, the operation and the OS name. The operation can be"
785 " ``%s`` or ``%s``." % (constants.DDM_ADD, constants.DDM_REMOVE)),
786 ("blacklisted_os", None, _TestClusterOsList,
787 "Modify list of blacklisted operating systems. Each modification must have"
788 " two items, the operation and the OS name. The operation can be"
789 " ``%s`` or ``%s``." % (constants.DDM_ADD, constants.DDM_REMOVE)),
793 class OpClusterRedistConf(OpCode):
794 """Force a full push of the cluster configuration.
799 class OpQuery(OpCode):
800 """Query for resources/items.
802 @ivar what: Resources to query for, must be one of L{constants.QR_VIA_OP}
803 @ivar fields: List of fields to retrieve
804 @ivar filter: Query filter
807 OP_DSC_FIELD = "what"
811 ("fields", ht.NoDefault, ht.TListOf(ht.TNonEmptyString),
813 ("filter", None, ht.TOr(ht.TNone, ht.TListOf),
818 class OpQueryFields(OpCode):
819 """Query for available resource/item fields.
821 @ivar what: Resources to query for, must be one of L{constants.QR_VIA_OP}
822 @ivar fields: List of fields to retrieve
825 OP_DSC_FIELD = "what"
828 ("fields", None, ht.TOr(ht.TNone, ht.TListOf(ht.TNonEmptyString)),
829 "Requested fields; if not given, all are returned"),
833 class OpOobCommand(OpCode):
834 """Interact with OOB."""
836 ("node_names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
837 "List of nodes to run the OOB command against"),
838 ("command", None, ht.TElemOf(constants.OOB_COMMANDS),
839 "OOB command to be run"),
840 ("timeout", constants.OOB_TIMEOUT, ht.TInt,
841 "Timeout before the OOB helper will be terminated"),
842 ("ignore_status", False, ht.TBool,
843 "Ignores the node offline status for power off"),
844 ("power_delay", constants.OOB_POWER_DELAY, ht.TPositiveFloat,
845 "Time in seconds to wait between powering on nodes"),
851 class OpNodeRemove(OpCode):
854 @type node_name: C{str}
855 @ivar node_name: The name of the node to remove. If the node still has
856 instances on it, the operation will fail.
859 OP_DSC_FIELD = "node_name"
865 class OpNodeAdd(OpCode):
866 """Add a node to the cluster.
868 @type node_name: C{str}
869 @ivar node_name: The name of the node to add. This can be a short name,
870 but it will be expanded to the FQDN.
871 @type primary_ip: IP address
872 @ivar primary_ip: The primary IP of the node. This will be ignored when the
873 opcode is submitted, but will be filled during the node
874 add (so it will be visible in the job query).
875 @type secondary_ip: IP address
876 @ivar secondary_ip: The secondary IP of the node. This needs to be passed
877 if the cluster has been initialized in 'dual-network'
878 mode, otherwise it must not be given.
880 @ivar readd: Whether to re-add an existing node to the cluster. If
881 this is not passed, then the operation will abort if the node
882 name is already in the cluster; use this parameter to 'repair'
883 a node that had its configuration broken, or was reinstalled
884 without removal from the cluster.
886 @ivar group: The node group to which this node will belong.
887 @type vm_capable: C{bool}
888 @ivar vm_capable: The vm_capable node attribute
889 @type master_capable: C{bool}
890 @ivar master_capable: The master_capable node attribute
893 OP_DSC_FIELD = "node_name"
896 ("primary_ip", None, ht.NoType, "Primary IP address"),
897 ("secondary_ip", None, ht.TMaybeString, "Secondary IP address"),
898 ("readd", False, ht.TBool, "Whether node is re-added to cluster"),
899 ("group", None, ht.TMaybeString, "Initial node group"),
900 ("master_capable", None, ht.TMaybeBool,
901 "Whether node can become master or master candidate"),
902 ("vm_capable", None, ht.TMaybeBool,
903 "Whether node can host instances"),
904 ("ndparams", None, ht.TMaybeDict, "Node parameters"),
908 class OpNodeQuery(OpCode):
909 """Compute the list of nodes."""
913 ("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
914 "Empty list to query all nodes, node names otherwise"),
918 class OpNodeQueryvols(OpCode):
919 """Get list of volumes on node."""
922 ("nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
923 "Empty list to query all nodes, node names otherwise"),
927 class OpNodeQueryStorage(OpCode):
928 """Get information on storage for node(s)."""
932 ("nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), "List of nodes"),
933 ("name", None, ht.TMaybeString, "Storage name"),
937 class OpNodeModifyStorage(OpCode):
938 """Modifies the properies of a storage unit"""
943 ("changes", ht.NoDefault, ht.TDict, "Requested changes"),
947 class OpRepairNodeStorage(OpCode):
948 """Repairs the volume group on a node."""
949 OP_DSC_FIELD = "node_name"
958 class OpNodeSetParams(OpCode):
959 """Change the parameters of a node."""
960 OP_DSC_FIELD = "node_name"
964 ("master_candidate", None, ht.TMaybeBool,
965 "Whether the node should become a master candidate"),
966 ("offline", None, ht.TMaybeBool,
967 "Whether the node should be marked as offline"),
968 ("drained", None, ht.TMaybeBool,
969 "Whether the node should be marked as drained"),
970 ("auto_promote", False, ht.TBool,
971 "Whether node(s) should be promoted to master candidate if necessary"),
972 ("master_capable", None, ht.TMaybeBool,
973 "Denote whether node can become master or master candidate"),
974 ("vm_capable", None, ht.TMaybeBool,
975 "Denote whether node can host instances"),
976 ("secondary_ip", None, ht.TMaybeString,
977 "Change node's secondary IP address"),
978 ("ndparams", None, ht.TMaybeDict, "Set node parameters"),
979 ("powered", None, ht.TMaybeBool,
980 "Whether the node should be marked as powered"),
982 OP_RESULT = _TSetParamsResult
985 class OpNodePowercycle(OpCode):
986 """Tries to powercycle a node."""
987 OP_DSC_FIELD = "node_name"
994 class OpNodeMigrate(OpCode):
995 """Migrate all instances from a node."""
996 OP_DSC_FIELD = "node_name"
1001 _PMigrationTargetNode,
1002 ("iallocator", None, ht.TMaybeString,
1003 "Iallocator for deciding the target node for shared-storage instances"),
1007 class OpNodeEvacuate(OpCode):
1008 """Evacuate instances off a number of nodes."""
1009 OP_DSC_FIELD = "node_name"
1013 ("remote_node", None, ht.TMaybeString, "New secondary node"),
1014 ("iallocator", None, ht.TMaybeString, "Iallocator for computing solution"),
1015 ("mode", ht.NoDefault, ht.TElemOf(constants.IALLOCATOR_NEVAC_MODES),
1016 "Node evacuation mode"),
1018 OP_RESULT = TJobIdListOnly
1023 class OpInstanceCreate(OpCode):
1024 """Create an instance.
1026 @ivar instance_name: Instance name
1027 @ivar mode: Instance creation mode (one of L{constants.INSTANCE_CREATE_MODES})
1028 @ivar source_handshake: Signed handshake from source (remote import only)
1029 @ivar source_x509_ca: Source X509 CA in PEM format (remote import only)
1030 @ivar source_instance_name: Previous name of instance (remote import only)
1031 @ivar source_shutdown_timeout: Shutdown timeout used for source instance
1032 (remote import only)
1035 OP_DSC_FIELD = "instance_name"
1041 ("beparams", ht.EmptyDict, ht.TDict, "Backend parameters for instance"),
1042 ("disks", ht.NoDefault,
1043 # TODO: Generate check from constants.IDISK_PARAMS_TYPES
1044 ht.TListOf(ht.TDictOf(ht.TElemOf(constants.IDISK_PARAMS),
1045 ht.TOr(ht.TNonEmptyString, ht.TInt))),
1046 "Disk descriptions, for example ``[{\"%s\": 100}, {\"%s\": 5}]``;"
1047 " each disk definition must contain a ``%s`` value and"
1048 " can contain an optional ``%s`` value denoting the disk access mode"
1050 (constants.IDISK_SIZE, constants.IDISK_SIZE, constants.IDISK_SIZE,
1051 constants.IDISK_MODE,
1052 " or ".join("``%s``" % i for i in sorted(constants.DISK_ACCESS_SET)))),
1053 ("disk_template", ht.NoDefault, _BuildDiskTemplateCheck(True),
1055 ("file_driver", None, ht.TOr(ht.TNone, ht.TElemOf(constants.FILE_DRIVER)),
1056 "Driver for file-backed disks"),
1057 ("file_storage_dir", None, ht.TMaybeString,
1058 "Directory for storing file-backed disks"),
1059 ("hvparams", ht.EmptyDict, ht.TDict,
1060 "Hypervisor parameters for instance, hypervisor-dependent"),
1061 ("hypervisor", None, ht.TMaybeString, "Hypervisor"),
1062 ("iallocator", None, ht.TMaybeString,
1063 "Iallocator for deciding which node(s) to use"),
1064 ("identify_defaults", False, ht.TBool,
1065 "Reset instance parameters to default if equal"),
1066 ("ip_check", True, ht.TBool, _PIpCheckDoc),
1067 ("mode", ht.NoDefault, ht.TElemOf(constants.INSTANCE_CREATE_MODES),
1068 "Instance creation mode"),
1069 ("nics", ht.NoDefault, ht.TListOf(_TestNicDef),
1070 "List of NIC (network interface) definitions, for example"
1071 " ``[{}, {}, {\"%s\": \"198.51.100.4\"}]``; each NIC definition can"
1072 " contain the optional values %s" %
1074 ", ".join("``%s``" % i for i in sorted(constants.INIC_PARAMS)))),
1075 ("no_install", None, ht.TMaybeBool,
1076 "Do not install the OS (will disable automatic start)"),
1077 ("osparams", ht.EmptyDict, ht.TDict, "OS parameters for instance"),
1078 ("os_type", None, ht.TMaybeString, "Operating system"),
1079 ("pnode", None, ht.TMaybeString, "Primary node"),
1080 ("snode", None, ht.TMaybeString, "Secondary node"),
1081 ("source_handshake", None, ht.TOr(ht.TList, ht.TNone),
1082 "Signed handshake from source (remote import only)"),
1083 ("source_instance_name", None, ht.TMaybeString,
1084 "Source instance name (remote import only)"),
1085 ("source_shutdown_timeout", constants.DEFAULT_SHUTDOWN_TIMEOUT,
1087 "How long source instance was given to shut down (remote import only)"),
1088 ("source_x509_ca", None, ht.TMaybeString,
1089 "Source X509 CA in PEM format (remote import only)"),
1090 ("src_node", None, ht.TMaybeString, "Source node for import"),
1091 ("src_path", None, ht.TMaybeString, "Source directory for import"),
1092 ("start", True, ht.TBool, "Whether to start instance after creation"),
1093 ("tags", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), "Instance tags"),
1095 OP_RESULT = ht.Comment("instance nodes")(ht.TListOf(ht.TNonEmptyString))
1098 class OpInstanceReinstall(OpCode):
1099 """Reinstall an instance's OS."""
1100 OP_DSC_FIELD = "instance_name"
1104 ("os_type", None, ht.TMaybeString, "Instance operating system"),
1105 ("osparams", None, ht.TMaybeDict, "Temporary OS parameters"),
1109 class OpInstanceRemove(OpCode):
1110 """Remove an instance."""
1111 OP_DSC_FIELD = "instance_name"
1115 ("ignore_failures", False, ht.TBool,
1116 "Whether to ignore failures during removal"),
1120 class OpInstanceRename(OpCode):
1121 """Rename an instance."""
1125 ("new_name", ht.NoDefault, ht.TNonEmptyString, "New instance name"),
1126 ("ip_check", False, ht.TBool, _PIpCheckDoc),
1128 OP_RESULT = ht.Comment("New instance name")(ht.TNonEmptyString)
1131 class OpInstanceStartup(OpCode):
1132 """Startup an instance."""
1133 OP_DSC_FIELD = "instance_name"
1137 _PIgnoreOfflineNodes,
1138 ("hvparams", ht.EmptyDict, ht.TDict,
1139 "Temporary hypervisor parameters, hypervisor-dependent"),
1140 ("beparams", ht.EmptyDict, ht.TDict, "Temporary backend parameters"),
1146 class OpInstanceShutdown(OpCode):
1147 """Shutdown an instance."""
1148 OP_DSC_FIELD = "instance_name"
1151 _PIgnoreOfflineNodes,
1152 ("timeout", constants.DEFAULT_SHUTDOWN_TIMEOUT, ht.TPositiveInt,
1153 "How long to wait for instance to shut down"),
1158 class OpInstanceReboot(OpCode):
1159 """Reboot an instance."""
1160 OP_DSC_FIELD = "instance_name"
1164 ("ignore_secondaries", False, ht.TBool,
1165 "Whether to start the instance even if secondary disks are failing"),
1166 ("reboot_type", ht.NoDefault, ht.TElemOf(constants.REBOOT_TYPES),
1167 "How to reboot instance"),
1171 class OpInstanceReplaceDisks(OpCode):
1172 """Replace the disks of an instance."""
1173 OP_DSC_FIELD = "instance_name"
1177 ("mode", ht.NoDefault, ht.TElemOf(constants.REPLACE_MODES),
1178 "Replacement mode"),
1179 ("disks", ht.EmptyList, ht.TListOf(ht.TPositiveInt),
1181 ("remote_node", None, ht.TMaybeString, "New secondary node"),
1182 ("iallocator", None, ht.TMaybeString,
1183 "Iallocator for deciding new secondary node"),
1187 class OpInstanceFailover(OpCode):
1188 """Failover an instance."""
1189 OP_DSC_FIELD = "instance_name"
1193 _PIgnoreConsistency,
1194 _PMigrationTargetNode,
1195 ("iallocator", None, ht.TMaybeString,
1196 "Iallocator for deciding the target node for shared-storage instances"),
1200 class OpInstanceMigrate(OpCode):
1201 """Migrate an instance.
1203 This migrates (without shutting down an instance) to its secondary
1206 @ivar instance_name: the name of the instance
1207 @ivar mode: the migration mode (live, non-live or None for auto)
1210 OP_DSC_FIELD = "instance_name"
1215 _PMigrationTargetNode,
1216 ("cleanup", False, ht.TBool,
1217 "Whether a previously failed migration should be cleaned up"),
1218 ("iallocator", None, ht.TMaybeString,
1219 "Iallocator for deciding the target node for shared-storage instances"),
1220 ("allow_failover", False, ht.TBool,
1221 "Whether we can fallback to failover if migration is not possible"),
1225 class OpInstanceMove(OpCode):
1226 """Move an instance.
1228 This move (with shutting down an instance and data copying) to an
1231 @ivar instance_name: the name of the instance
1232 @ivar target_node: the destination node
1235 OP_DSC_FIELD = "instance_name"
1239 ("target_node", ht.NoDefault, ht.TNonEmptyString, "Target node"),
1240 _PIgnoreConsistency,
1244 class OpInstanceConsole(OpCode):
1245 """Connect to an instance's console."""
1246 OP_DSC_FIELD = "instance_name"
1252 class OpInstanceActivateDisks(OpCode):
1253 """Activate an instance's disks."""
1254 OP_DSC_FIELD = "instance_name"
1257 ("ignore_size", False, ht.TBool, "Whether to ignore recorded size"),
1261 class OpInstanceDeactivateDisks(OpCode):
1262 """Deactivate an instance's disks."""
1263 OP_DSC_FIELD = "instance_name"
1270 class OpInstanceRecreateDisks(OpCode):
1271 """Deactivate an instance's disks."""
1272 OP_DSC_FIELD = "instance_name"
1275 ("disks", ht.EmptyList, ht.TListOf(ht.TPositiveInt),
1276 "List of disk indexes"),
1277 ("nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
1278 "New instance nodes, if relocation is desired"),
1282 class OpInstanceQuery(OpCode):
1283 """Compute the list of instances."""
1287 ("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
1288 "Empty list to query all instances, instance names otherwise"),
1292 class OpInstanceQueryData(OpCode):
1293 """Compute the run-time status of instances."""
1296 ("instances", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
1298 ("static", False, ht.TBool,
1299 "Whether to only return configuration data without querying"
1304 class OpInstanceSetParams(OpCode):
1305 """Change the parameters of an instance."""
1306 OP_DSC_FIELD = "instance_name"
1311 # TODO: Use _TestNicDef
1312 ("nics", ht.EmptyList, ht.TList,
1313 "List of NIC changes. Each item is of the form ``(op, settings)``."
1314 " ``op`` can be ``%s`` to add a new NIC with the specified settings,"
1315 " ``%s`` to remove the last NIC or a number to modify the settings"
1316 " of the NIC with that index." %
1317 (constants.DDM_ADD, constants.DDM_REMOVE)),
1318 ("disks", ht.EmptyList, ht.TList, "List of disk changes. See ``nics``."),
1319 ("beparams", ht.EmptyDict, ht.TDict, "Per-instance backend parameters"),
1320 ("hvparams", ht.EmptyDict, ht.TDict,
1321 "Per-instance hypervisor parameters, hypervisor-dependent"),
1322 ("disk_template", None, ht.TOr(ht.TNone, _BuildDiskTemplateCheck(False)),
1323 "Disk template for instance"),
1324 ("remote_node", None, ht.TMaybeString,
1325 "Secondary node (used when changing disk template)"),
1326 ("os_name", None, ht.TMaybeString,
1327 "Change instance's OS name. Does not reinstall the instance."),
1328 ("osparams", None, ht.TMaybeDict, "Per-instance OS parameters"),
1329 ("wait_for_sync", True, ht.TBool,
1330 "Whether to wait for the disk to synchronize, when changing template"),
1332 OP_RESULT = _TSetParamsResult
1335 class OpInstanceGrowDisk(OpCode):
1336 """Grow a disk of an instance."""
1337 OP_DSC_FIELD = "instance_name"
1341 ("disk", ht.NoDefault, ht.TInt, "Disk index"),
1342 ("amount", ht.NoDefault, ht.TInt,
1343 "Amount of disk space to add (megabytes)"),
1347 class OpInstanceChangeGroup(OpCode):
1348 """Moves an instance to another node group."""
1349 OP_DSC_FIELD = "instance_name"
1353 ("iallocator", None, ht.TMaybeString, "Iallocator for computing solution"),
1354 ("target_groups", None, ht.TOr(ht.TNone, ht.TListOf(ht.TNonEmptyString)),
1355 "Destination group names or UUIDs (defaults to \"all but current group\""),
1357 OP_RESULT = TJobIdListOnly
1360 # Node group opcodes
1362 class OpGroupAdd(OpCode):
1363 """Add a node group to the cluster."""
1364 OP_DSC_FIELD = "group_name"
1367 _PNodeGroupAllocPolicy,
1372 class OpGroupAssignNodes(OpCode):
1373 """Assign nodes to a node group."""
1374 OP_DSC_FIELD = "group_name"
1378 ("nodes", ht.NoDefault, ht.TListOf(ht.TNonEmptyString),
1379 "List of nodes to assign"),
1383 class OpGroupQuery(OpCode):
1384 """Compute the list of node groups."""
1387 ("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
1388 "Empty list to query all groups, group names otherwise"),
1392 class OpGroupSetParams(OpCode):
1393 """Change the parameters of a node group."""
1394 OP_DSC_FIELD = "group_name"
1397 _PNodeGroupAllocPolicy,
1400 OP_RESULT = _TSetParamsResult
1403 class OpGroupRemove(OpCode):
1404 """Remove a node group from the cluster."""
1405 OP_DSC_FIELD = "group_name"
1411 class OpGroupRename(OpCode):
1412 """Rename a node group in the cluster."""
1415 ("new_name", ht.NoDefault, ht.TNonEmptyString, "New group name"),
1417 OP_RESULT = ht.Comment("New group name")(ht.TNonEmptyString)
1420 class OpGroupEvacuate(OpCode):
1421 """Evacuate a node group in the cluster."""
1422 OP_DSC_FIELD = "group_name"
1426 ("iallocator", None, ht.TMaybeString, "Iallocator for computing solution"),
1427 ("target_groups", None, ht.TOr(ht.TNone, ht.TListOf(ht.TNonEmptyString)),
1428 "Destination group names or UUIDs"),
1430 OP_RESULT = TJobIdListOnly
1434 class OpOsDiagnose(OpCode):
1435 """Compute the list of guest operating systems."""
1438 ("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
1439 "Which operating systems to diagnose"),
1444 class OpBackupQuery(OpCode):
1445 """Compute the list of exported images."""
1448 ("nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
1449 "Empty list to query all nodes, node names otherwise"),
1453 class OpBackupPrepare(OpCode):
1454 """Prepares an instance export.
1456 @ivar instance_name: Instance name
1457 @ivar mode: Export mode (one of L{constants.EXPORT_MODES})
1460 OP_DSC_FIELD = "instance_name"
1463 ("mode", ht.NoDefault, ht.TElemOf(constants.EXPORT_MODES),
1468 class OpBackupExport(OpCode):
1469 """Export an instance.
1471 For local exports, the export destination is the node name. For remote
1472 exports, the export destination is a list of tuples, each consisting of
1473 hostname/IP address, port, HMAC and HMAC salt. The HMAC is calculated using
1474 the cluster domain secret over the value "${index}:${hostname}:${port}". The
1475 destination X509 CA must be a signed certificate.
1477 @ivar mode: Export mode (one of L{constants.EXPORT_MODES})
1478 @ivar target_node: Export destination
1479 @ivar x509_key_name: X509 key to use (remote export only)
1480 @ivar destination_x509_ca: Destination X509 CA in PEM format (remote export
1484 OP_DSC_FIELD = "instance_name"
1488 # TODO: Rename target_node as it changes meaning for different export modes
1489 # (e.g. "destination")
1490 ("target_node", ht.NoDefault, ht.TOr(ht.TNonEmptyString, ht.TList),
1491 "Destination information, depends on export mode"),
1492 ("shutdown", True, ht.TBool, "Whether to shutdown instance before export"),
1493 ("remove_instance", False, ht.TBool,
1494 "Whether to remove instance after export"),
1495 ("ignore_remove_failures", False, ht.TBool,
1496 "Whether to ignore failures while removing instances"),
1497 ("mode", constants.EXPORT_MODE_LOCAL, ht.TElemOf(constants.EXPORT_MODES),
1499 ("x509_key_name", None, ht.TOr(ht.TList, ht.TNone),
1500 "Name of X509 key (remote export only)"),
1501 ("destination_x509_ca", None, ht.TMaybeString,
1502 "Destination X509 CA (remote export only)"),
1506 class OpBackupRemove(OpCode):
1507 """Remove an instance's export."""
1508 OP_DSC_FIELD = "instance_name"
1515 class OpTagsGet(OpCode):
1516 """Returns the tags of the given object."""
1517 OP_DSC_FIELD = "name"
1520 # Name is only meaningful for nodes and instances
1521 ("name", ht.NoDefault, ht.TMaybeString, None),
1525 class OpTagsSearch(OpCode):
1526 """Searches the tags in the cluster for a given pattern."""
1527 OP_DSC_FIELD = "pattern"
1529 ("pattern", ht.NoDefault, ht.TNonEmptyString, None),
1533 class OpTagsSet(OpCode):
1534 """Add a list of tags on a given object."""
1538 # Name is only meaningful for nodes and instances
1539 ("name", ht.NoDefault, ht.TMaybeString, None),
1543 class OpTagsDel(OpCode):
1544 """Remove a list of tags from a given object."""
1548 # Name is only meaningful for nodes and instances
1549 ("name", ht.NoDefault, ht.TMaybeString, None),
1554 class OpTestDelay(OpCode):
1555 """Sleeps for a configured amount of time.
1557 This is used just for debugging and testing.
1560 - duration: the time to sleep
1561 - on_master: if true, sleep on the master
1562 - on_nodes: list of nodes in which to sleep
1564 If the on_master parameter is true, it will execute a sleep on the
1565 master (before any node sleep).
1567 If the on_nodes list is not empty, it will sleep on those nodes
1568 (after the sleep on the master, if that is enabled).
1570 As an additional feature, the case of duration < 0 will be reported
1571 as an execution error, so this opcode can be used as a failure
1572 generator. The case of duration == 0 will not be treated specially.
1575 OP_DSC_FIELD = "duration"
1577 ("duration", ht.NoDefault, ht.TNumber, None),
1578 ("on_master", True, ht.TBool, None),
1579 ("on_nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), None),
1580 ("repeat", 0, ht.TPositiveInt, None),
1584 class OpTestAllocator(OpCode):
1585 """Allocator framework testing.
1587 This opcode has two modes:
1588 - gather and return allocator input for a given mode (allocate new
1589 or replace secondary) and a given instance definition (direction
1591 - run a selected allocator for a given operation (as above) and
1592 return the allocator output (direction 'out')
1595 OP_DSC_FIELD = "allocator"
1597 ("direction", ht.NoDefault,
1598 ht.TElemOf(constants.VALID_IALLOCATOR_DIRECTIONS), None),
1599 ("mode", ht.NoDefault, ht.TElemOf(constants.VALID_IALLOCATOR_MODES), None),
1600 ("name", ht.NoDefault, ht.TNonEmptyString, None),
1601 ("nics", ht.NoDefault, ht.TOr(ht.TNone, ht.TListOf(
1602 ht.TDictOf(ht.TElemOf([constants.INIC_MAC, constants.INIC_IP, "bridge"]),
1603 ht.TOr(ht.TNone, ht.TNonEmptyString)))), None),
1604 ("disks", ht.NoDefault, ht.TOr(ht.TNone, ht.TList), None),
1605 ("hypervisor", None, ht.TMaybeString, None),
1606 ("allocator", None, ht.TMaybeString, None),
1607 ("tags", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), None),
1608 ("memory", None, ht.TOr(ht.TNone, ht.TPositiveInt), None),
1609 ("vcpus", None, ht.TOr(ht.TNone, ht.TPositiveInt), None),
1610 ("os", None, ht.TMaybeString, None),
1611 ("disk_template", None, ht.TMaybeString, None),
1612 ("instances", None, ht.TOr(ht.TNone, ht.TListOf(ht.TNonEmptyString)),
1615 ht.TOr(ht.TNone, ht.TElemOf(constants.IALLOCATOR_NEVAC_MODES)), None),
1616 ("target_groups", None, ht.TOr(ht.TNone, ht.TListOf(ht.TNonEmptyString)),
1621 class OpTestJqueue(OpCode):
1622 """Utility opcode to test some aspects of the job queue.
1626 ("notify_waitlock", False, ht.TBool, None),
1627 ("notify_exec", False, ht.TBool, None),
1628 ("log_messages", ht.EmptyList, ht.TListOf(ht.TString), None),
1629 ("fail", False, ht.TBool, None),
1633 class OpTestDummy(OpCode):
1634 """Utility opcode used by unittests.
1638 ("result", ht.NoDefault, ht.NoType, None),
1639 ("messages", ht.NoDefault, ht.NoType, None),
1640 ("fail", ht.NoDefault, ht.NoType, None),
1641 ("submit_jobs", None, ht.NoType, None),
1647 """Returns list of all defined opcodes.
1649 Does not eliminate duplicates by C{OP_ID}.
1652 return [v for v in globals().values()
1653 if (isinstance(v, type) and issubclass(v, OpCode) and
1654 hasattr(v, "OP_ID") and v is not OpCode)]
1657 OP_MAPPING = dict((v.OP_ID, v) for v in _GetOpList())