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")
140 _PIgnoreErrors = ("ignore_errors", ht.EmptyList,
141 ht.TListOf(ht.TElemOf(constants.CV_ALL_ECODES_STRINGS)),
142 "List of error codes that should be treated as warnings")
144 #: OP_ID conversion regular expression
145 _OPID_RE = re.compile("([a-z])([A-Z])")
147 #: Utility function for L{OpClusterSetParams}
148 _TestClusterOsList = ht.TOr(ht.TNone,
149 ht.TListOf(ht.TAnd(ht.TList, ht.TIsLength(2),
150 ht.TMap(ht.WithDesc("GetFirstItem")(compat.fst),
151 ht.TElemOf(constants.DDMS_VALUES)))))
154 # TODO: Generate check from constants.INIC_PARAMS_TYPES
155 #: Utility function for testing NIC definitions
156 _TestNicDef = ht.TDictOf(ht.TElemOf(constants.INIC_PARAMS),
157 ht.TOr(ht.TNone, ht.TNonEmptyString))
159 _TSetParamsResultItemItems = [
160 ht.Comment("name of changed parameter")(ht.TNonEmptyString),
164 _TSetParamsResult = \
165 ht.TListOf(ht.TAnd(ht.TIsLength(len(_TSetParamsResultItemItems)),
166 ht.TItems(_TSetParamsResultItemItems)))
175 #: Attribute name for dependencies
176 DEPEND_ATTR = "depends"
178 #: Attribute name for comment
179 COMMENT_ATTR = "comment"
183 """Convert an opcode class name to an OP_ID.
186 @param name: the class name, as OpXxxYyy
188 @return: the name in the OP_XXXX_YYYY format
191 if not name.startswith("Op"):
193 # Note: (?<=[a-z])(?=[A-Z]) would be ideal, since it wouldn't
194 # consume any input, and hence we would just have all the elements
195 # in the list, one by one; but it seems that split doesn't work on
196 # non-consuming input, hence we have to process the input string a
198 name = _OPID_RE.sub(r"\1,\2", name)
199 elems = name.split(",")
200 return "_".join(n.upper() for n in elems)
203 def RequireFileStorage():
204 """Checks that file storage is enabled.
206 While it doesn't really fit into this module, L{utils} was deemed too large
207 of a dependency to be imported for just one or two functions.
209 @raise errors.OpPrereqError: when file storage is disabled
212 if not constants.ENABLE_FILE_STORAGE:
213 raise errors.OpPrereqError("File storage disabled at configure time",
217 def RequireSharedFileStorage():
218 """Checks that shared file storage is enabled.
220 While it doesn't really fit into this module, L{utils} was deemed too large
221 of a dependency to be imported for just one or two functions.
223 @raise errors.OpPrereqError: when shared file storage is disabled
226 if not constants.ENABLE_SHARED_FILE_STORAGE:
227 raise errors.OpPrereqError("Shared file storage disabled at"
228 " configure time", errors.ECODE_INVAL)
231 @ht.WithDesc("CheckFileStorage")
232 def _CheckFileStorage(value):
233 """Ensures file storage is enabled if used.
236 if value == constants.DT_FILE:
238 elif value == constants.DT_SHARED_FILE:
239 RequireSharedFileStorage()
243 def _BuildDiskTemplateCheck(accept_none):
244 """Builds check for disk template.
246 @type accept_none: bool
247 @param accept_none: whether to accept None as a correct value
251 template_check = ht.TElemOf(constants.DISK_TEMPLATES)
254 template_check = ht.TOr(template_check, ht.TNone)
256 return ht.TAnd(template_check, _CheckFileStorage)
259 def _CheckStorageType(storage_type):
260 """Ensure a given storage type is valid.
263 if storage_type not in constants.VALID_STORAGE_TYPES:
264 raise errors.OpPrereqError("Unknown storage type: %s" % storage_type,
266 if storage_type == constants.ST_FILE:
271 #: Storage type parameter
272 _PStorageType = ("storage_type", ht.NoDefault, _CheckStorageType,
276 class _AutoOpParamSlots(type):
277 """Meta class for opcode definitions.
280 def __new__(mcs, name, bases, attrs):
281 """Called when a class should be created.
283 @param mcs: The meta class
284 @param name: Name of created class
285 @param bases: Base classes
287 @param attrs: Class attributes
290 assert "__slots__" not in attrs, \
291 "Class '%s' defines __slots__ when it should use OP_PARAMS" % name
292 assert "OP_ID" not in attrs, "Class '%s' defining OP_ID" % name
294 attrs["OP_ID"] = _NameToId(name)
296 # Always set OP_PARAMS to avoid duplicates in BaseOpCode.GetAllParams
297 params = attrs.setdefault("OP_PARAMS", [])
299 # Use parameter names as slots
300 slots = [pname for (pname, _, _, _) in params]
302 assert "OP_DSC_FIELD" not in attrs or attrs["OP_DSC_FIELD"] in slots, \
303 "Class '%s' uses unknown field in OP_DSC_FIELD" % name
305 attrs["__slots__"] = slots
307 return type.__new__(mcs, name, bases, attrs)
310 class BaseOpCode(object):
311 """A simple serializable object.
313 This object serves as a parent class for OpCode without any custom
317 # pylint: disable=E1101
318 # as OP_ID is dynamically defined
319 __metaclass__ = _AutoOpParamSlots
321 def __init__(self, **kwargs):
322 """Constructor for BaseOpCode.
324 The constructor takes only keyword arguments and will set
325 attributes on this object based on the passed arguments. As such,
326 it means that you should not pass arguments which are not in the
327 __slots__ attribute for this class.
330 slots = self._all_slots()
333 raise TypeError("Object %s doesn't support the parameter '%s'" %
334 (self.__class__.__name__, key))
335 setattr(self, key, kwargs[key])
337 def __getstate__(self):
338 """Generic serializer.
340 This method just returns the contents of the instance as a
344 @return: the instance attributes and their values
348 for name in self._all_slots():
349 if hasattr(self, name):
350 state[name] = getattr(self, name)
353 def __setstate__(self, state):
354 """Generic unserializer.
356 This method just restores from the serialized state the attributes
357 of the current instance.
359 @param state: the serialized opcode data
363 if not isinstance(state, dict):
364 raise ValueError("Invalid data to __setstate__: expected dict, got %s" %
367 for name in self._all_slots():
368 if name not in state and hasattr(self, name):
372 setattr(self, name, state[name])
376 """Compute the list of all declared slots for a class.
380 for parent in cls.__mro__:
381 slots.extend(getattr(parent, "__slots__", []))
385 def GetAllParams(cls):
386 """Compute list of all parameters for an opcode.
390 for parent in cls.__mro__:
391 slots.extend(getattr(parent, "OP_PARAMS", []))
394 def Validate(self, set_defaults):
395 """Validate opcode parameters, optionally setting default values.
397 @type set_defaults: bool
398 @param set_defaults: Whether to set default values
399 @raise errors.OpPrereqError: When a parameter value doesn't match
403 for (attr_name, default, test, _) in self.GetAllParams():
404 assert test == ht.NoType or callable(test)
406 if not hasattr(self, attr_name):
407 if default == ht.NoDefault:
408 raise errors.OpPrereqError("Required parameter '%s.%s' missing" %
409 (self.OP_ID, attr_name),
412 if callable(default):
416 setattr(self, attr_name, dval)
418 if test == ht.NoType:
422 if set_defaults or hasattr(self, attr_name):
423 attr_val = getattr(self, attr_name)
424 if not test(attr_val):
425 logging.error("OpCode %s, parameter %s, has invalid type %s/value %s",
426 self.OP_ID, attr_name, type(attr_val), attr_val)
427 raise errors.OpPrereqError("Parameter '%s.%s' fails validation" %
428 (self.OP_ID, attr_name),
432 def _BuildJobDepCheck(relative):
433 """Builds check for job dependencies (L{DEPEND_ATTR}).
436 @param relative: Whether to accept relative job IDs (negative)
441 job_id = ht.TOr(ht.TJobId, ht.TRelativeJobId)
446 ht.TAnd(ht.TIsLength(2),
448 ht.TListOf(ht.TElemOf(constants.JOBS_FINALIZED))]))
450 return ht.TOr(ht.TNone, ht.TListOf(job_dep))
453 TNoRelativeJobDependencies = _BuildJobDepCheck(False)
455 #: List of submission status and job ID as returned by C{SubmitManyJobs}
457 ht.TAnd(ht.TIsLength(2),
458 ht.TItems([ht.Comment("success")(ht.TBool),
459 ht.Comment("Job ID if successful, error message"
460 " otherwise")(ht.TOr(ht.TString,
462 TJobIdList = ht.TListOf(_TJobIdListItem)
464 #: Result containing only list of submitted jobs
465 TJobIdListOnly = ht.TStrictDict(True, True, {
466 constants.JOB_IDS_KEY: ht.Comment("List of submitted jobs")(TJobIdList),
470 class OpCode(BaseOpCode):
473 This is the root of the actual OpCode hierarchy. All clases derived
474 from this class should override OP_ID.
476 @cvar OP_ID: The ID of this opcode. This should be unique amongst all
477 children of this class.
478 @cvar OP_DSC_FIELD: The name of a field whose value will be included in the
479 string returned by Summary(); see the docstring of that
481 @cvar OP_PARAMS: List of opcode attributes, the default values they should
482 get if not already defined, and types they must match.
483 @cvar OP_RESULT: Callable to verify opcode result
484 @cvar WITH_LU: Boolean that specifies whether this should be included in
485 mcpu's dispatch table
486 @ivar dry_run: Whether the LU should be run in dry-run mode, i.e. just
488 @ivar priority: Opcode priority for queue
491 # pylint: disable=E1101
492 # as OP_ID is dynamically defined
495 ("dry_run", None, ht.TMaybeBool, "Run checks only, don't execute"),
496 ("debug_level", None, ht.TOr(ht.TNone, ht.TPositiveInt), "Debug level"),
497 ("priority", constants.OP_PRIO_DEFAULT,
498 ht.TElemOf(constants.OP_PRIO_SUBMIT_VALID), "Opcode priority"),
499 (DEPEND_ATTR, None, _BuildJobDepCheck(True),
500 "Job dependencies; if used through ``SubmitManyJobs`` relative (negative)"
501 " job IDs can be used"),
502 (COMMENT_ATTR, None, ht.TMaybeString,
503 "Comment describing the purpose of the opcode"),
507 def __getstate__(self):
508 """Specialized getstate for opcodes.
510 This method adds to the state dictionary the OP_ID of the class,
511 so that on unload we can identify the correct class for
512 instantiating the opcode.
515 @return: the state as a dictionary
518 data = BaseOpCode.__getstate__(self)
519 data["OP_ID"] = self.OP_ID
523 def LoadOpCode(cls, data):
524 """Generic load opcode method.
526 The method identifies the correct opcode class from the dict-form
527 by looking for a OP_ID key, if this is not found, or its value is
528 not available in this module as a child of this class, we fail.
531 @param data: the serialized opcode
534 if not isinstance(data, dict):
535 raise ValueError("Invalid data to LoadOpCode (%s)" % type(data))
536 if "OP_ID" not in data:
537 raise ValueError("Invalid data to LoadOpcode, missing OP_ID")
538 op_id = data["OP_ID"]
540 if op_id in OP_MAPPING:
541 op_class = OP_MAPPING[op_id]
543 raise ValueError("Invalid data to LoadOpCode: OP_ID %s unsupported" %
546 new_data = data.copy()
547 del new_data["OP_ID"]
548 op.__setstate__(new_data)
552 """Generates a summary description of this opcode.
554 The summary is the value of the OP_ID attribute (without the "OP_"
555 prefix), plus the value of the OP_DSC_FIELD attribute, if one was
556 defined; this field should allow to easily identify the operation
557 (for an instance creation job, e.g., it would be the instance
561 assert self.OP_ID is not None and len(self.OP_ID) > 3
562 # all OP_ID start with OP_, we remove that
564 field_name = getattr(self, "OP_DSC_FIELD", None)
566 field_value = getattr(self, field_name, None)
567 if isinstance(field_value, (list, tuple)):
568 field_value = ",".join(str(i) for i in field_value)
569 txt = "%s(%s)" % (txt, field_value)
572 def TinySummary(self):
573 """Generates a compact summary description of the opcode.
576 assert self.OP_ID.startswith("OP_")
578 text = self.OP_ID[3:]
580 for (prefix, supplement) in _SUMMARY_PREFIX.items():
581 if text.startswith(prefix):
582 return supplement + text[len(prefix):]
589 class OpClusterPostInit(OpCode):
590 """Post cluster initialization.
592 This opcode does not touch the cluster at all. Its purpose is to run hooks
593 after the cluster has been initialized.
598 class OpClusterDestroy(OpCode):
599 """Destroy the cluster.
601 This opcode has no other parameters. All the state is irreversibly
602 lost after the execution of this opcode.
607 class OpClusterQuery(OpCode):
608 """Query cluster information."""
611 class OpClusterVerify(OpCode):
612 """Submits all jobs necessary to verify the cluster.
616 _PDebugSimulateErrors,
621 ("group_name", None, ht.TMaybeString, "Group to verify")
623 OP_RESULT = TJobIdListOnly
626 class OpClusterVerifyConfig(OpCode):
627 """Verify the cluster config.
631 _PDebugSimulateErrors,
639 class OpClusterVerifyGroup(OpCode):
640 """Run verify on a node group from the cluster.
642 @type skip_checks: C{list}
643 @ivar skip_checks: steps to be skipped from the verify process; this
644 needs to be a subset of
645 L{constants.VERIFY_OPTIONAL_CHECKS}; currently
646 only L{constants.VERIFY_NPLUSONE_MEM} can be passed
649 OP_DSC_FIELD = "group_name"
652 _PDebugSimulateErrors,
661 class OpClusterVerifyDisks(OpCode):
662 """Verify the cluster disks.
665 OP_RESULT = TJobIdListOnly
668 class OpGroupVerifyDisks(OpCode):
669 """Verifies the status of all disks in a node group.
671 Result: a tuple of three elements:
672 - dict of node names with issues (values: error msg)
673 - list of instances with degraded disks (that should be activated)
674 - dict of instances with missing logical volumes (values: (node, vol)
675 pairs with details about the missing volumes)
677 In normal operation, all lists should be empty. A non-empty instance
678 list (3rd element of the result) is still ok (errors were fixed) but
679 non-empty node list means some node is down, and probably there are
680 unfixable drbd errors.
682 Note that only instances that are drbd-based are taken into
683 consideration. This might need to be revisited in the future.
686 OP_DSC_FIELD = "group_name"
691 ht.TAnd(ht.TIsLength(3),
692 ht.TItems([ht.TDictOf(ht.TString, ht.TString),
693 ht.TListOf(ht.TString),
694 ht.TDictOf(ht.TString, ht.TListOf(ht.TString))]))
697 class OpClusterRepairDiskSizes(OpCode):
698 """Verify the disk sizes of the instances and fixes configuration
701 Parameters: optional instances list, in case we want to restrict the
702 checks to only a subset of the instances.
704 Result: a list of tuples, (instance, disk, new-size) for changed
707 In normal operation, the list should be empty.
709 @type instances: list
710 @ivar instances: the list of instances to check, or empty for all instances
714 ("instances", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), None),
718 class OpClusterConfigQuery(OpCode):
719 """Query cluster configuration values."""
725 class OpClusterRename(OpCode):
726 """Rename the cluster.
729 @ivar name: The new name of the cluster. The name and/or the master IP
730 address will be changed to match the new name and its IP
734 OP_DSC_FIELD = "name"
736 ("name", ht.NoDefault, ht.TNonEmptyString, None),
740 class OpClusterSetParams(OpCode):
741 """Change the parameters of the cluster.
743 @type vg_name: C{str} or C{None}
744 @ivar vg_name: The new volume group name or None to disable LVM usage.
748 ("vg_name", None, ht.TMaybeString, "Volume group name"),
749 ("enabled_hypervisors", None,
750 ht.TOr(ht.TAnd(ht.TListOf(ht.TElemOf(constants.HYPER_TYPES)), ht.TTrue),
752 "List of enabled hypervisors"),
753 ("hvparams", None, ht.TOr(ht.TDictOf(ht.TNonEmptyString, ht.TDict),
755 "Cluster-wide hypervisor parameter defaults, hypervisor-dependent"),
756 ("beparams", None, ht.TOr(ht.TDict, ht.TNone),
757 "Cluster-wide backend parameter defaults"),
758 ("os_hvp", None, ht.TOr(ht.TDictOf(ht.TNonEmptyString, ht.TDict),
760 "Cluster-wide per-OS hypervisor parameter defaults"),
761 ("osparams", None, ht.TOr(ht.TDictOf(ht.TNonEmptyString, ht.TDict),
763 "Cluster-wide OS parameter defaults"),
764 ("candidate_pool_size", None, ht.TOr(ht.TStrictPositiveInt, ht.TNone),
765 "Master candidate pool size"),
766 ("uid_pool", None, ht.NoType,
767 "Set UID pool, must be list of lists describing UID ranges (two items,"
768 " start and end inclusive)"),
769 ("add_uids", None, ht.NoType,
770 "Extend UID pool, must be list of lists describing UID ranges (two"
771 " items, start and end inclusive) to be added"),
772 ("remove_uids", None, ht.NoType,
773 "Shrink UID pool, must be list of lists describing UID ranges (two"
774 " items, start and end inclusive) to be removed"),
775 ("maintain_node_health", None, ht.TMaybeBool,
776 "Whether to automatically maintain node health"),
777 ("prealloc_wipe_disks", None, ht.TMaybeBool,
778 "Whether to wipe disks before allocating them to instances"),
779 ("nicparams", None, ht.TMaybeDict, "Cluster-wide NIC parameter defaults"),
780 ("ndparams", None, ht.TMaybeDict, "Cluster-wide node parameter defaults"),
781 ("drbd_helper", None, ht.TOr(ht.TString, ht.TNone), "DRBD helper program"),
782 ("default_iallocator", None, ht.TOr(ht.TString, ht.TNone),
783 "Default iallocator for cluster"),
784 ("master_netdev", None, ht.TOr(ht.TString, ht.TNone),
785 "Master network device"),
786 ("master_netmask", None, ht.TOr(ht.TInt, ht.TNone),
787 "Netmask of the master IP"),
788 ("reserved_lvs", None, ht.TOr(ht.TListOf(ht.TNonEmptyString), ht.TNone),
789 "List of reserved LVs"),
790 ("hidden_os", None, _TestClusterOsList,
791 "Modify list of hidden operating systems. Each modification must have"
792 " two items, the operation and the OS name. The operation can be"
793 " ``%s`` or ``%s``." % (constants.DDM_ADD, constants.DDM_REMOVE)),
794 ("blacklisted_os", None, _TestClusterOsList,
795 "Modify list of blacklisted operating systems. Each modification must have"
796 " two items, the operation and the OS name. The operation can be"
797 " ``%s`` or ``%s``." % (constants.DDM_ADD, constants.DDM_REMOVE)),
801 class OpClusterRedistConf(OpCode):
802 """Force a full push of the cluster configuration.
807 class OpClusterActivateMasterIp(OpCode):
808 """Activate the master IP on the master node.
813 class OpClusterDeactivateMasterIp(OpCode):
814 """Deactivate the master IP on the master node.
819 class OpQuery(OpCode):
820 """Query for resources/items.
822 @ivar what: Resources to query for, must be one of L{constants.QR_VIA_OP}
823 @ivar fields: List of fields to retrieve
824 @ivar filter: Query filter
827 OP_DSC_FIELD = "what"
831 ("fields", ht.NoDefault, ht.TListOf(ht.TNonEmptyString),
833 ("filter", None, ht.TOr(ht.TNone, ht.TListOf),
838 class OpQueryFields(OpCode):
839 """Query for available resource/item fields.
841 @ivar what: Resources to query for, must be one of L{constants.QR_VIA_OP}
842 @ivar fields: List of fields to retrieve
845 OP_DSC_FIELD = "what"
848 ("fields", None, ht.TOr(ht.TNone, ht.TListOf(ht.TNonEmptyString)),
849 "Requested fields; if not given, all are returned"),
853 class OpOobCommand(OpCode):
854 """Interact with OOB."""
856 ("node_names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
857 "List of nodes to run the OOB command against"),
858 ("command", None, ht.TElemOf(constants.OOB_COMMANDS),
859 "OOB command to be run"),
860 ("timeout", constants.OOB_TIMEOUT, ht.TInt,
861 "Timeout before the OOB helper will be terminated"),
862 ("ignore_status", False, ht.TBool,
863 "Ignores the node offline status for power off"),
864 ("power_delay", constants.OOB_POWER_DELAY, ht.TPositiveFloat,
865 "Time in seconds to wait between powering on nodes"),
871 class OpNodeRemove(OpCode):
874 @type node_name: C{str}
875 @ivar node_name: The name of the node to remove. If the node still has
876 instances on it, the operation will fail.
879 OP_DSC_FIELD = "node_name"
885 class OpNodeAdd(OpCode):
886 """Add a node to the cluster.
888 @type node_name: C{str}
889 @ivar node_name: The name of the node to add. This can be a short name,
890 but it will be expanded to the FQDN.
891 @type primary_ip: IP address
892 @ivar primary_ip: The primary IP of the node. This will be ignored when the
893 opcode is submitted, but will be filled during the node
894 add (so it will be visible in the job query).
895 @type secondary_ip: IP address
896 @ivar secondary_ip: The secondary IP of the node. This needs to be passed
897 if the cluster has been initialized in 'dual-network'
898 mode, otherwise it must not be given.
900 @ivar readd: Whether to re-add an existing node to the cluster. If
901 this is not passed, then the operation will abort if the node
902 name is already in the cluster; use this parameter to 'repair'
903 a node that had its configuration broken, or was reinstalled
904 without removal from the cluster.
906 @ivar group: The node group to which this node will belong.
907 @type vm_capable: C{bool}
908 @ivar vm_capable: The vm_capable node attribute
909 @type master_capable: C{bool}
910 @ivar master_capable: The master_capable node attribute
913 OP_DSC_FIELD = "node_name"
916 ("primary_ip", None, ht.NoType, "Primary IP address"),
917 ("secondary_ip", None, ht.TMaybeString, "Secondary IP address"),
918 ("readd", False, ht.TBool, "Whether node is re-added to cluster"),
919 ("group", None, ht.TMaybeString, "Initial node group"),
920 ("master_capable", None, ht.TMaybeBool,
921 "Whether node can become master or master candidate"),
922 ("vm_capable", None, ht.TMaybeBool,
923 "Whether node can host instances"),
924 ("ndparams", None, ht.TMaybeDict, "Node parameters"),
928 class OpNodeQuery(OpCode):
929 """Compute the list of nodes."""
933 ("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
934 "Empty list to query all nodes, node names otherwise"),
938 class OpNodeQueryvols(OpCode):
939 """Get list of volumes on node."""
942 ("nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
943 "Empty list to query all nodes, node names otherwise"),
947 class OpNodeQueryStorage(OpCode):
948 """Get information on storage for node(s)."""
952 ("nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), "List of nodes"),
953 ("name", None, ht.TMaybeString, "Storage name"),
957 class OpNodeModifyStorage(OpCode):
958 """Modifies the properies of a storage unit"""
963 ("changes", ht.NoDefault, ht.TDict, "Requested changes"),
967 class OpRepairNodeStorage(OpCode):
968 """Repairs the volume group on a node."""
969 OP_DSC_FIELD = "node_name"
978 class OpNodeSetParams(OpCode):
979 """Change the parameters of a node."""
980 OP_DSC_FIELD = "node_name"
984 ("master_candidate", None, ht.TMaybeBool,
985 "Whether the node should become a master candidate"),
986 ("offline", None, ht.TMaybeBool,
987 "Whether the node should be marked as offline"),
988 ("drained", None, ht.TMaybeBool,
989 "Whether the node should be marked as drained"),
990 ("auto_promote", False, ht.TBool,
991 "Whether node(s) should be promoted to master candidate if necessary"),
992 ("master_capable", None, ht.TMaybeBool,
993 "Denote whether node can become master or master candidate"),
994 ("vm_capable", None, ht.TMaybeBool,
995 "Denote whether node can host instances"),
996 ("secondary_ip", None, ht.TMaybeString,
997 "Change node's secondary IP address"),
998 ("ndparams", None, ht.TMaybeDict, "Set node parameters"),
999 ("powered", None, ht.TMaybeBool,
1000 "Whether the node should be marked as powered"),
1002 OP_RESULT = _TSetParamsResult
1005 class OpNodePowercycle(OpCode):
1006 """Tries to powercycle a node."""
1007 OP_DSC_FIELD = "node_name"
1014 class OpNodeMigrate(OpCode):
1015 """Migrate all instances from a node."""
1016 OP_DSC_FIELD = "node_name"
1021 _PMigrationTargetNode,
1022 ("iallocator", None, ht.TMaybeString,
1023 "Iallocator for deciding the target node for shared-storage instances"),
1027 class OpNodeEvacuate(OpCode):
1028 """Evacuate instances off a number of nodes."""
1029 OP_DSC_FIELD = "node_name"
1033 ("remote_node", None, ht.TMaybeString, "New secondary node"),
1034 ("iallocator", None, ht.TMaybeString, "Iallocator for computing solution"),
1035 ("mode", ht.NoDefault, ht.TElemOf(constants.IALLOCATOR_NEVAC_MODES),
1036 "Node evacuation mode"),
1038 OP_RESULT = TJobIdListOnly
1043 class OpInstanceCreate(OpCode):
1044 """Create an instance.
1046 @ivar instance_name: Instance name
1047 @ivar mode: Instance creation mode (one of L{constants.INSTANCE_CREATE_MODES})
1048 @ivar source_handshake: Signed handshake from source (remote import only)
1049 @ivar source_x509_ca: Source X509 CA in PEM format (remote import only)
1050 @ivar source_instance_name: Previous name of instance (remote import only)
1051 @ivar source_shutdown_timeout: Shutdown timeout used for source instance
1052 (remote import only)
1055 OP_DSC_FIELD = "instance_name"
1061 ("beparams", ht.EmptyDict, ht.TDict, "Backend parameters for instance"),
1062 ("disks", ht.NoDefault,
1063 # TODO: Generate check from constants.IDISK_PARAMS_TYPES
1064 ht.TListOf(ht.TDictOf(ht.TElemOf(constants.IDISK_PARAMS),
1065 ht.TOr(ht.TNonEmptyString, ht.TInt))),
1066 "Disk descriptions, for example ``[{\"%s\": 100}, {\"%s\": 5}]``;"
1067 " each disk definition must contain a ``%s`` value and"
1068 " can contain an optional ``%s`` value denoting the disk access mode"
1070 (constants.IDISK_SIZE, constants.IDISK_SIZE, constants.IDISK_SIZE,
1071 constants.IDISK_MODE,
1072 " or ".join("``%s``" % i for i in sorted(constants.DISK_ACCESS_SET)))),
1073 ("disk_template", ht.NoDefault, _BuildDiskTemplateCheck(True),
1075 ("file_driver", None, ht.TOr(ht.TNone, ht.TElemOf(constants.FILE_DRIVER)),
1076 "Driver for file-backed disks"),
1077 ("file_storage_dir", None, ht.TMaybeString,
1078 "Directory for storing file-backed disks"),
1079 ("hvparams", ht.EmptyDict, ht.TDict,
1080 "Hypervisor parameters for instance, hypervisor-dependent"),
1081 ("hypervisor", None, ht.TMaybeString, "Hypervisor"),
1082 ("iallocator", None, ht.TMaybeString,
1083 "Iallocator for deciding which node(s) to use"),
1084 ("identify_defaults", False, ht.TBool,
1085 "Reset instance parameters to default if equal"),
1086 ("ip_check", True, ht.TBool, _PIpCheckDoc),
1087 ("mode", ht.NoDefault, ht.TElemOf(constants.INSTANCE_CREATE_MODES),
1088 "Instance creation mode"),
1089 ("nics", ht.NoDefault, ht.TListOf(_TestNicDef),
1090 "List of NIC (network interface) definitions, for example"
1091 " ``[{}, {}, {\"%s\": \"198.51.100.4\"}]``; each NIC definition can"
1092 " contain the optional values %s" %
1094 ", ".join("``%s``" % i for i in sorted(constants.INIC_PARAMS)))),
1095 ("no_install", None, ht.TMaybeBool,
1096 "Do not install the OS (will disable automatic start)"),
1097 ("osparams", ht.EmptyDict, ht.TDict, "OS parameters for instance"),
1098 ("os_type", None, ht.TMaybeString, "Operating system"),
1099 ("pnode", None, ht.TMaybeString, "Primary node"),
1100 ("snode", None, ht.TMaybeString, "Secondary node"),
1101 ("source_handshake", None, ht.TOr(ht.TList, ht.TNone),
1102 "Signed handshake from source (remote import only)"),
1103 ("source_instance_name", None, ht.TMaybeString,
1104 "Source instance name (remote import only)"),
1105 ("source_shutdown_timeout", constants.DEFAULT_SHUTDOWN_TIMEOUT,
1107 "How long source instance was given to shut down (remote import only)"),
1108 ("source_x509_ca", None, ht.TMaybeString,
1109 "Source X509 CA in PEM format (remote import only)"),
1110 ("src_node", None, ht.TMaybeString, "Source node for import"),
1111 ("src_path", None, ht.TMaybeString, "Source directory for import"),
1112 ("start", True, ht.TBool, "Whether to start instance after creation"),
1113 ("tags", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), "Instance tags"),
1115 OP_RESULT = ht.Comment("instance nodes")(ht.TListOf(ht.TNonEmptyString))
1118 class OpInstanceReinstall(OpCode):
1119 """Reinstall an instance's OS."""
1120 OP_DSC_FIELD = "instance_name"
1124 ("os_type", None, ht.TMaybeString, "Instance operating system"),
1125 ("osparams", None, ht.TMaybeDict, "Temporary OS parameters"),
1129 class OpInstanceRemove(OpCode):
1130 """Remove an instance."""
1131 OP_DSC_FIELD = "instance_name"
1135 ("ignore_failures", False, ht.TBool,
1136 "Whether to ignore failures during removal"),
1140 class OpInstanceRename(OpCode):
1141 """Rename an instance."""
1145 ("new_name", ht.NoDefault, ht.TNonEmptyString, "New instance name"),
1146 ("ip_check", False, ht.TBool, _PIpCheckDoc),
1148 OP_RESULT = ht.Comment("New instance name")(ht.TNonEmptyString)
1151 class OpInstanceStartup(OpCode):
1152 """Startup an instance."""
1153 OP_DSC_FIELD = "instance_name"
1157 _PIgnoreOfflineNodes,
1158 ("hvparams", ht.EmptyDict, ht.TDict,
1159 "Temporary hypervisor parameters, hypervisor-dependent"),
1160 ("beparams", ht.EmptyDict, ht.TDict, "Temporary backend parameters"),
1166 class OpInstanceShutdown(OpCode):
1167 """Shutdown an instance."""
1168 OP_DSC_FIELD = "instance_name"
1171 _PIgnoreOfflineNodes,
1172 ("timeout", constants.DEFAULT_SHUTDOWN_TIMEOUT, ht.TPositiveInt,
1173 "How long to wait for instance to shut down"),
1178 class OpInstanceReboot(OpCode):
1179 """Reboot an instance."""
1180 OP_DSC_FIELD = "instance_name"
1184 ("ignore_secondaries", False, ht.TBool,
1185 "Whether to start the instance even if secondary disks are failing"),
1186 ("reboot_type", ht.NoDefault, ht.TElemOf(constants.REBOOT_TYPES),
1187 "How to reboot instance"),
1191 class OpInstanceReplaceDisks(OpCode):
1192 """Replace the disks of an instance."""
1193 OP_DSC_FIELD = "instance_name"
1197 ("mode", ht.NoDefault, ht.TElemOf(constants.REPLACE_MODES),
1198 "Replacement mode"),
1199 ("disks", ht.EmptyList, ht.TListOf(ht.TPositiveInt),
1201 ("remote_node", None, ht.TMaybeString, "New secondary node"),
1202 ("iallocator", None, ht.TMaybeString,
1203 "Iallocator for deciding new secondary node"),
1207 class OpInstanceFailover(OpCode):
1208 """Failover an instance."""
1209 OP_DSC_FIELD = "instance_name"
1213 _PIgnoreConsistency,
1214 _PMigrationTargetNode,
1215 ("iallocator", None, ht.TMaybeString,
1216 "Iallocator for deciding the target node for shared-storage instances"),
1220 class OpInstanceMigrate(OpCode):
1221 """Migrate an instance.
1223 This migrates (without shutting down an instance) to its secondary
1226 @ivar instance_name: the name of the instance
1227 @ivar mode: the migration mode (live, non-live or None for auto)
1230 OP_DSC_FIELD = "instance_name"
1235 _PMigrationTargetNode,
1236 ("cleanup", False, ht.TBool,
1237 "Whether a previously failed migration should be cleaned up"),
1238 ("iallocator", None, ht.TMaybeString,
1239 "Iallocator for deciding the target node for shared-storage instances"),
1240 ("allow_failover", False, ht.TBool,
1241 "Whether we can fallback to failover if migration is not possible"),
1245 class OpInstanceMove(OpCode):
1246 """Move an instance.
1248 This move (with shutting down an instance and data copying) to an
1251 @ivar instance_name: the name of the instance
1252 @ivar target_node: the destination node
1255 OP_DSC_FIELD = "instance_name"
1259 ("target_node", ht.NoDefault, ht.TNonEmptyString, "Target node"),
1260 _PIgnoreConsistency,
1264 class OpInstanceConsole(OpCode):
1265 """Connect to an instance's console."""
1266 OP_DSC_FIELD = "instance_name"
1272 class OpInstanceActivateDisks(OpCode):
1273 """Activate an instance's disks."""
1274 OP_DSC_FIELD = "instance_name"
1277 ("ignore_size", False, ht.TBool, "Whether to ignore recorded size"),
1281 class OpInstanceDeactivateDisks(OpCode):
1282 """Deactivate an instance's disks."""
1283 OP_DSC_FIELD = "instance_name"
1290 class OpInstanceRecreateDisks(OpCode):
1291 """Recreate an instance's disks."""
1292 OP_DSC_FIELD = "instance_name"
1295 ("disks", ht.EmptyList, ht.TListOf(ht.TPositiveInt),
1296 "List of disk indexes"),
1297 ("nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
1298 "New instance nodes, if relocation is desired"),
1302 class OpInstanceQuery(OpCode):
1303 """Compute the list of instances."""
1307 ("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
1308 "Empty list to query all instances, instance names otherwise"),
1312 class OpInstanceQueryData(OpCode):
1313 """Compute the run-time status of instances."""
1316 ("instances", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
1318 ("static", False, ht.TBool,
1319 "Whether to only return configuration data without querying"
1324 class OpInstanceSetParams(OpCode):
1325 """Change the parameters of an instance."""
1326 OP_DSC_FIELD = "instance_name"
1331 # TODO: Use _TestNicDef
1332 ("nics", ht.EmptyList, ht.TList,
1333 "List of NIC changes. Each item is of the form ``(op, settings)``."
1334 " ``op`` can be ``%s`` to add a new NIC with the specified settings,"
1335 " ``%s`` to remove the last NIC or a number to modify the settings"
1336 " of the NIC with that index." %
1337 (constants.DDM_ADD, constants.DDM_REMOVE)),
1338 ("disks", ht.EmptyList, ht.TList, "List of disk changes. See ``nics``."),
1339 ("beparams", ht.EmptyDict, ht.TDict, "Per-instance backend parameters"),
1340 ("hvparams", ht.EmptyDict, ht.TDict,
1341 "Per-instance hypervisor parameters, hypervisor-dependent"),
1342 ("disk_template", None, ht.TOr(ht.TNone, _BuildDiskTemplateCheck(False)),
1343 "Disk template for instance"),
1344 ("remote_node", None, ht.TMaybeString,
1345 "Secondary node (used when changing disk template)"),
1346 ("os_name", None, ht.TMaybeString,
1347 "Change instance's OS name. Does not reinstall the instance."),
1348 ("osparams", None, ht.TMaybeDict, "Per-instance OS parameters"),
1349 ("wait_for_sync", True, ht.TBool,
1350 "Whether to wait for the disk to synchronize, when changing template"),
1352 OP_RESULT = _TSetParamsResult
1355 class OpInstanceGrowDisk(OpCode):
1356 """Grow a disk of an instance."""
1357 OP_DSC_FIELD = "instance_name"
1361 ("disk", ht.NoDefault, ht.TInt, "Disk index"),
1362 ("amount", ht.NoDefault, ht.TInt,
1363 "Amount of disk space to add (megabytes)"),
1367 class OpInstanceChangeGroup(OpCode):
1368 """Moves an instance to another node group."""
1369 OP_DSC_FIELD = "instance_name"
1373 ("iallocator", None, ht.TMaybeString, "Iallocator for computing solution"),
1374 ("target_groups", None, ht.TOr(ht.TNone, ht.TListOf(ht.TNonEmptyString)),
1375 "Destination group names or UUIDs (defaults to \"all but current group\""),
1377 OP_RESULT = TJobIdListOnly
1380 # Node group opcodes
1382 class OpGroupAdd(OpCode):
1383 """Add a node group to the cluster."""
1384 OP_DSC_FIELD = "group_name"
1387 _PNodeGroupAllocPolicy,
1392 class OpGroupAssignNodes(OpCode):
1393 """Assign nodes to a node group."""
1394 OP_DSC_FIELD = "group_name"
1398 ("nodes", ht.NoDefault, ht.TListOf(ht.TNonEmptyString),
1399 "List of nodes to assign"),
1403 class OpGroupQuery(OpCode):
1404 """Compute the list of node groups."""
1407 ("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
1408 "Empty list to query all groups, group names otherwise"),
1412 class OpGroupSetParams(OpCode):
1413 """Change the parameters of a node group."""
1414 OP_DSC_FIELD = "group_name"
1417 _PNodeGroupAllocPolicy,
1420 OP_RESULT = _TSetParamsResult
1423 class OpGroupRemove(OpCode):
1424 """Remove a node group from the cluster."""
1425 OP_DSC_FIELD = "group_name"
1431 class OpGroupRename(OpCode):
1432 """Rename a node group in the cluster."""
1435 ("new_name", ht.NoDefault, ht.TNonEmptyString, "New group name"),
1437 OP_RESULT = ht.Comment("New group name")(ht.TNonEmptyString)
1440 class OpGroupEvacuate(OpCode):
1441 """Evacuate a node group in the cluster."""
1442 OP_DSC_FIELD = "group_name"
1446 ("iallocator", None, ht.TMaybeString, "Iallocator for computing solution"),
1447 ("target_groups", None, ht.TOr(ht.TNone, ht.TListOf(ht.TNonEmptyString)),
1448 "Destination group names or UUIDs"),
1450 OP_RESULT = TJobIdListOnly
1454 class OpOsDiagnose(OpCode):
1455 """Compute the list of guest operating systems."""
1458 ("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
1459 "Which operating systems to diagnose"),
1464 class OpBackupQuery(OpCode):
1465 """Compute the list of exported images."""
1468 ("nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
1469 "Empty list to query all nodes, node names otherwise"),
1473 class OpBackupPrepare(OpCode):
1474 """Prepares an instance export.
1476 @ivar instance_name: Instance name
1477 @ivar mode: Export mode (one of L{constants.EXPORT_MODES})
1480 OP_DSC_FIELD = "instance_name"
1483 ("mode", ht.NoDefault, ht.TElemOf(constants.EXPORT_MODES),
1488 class OpBackupExport(OpCode):
1489 """Export an instance.
1491 For local exports, the export destination is the node name. For remote
1492 exports, the export destination is a list of tuples, each consisting of
1493 hostname/IP address, port, HMAC and HMAC salt. The HMAC is calculated using
1494 the cluster domain secret over the value "${index}:${hostname}:${port}". The
1495 destination X509 CA must be a signed certificate.
1497 @ivar mode: Export mode (one of L{constants.EXPORT_MODES})
1498 @ivar target_node: Export destination
1499 @ivar x509_key_name: X509 key to use (remote export only)
1500 @ivar destination_x509_ca: Destination X509 CA in PEM format (remote export
1504 OP_DSC_FIELD = "instance_name"
1508 # TODO: Rename target_node as it changes meaning for different export modes
1509 # (e.g. "destination")
1510 ("target_node", ht.NoDefault, ht.TOr(ht.TNonEmptyString, ht.TList),
1511 "Destination information, depends on export mode"),
1512 ("shutdown", True, ht.TBool, "Whether to shutdown instance before export"),
1513 ("remove_instance", False, ht.TBool,
1514 "Whether to remove instance after export"),
1515 ("ignore_remove_failures", False, ht.TBool,
1516 "Whether to ignore failures while removing instances"),
1517 ("mode", constants.EXPORT_MODE_LOCAL, ht.TElemOf(constants.EXPORT_MODES),
1519 ("x509_key_name", None, ht.TOr(ht.TList, ht.TNone),
1520 "Name of X509 key (remote export only)"),
1521 ("destination_x509_ca", None, ht.TMaybeString,
1522 "Destination X509 CA (remote export only)"),
1526 class OpBackupRemove(OpCode):
1527 """Remove an instance's export."""
1528 OP_DSC_FIELD = "instance_name"
1535 class OpTagsGet(OpCode):
1536 """Returns the tags of the given object."""
1537 OP_DSC_FIELD = "name"
1540 # Name is only meaningful for nodes and instances
1541 ("name", ht.NoDefault, ht.TMaybeString, None),
1545 class OpTagsSearch(OpCode):
1546 """Searches the tags in the cluster for a given pattern."""
1547 OP_DSC_FIELD = "pattern"
1549 ("pattern", ht.NoDefault, ht.TNonEmptyString, None),
1553 class OpTagsSet(OpCode):
1554 """Add a list of tags on a given object."""
1558 # Name is only meaningful for nodes and instances
1559 ("name", ht.NoDefault, ht.TMaybeString, None),
1563 class OpTagsDel(OpCode):
1564 """Remove a list of tags from a given object."""
1568 # Name is only meaningful for nodes and instances
1569 ("name", ht.NoDefault, ht.TMaybeString, None),
1574 class OpTestDelay(OpCode):
1575 """Sleeps for a configured amount of time.
1577 This is used just for debugging and testing.
1580 - duration: the time to sleep
1581 - on_master: if true, sleep on the master
1582 - on_nodes: list of nodes in which to sleep
1584 If the on_master parameter is true, it will execute a sleep on the
1585 master (before any node sleep).
1587 If the on_nodes list is not empty, it will sleep on those nodes
1588 (after the sleep on the master, if that is enabled).
1590 As an additional feature, the case of duration < 0 will be reported
1591 as an execution error, so this opcode can be used as a failure
1592 generator. The case of duration == 0 will not be treated specially.
1595 OP_DSC_FIELD = "duration"
1597 ("duration", ht.NoDefault, ht.TNumber, None),
1598 ("on_master", True, ht.TBool, None),
1599 ("on_nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), None),
1600 ("repeat", 0, ht.TPositiveInt, None),
1604 class OpTestAllocator(OpCode):
1605 """Allocator framework testing.
1607 This opcode has two modes:
1608 - gather and return allocator input for a given mode (allocate new
1609 or replace secondary) and a given instance definition (direction
1611 - run a selected allocator for a given operation (as above) and
1612 return the allocator output (direction 'out')
1615 OP_DSC_FIELD = "allocator"
1617 ("direction", ht.NoDefault,
1618 ht.TElemOf(constants.VALID_IALLOCATOR_DIRECTIONS), None),
1619 ("mode", ht.NoDefault, ht.TElemOf(constants.VALID_IALLOCATOR_MODES), None),
1620 ("name", ht.NoDefault, ht.TNonEmptyString, None),
1621 ("nics", ht.NoDefault, ht.TOr(ht.TNone, ht.TListOf(
1622 ht.TDictOf(ht.TElemOf([constants.INIC_MAC, constants.INIC_IP, "bridge"]),
1623 ht.TOr(ht.TNone, ht.TNonEmptyString)))), None),
1624 ("disks", ht.NoDefault, ht.TOr(ht.TNone, ht.TList), None),
1625 ("hypervisor", None, ht.TMaybeString, None),
1626 ("allocator", None, ht.TMaybeString, None),
1627 ("tags", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), None),
1628 ("memory", None, ht.TOr(ht.TNone, ht.TPositiveInt), None),
1629 ("vcpus", None, ht.TOr(ht.TNone, ht.TPositiveInt), None),
1630 ("os", None, ht.TMaybeString, None),
1631 ("disk_template", None, ht.TMaybeString, None),
1632 ("instances", None, ht.TOr(ht.TNone, ht.TListOf(ht.TNonEmptyString)),
1635 ht.TOr(ht.TNone, ht.TElemOf(constants.IALLOCATOR_NEVAC_MODES)), None),
1636 ("target_groups", None, ht.TOr(ht.TNone, ht.TListOf(ht.TNonEmptyString)),
1641 class OpTestJqueue(OpCode):
1642 """Utility opcode to test some aspects of the job queue.
1646 ("notify_waitlock", False, ht.TBool, None),
1647 ("notify_exec", False, ht.TBool, None),
1648 ("log_messages", ht.EmptyList, ht.TListOf(ht.TString), None),
1649 ("fail", False, ht.TBool, None),
1653 class OpTestDummy(OpCode):
1654 """Utility opcode used by unittests.
1658 ("result", ht.NoDefault, ht.NoType, None),
1659 ("messages", ht.NoDefault, ht.NoType, None),
1660 ("fail", ht.NoDefault, ht.NoType, None),
1661 ("submit_jobs", None, ht.NoType, None),
1667 """Returns list of all defined opcodes.
1669 Does not eliminate duplicates by C{OP_ID}.
1672 return [v for v in globals().values()
1673 if (isinstance(v, type) and issubclass(v, OpCode) and
1674 hasattr(v, "OP_ID") and v is not OpCode)]
1677 OP_MAPPING = dict((v.OP_ID, v) for v in _GetOpList())