root / lib / opcodes.py @ 528140fb
History | View | Annotate | Download (36.7 kB)
1 | 2f31098c | Iustin Pop | #
|
---|---|---|---|
2 | a8083063 | Iustin Pop | #
|
3 | a8083063 | Iustin Pop | |
4 | 687c10d9 | Iustin Pop | # Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Google Inc.
|
5 | a8083063 | Iustin Pop | #
|
6 | a8083063 | Iustin Pop | # This program is free software; you can redistribute it and/or modify
|
7 | a8083063 | Iustin Pop | # it under the terms of the GNU General Public License as published by
|
8 | a8083063 | Iustin Pop | # the Free Software Foundation; either version 2 of the License, or
|
9 | a8083063 | Iustin Pop | # (at your option) any later version.
|
10 | a8083063 | Iustin Pop | #
|
11 | a8083063 | Iustin Pop | # This program is distributed in the hope that it will be useful, but
|
12 | a8083063 | Iustin Pop | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | a8083063 | Iustin Pop | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 | a8083063 | Iustin Pop | # General Public License for more details.
|
15 | a8083063 | Iustin Pop | #
|
16 | a8083063 | Iustin Pop | # You should have received a copy of the GNU General Public License
|
17 | a8083063 | Iustin Pop | # along with this program; if not, write to the Free Software
|
18 | a8083063 | Iustin Pop | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
19 | a8083063 | Iustin Pop | # 02110-1301, USA.
|
20 | a8083063 | Iustin Pop | |
21 | a8083063 | Iustin Pop | |
22 | a8083063 | Iustin Pop | """OpCodes module
|
23 | a8083063 | Iustin Pop |
|
24 | a8083063 | Iustin Pop | This module implements the data structures which define the cluster
|
25 | a8083063 | Iustin Pop | operations - the so-called opcodes.
|
26 | a8083063 | Iustin Pop |
|
27 | 0e46916d | Iustin Pop | Every operation which modifies the cluster state is expressed via
|
28 | 0e46916d | Iustin Pop | opcodes.
|
29 | a8083063 | Iustin Pop |
|
30 | a8083063 | Iustin Pop | """
|
31 | a8083063 | Iustin Pop | |
32 | a8083063 | Iustin Pop | # this are practically structures, so disable the message about too
|
33 | a8083063 | Iustin Pop | # few public methods:
|
34 | a8083063 | Iustin Pop | # pylint: disable-msg=R0903
|
35 | a8083063 | Iustin Pop | |
36 | 1cbef6d8 | Michael Hanselmann | import logging |
37 | ff0d18e6 | Iustin Pop | import re |
38 | 1cbef6d8 | Michael Hanselmann | |
39 | 65e183af | Michael Hanselmann | from ganeti import constants |
40 | 65e183af | Michael Hanselmann | from ganeti import errors |
41 | 65e183af | Michael Hanselmann | from ganeti import ht |
42 | 65e183af | Michael Hanselmann | |
43 | 65e183af | Michael Hanselmann | |
44 | 65e183af | Michael Hanselmann | # Common opcode attributes
|
45 | 65e183af | Michael Hanselmann | |
46 | 65e183af | Michael Hanselmann | #: output fields for a query operation
|
47 | 65e183af | Michael Hanselmann | _POutputFields = ("output_fields", ht.NoDefault, ht.TListOf(ht.TNonEmptyString))
|
48 | 65e183af | Michael Hanselmann | |
49 | 65e183af | Michael Hanselmann | #: the shutdown timeout
|
50 | 65e183af | Michael Hanselmann | _PShutdownTimeout = ("shutdown_timeout", constants.DEFAULT_SHUTDOWN_TIMEOUT,
|
51 | 65e183af | Michael Hanselmann | ht.TPositiveInt) |
52 | 65e183af | Michael Hanselmann | |
53 | 65e183af | Michael Hanselmann | #: the force parameter
|
54 | 65e183af | Michael Hanselmann | _PForce = ("force", False, ht.TBool) |
55 | 65e183af | Michael Hanselmann | |
56 | 65e183af | Michael Hanselmann | #: a required instance name (for single-instance LUs)
|
57 | 65e183af | Michael Hanselmann | _PInstanceName = ("instance_name", ht.NoDefault, ht.TNonEmptyString)
|
58 | 65e183af | Michael Hanselmann | |
59 | 65e183af | Michael Hanselmann | #: Whether to ignore offline nodes
|
60 | 65e183af | Michael Hanselmann | _PIgnoreOfflineNodes = ("ignore_offline_nodes", False, ht.TBool) |
61 | 65e183af | Michael Hanselmann | |
62 | 65e183af | Michael Hanselmann | #: a required node name (for single-node LUs)
|
63 | 65e183af | Michael Hanselmann | _PNodeName = ("node_name", ht.NoDefault, ht.TNonEmptyString)
|
64 | 65e183af | Michael Hanselmann | |
65 | 65e183af | Michael Hanselmann | #: a required node group name (for single-group LUs)
|
66 | 65e183af | Michael Hanselmann | _PGroupName = ("group_name", ht.NoDefault, ht.TNonEmptyString)
|
67 | 65e183af | Michael Hanselmann | |
68 | 65e183af | Michael Hanselmann | #: Migration type (live/non-live)
|
69 | 65e183af | Michael Hanselmann | _PMigrationMode = ("mode", None, |
70 | 65e183af | Michael Hanselmann | ht.TOr(ht.TNone, ht.TElemOf(constants.HT_MIGRATION_MODES))) |
71 | 65e183af | Michael Hanselmann | |
72 | 65e183af | Michael Hanselmann | #: Obsolete 'live' migration mode (boolean)
|
73 | 65e183af | Michael Hanselmann | _PMigrationLive = ("live", None, ht.TMaybeBool) |
74 | 65e183af | Michael Hanselmann | |
75 | 65e183af | Michael Hanselmann | #: Tag type
|
76 | 65e183af | Michael Hanselmann | _PTagKind = ("kind", ht.NoDefault, ht.TElemOf(constants.VALID_TAG_TYPES))
|
77 | 65e183af | Michael Hanselmann | |
78 | 65e183af | Michael Hanselmann | #: List of tag strings
|
79 | 65e183af | Michael Hanselmann | _PTags = ("tags", ht.NoDefault, ht.TListOf(ht.TNonEmptyString))
|
80 | 65e183af | Michael Hanselmann | |
81 | ff0d18e6 | Iustin Pop | #: OP_ID conversion regular expression
|
82 | ff0d18e6 | Iustin Pop | _OPID_RE = re.compile("([a-z])([A-Z])")
|
83 | ff0d18e6 | Iustin Pop | |
84 | ff0d18e6 | Iustin Pop | |
85 | ff0d18e6 | Iustin Pop | def _NameToId(name): |
86 | ff0d18e6 | Iustin Pop | """Convert an opcode class name to an OP_ID.
|
87 | ff0d18e6 | Iustin Pop |
|
88 | ff0d18e6 | Iustin Pop | @type name: string
|
89 | ff0d18e6 | Iustin Pop | @param name: the class name, as OpXxxYyy
|
90 | ff0d18e6 | Iustin Pop | @rtype: string
|
91 | ff0d18e6 | Iustin Pop | @return: the name in the OP_XXXX_YYYY format
|
92 | ff0d18e6 | Iustin Pop |
|
93 | ff0d18e6 | Iustin Pop | """
|
94 | ff0d18e6 | Iustin Pop | if not name.startswith("Op"): |
95 | ff0d18e6 | Iustin Pop | return None |
96 | ff0d18e6 | Iustin Pop | # Note: (?<=[a-z])(?=[A-Z]) would be ideal, since it wouldn't
|
97 | ff0d18e6 | Iustin Pop | # consume any input, and hence we would just have all the elements
|
98 | ff0d18e6 | Iustin Pop | # in the list, one by one; but it seems that split doesn't work on
|
99 | ff0d18e6 | Iustin Pop | # non-consuming input, hence we have to process the input string a
|
100 | ff0d18e6 | Iustin Pop | # bit
|
101 | ff0d18e6 | Iustin Pop | name = _OPID_RE.sub(r"\1,\2", name)
|
102 | ff0d18e6 | Iustin Pop | elems = name.split(",")
|
103 | ff0d18e6 | Iustin Pop | return "_".join(n.upper() for n in elems) |
104 | ff0d18e6 | Iustin Pop | |
105 | 65e183af | Michael Hanselmann | |
106 | 65e183af | Michael Hanselmann | def RequireFileStorage(): |
107 | 65e183af | Michael Hanselmann | """Checks that file storage is enabled.
|
108 | 65e183af | Michael Hanselmann |
|
109 | 65e183af | Michael Hanselmann | While it doesn't really fit into this module, L{utils} was deemed too large
|
110 | 65e183af | Michael Hanselmann | of a dependency to be imported for just one or two functions.
|
111 | 65e183af | Michael Hanselmann |
|
112 | 65e183af | Michael Hanselmann | @raise errors.OpPrereqError: when file storage is disabled
|
113 | 65e183af | Michael Hanselmann |
|
114 | 65e183af | Michael Hanselmann | """
|
115 | 65e183af | Michael Hanselmann | if not constants.ENABLE_FILE_STORAGE: |
116 | 65e183af | Michael Hanselmann | raise errors.OpPrereqError("File storage disabled at configure time", |
117 | 65e183af | Michael Hanselmann | errors.ECODE_INVAL) |
118 | 65e183af | Michael Hanselmann | |
119 | 65e183af | Michael Hanselmann | |
120 | 53197381 | Apollon Oikonomopoulos | def RequireSharedFileStorage(): |
121 | 53197381 | Apollon Oikonomopoulos | """Checks that shared file storage is enabled.
|
122 | 53197381 | Apollon Oikonomopoulos |
|
123 | 53197381 | Apollon Oikonomopoulos | While it doesn't really fit into this module, L{utils} was deemed too large
|
124 | 53197381 | Apollon Oikonomopoulos | of a dependency to be imported for just one or two functions.
|
125 | 53197381 | Apollon Oikonomopoulos |
|
126 | 53197381 | Apollon Oikonomopoulos | @raise errors.OpPrereqError: when shared file storage is disabled
|
127 | 53197381 | Apollon Oikonomopoulos |
|
128 | 53197381 | Apollon Oikonomopoulos | """
|
129 | 53197381 | Apollon Oikonomopoulos | if not constants.ENABLE_SHARED_FILE_STORAGE: |
130 | 53197381 | Apollon Oikonomopoulos | raise errors.OpPrereqError("Shared file storage disabled at" |
131 | 53197381 | Apollon Oikonomopoulos | " configure time", errors.ECODE_INVAL)
|
132 | 53197381 | Apollon Oikonomopoulos | |
133 | 53197381 | Apollon Oikonomopoulos | |
134 | 65e183af | Michael Hanselmann | def _CheckDiskTemplate(template): |
135 | 65e183af | Michael Hanselmann | """Ensure a given disk template is valid.
|
136 | 65e183af | Michael Hanselmann |
|
137 | 65e183af | Michael Hanselmann | """
|
138 | 65e183af | Michael Hanselmann | if template not in constants.DISK_TEMPLATES: |
139 | 65e183af | Michael Hanselmann | # Using str.join directly to avoid importing utils for CommaJoin
|
140 | 65e183af | Michael Hanselmann | msg = ("Invalid disk template name '%s', valid templates are: %s" %
|
141 | 65e183af | Michael Hanselmann | (template, ", ".join(constants.DISK_TEMPLATES)))
|
142 | 65e183af | Michael Hanselmann | raise errors.OpPrereqError(msg, errors.ECODE_INVAL)
|
143 | 65e183af | Michael Hanselmann | if template == constants.DT_FILE:
|
144 | 65e183af | Michael Hanselmann | RequireFileStorage() |
145 | 53197381 | Apollon Oikonomopoulos | elif template == constants.DT_SHARED_FILE:
|
146 | 53197381 | Apollon Oikonomopoulos | RequireSharedFileStorage() |
147 | 65e183af | Michael Hanselmann | return True |
148 | 65e183af | Michael Hanselmann | |
149 | 65e183af | Michael Hanselmann | |
150 | 65e183af | Michael Hanselmann | def _CheckStorageType(storage_type): |
151 | 65e183af | Michael Hanselmann | """Ensure a given storage type is valid.
|
152 | 65e183af | Michael Hanselmann |
|
153 | 65e183af | Michael Hanselmann | """
|
154 | 65e183af | Michael Hanselmann | if storage_type not in constants.VALID_STORAGE_TYPES: |
155 | 65e183af | Michael Hanselmann | raise errors.OpPrereqError("Unknown storage type: %s" % storage_type, |
156 | 65e183af | Michael Hanselmann | errors.ECODE_INVAL) |
157 | 65e183af | Michael Hanselmann | if storage_type == constants.ST_FILE:
|
158 | 65e183af | Michael Hanselmann | RequireFileStorage() |
159 | 65e183af | Michael Hanselmann | return True |
160 | 65e183af | Michael Hanselmann | |
161 | 65e183af | Michael Hanselmann | |
162 | 65e183af | Michael Hanselmann | #: Storage type parameter
|
163 | 65e183af | Michael Hanselmann | _PStorageType = ("storage_type", ht.NoDefault, _CheckStorageType)
|
164 | 65e183af | Michael Hanselmann | |
165 | 65e183af | Michael Hanselmann | |
166 | 65e183af | Michael Hanselmann | class _AutoOpParamSlots(type): |
167 | 65e183af | Michael Hanselmann | """Meta class for opcode definitions.
|
168 | 65e183af | Michael Hanselmann |
|
169 | 65e183af | Michael Hanselmann | """
|
170 | 65e183af | Michael Hanselmann | def __new__(mcs, name, bases, attrs): |
171 | 65e183af | Michael Hanselmann | """Called when a class should be created.
|
172 | 65e183af | Michael Hanselmann |
|
173 | 65e183af | Michael Hanselmann | @param mcs: The meta class
|
174 | 65e183af | Michael Hanselmann | @param name: Name of created class
|
175 | 65e183af | Michael Hanselmann | @param bases: Base classes
|
176 | 65e183af | Michael Hanselmann | @type attrs: dict
|
177 | 65e183af | Michael Hanselmann | @param attrs: Class attributes
|
178 | 65e183af | Michael Hanselmann |
|
179 | 65e183af | Michael Hanselmann | """
|
180 | 65e183af | Michael Hanselmann | assert "__slots__" not in attrs, \ |
181 | 65e183af | Michael Hanselmann | "Class '%s' defines __slots__ when it should use OP_PARAMS" % name
|
182 | e89a9021 | Iustin Pop | assert "OP_ID" not in attrs, "Class '%s' defining OP_ID" % name |
183 | ff0d18e6 | Iustin Pop | |
184 | e89a9021 | Iustin Pop | attrs["OP_ID"] = _NameToId(name)
|
185 | 65e183af | Michael Hanselmann | |
186 | 65e183af | Michael Hanselmann | # Always set OP_PARAMS to avoid duplicates in BaseOpCode.GetAllParams
|
187 | 65e183af | Michael Hanselmann | params = attrs.setdefault("OP_PARAMS", [])
|
188 | 65e183af | Michael Hanselmann | |
189 | 65e183af | Michael Hanselmann | # Use parameter names as slots
|
190 | 65e183af | Michael Hanselmann | slots = [pname for (pname, _, _) in params] |
191 | 65e183af | Michael Hanselmann | |
192 | 65e183af | Michael Hanselmann | assert "OP_DSC_FIELD" not in attrs or attrs["OP_DSC_FIELD"] in slots, \ |
193 | 65e183af | Michael Hanselmann | "Class '%s' uses unknown field in OP_DSC_FIELD" % name
|
194 | 65e183af | Michael Hanselmann | |
195 | 65e183af | Michael Hanselmann | attrs["__slots__"] = slots
|
196 | 65e183af | Michael Hanselmann | |
197 | 65e183af | Michael Hanselmann | return type.__new__(mcs, name, bases, attrs) |
198 | 65e183af | Michael Hanselmann | |
199 | df458e0b | Iustin Pop | |
200 | 0e46916d | Iustin Pop | class BaseOpCode(object): |
201 | df458e0b | Iustin Pop | """A simple serializable object.
|
202 | df458e0b | Iustin Pop |
|
203 | 0e46916d | Iustin Pop | This object serves as a parent class for OpCode without any custom
|
204 | 0e46916d | Iustin Pop | field handling.
|
205 | 0e46916d | Iustin Pop |
|
206 | df458e0b | Iustin Pop | """
|
207 | e89a9021 | Iustin Pop | # pylint: disable-msg=E1101
|
208 | e89a9021 | Iustin Pop | # as OP_ID is dynamically defined
|
209 | 65e183af | Michael Hanselmann | __metaclass__ = _AutoOpParamSlots |
210 | 65e183af | Michael Hanselmann | |
211 | a8083063 | Iustin Pop | def __init__(self, **kwargs): |
212 | a7399f66 | Iustin Pop | """Constructor for BaseOpCode.
|
213 | a7399f66 | Iustin Pop |
|
214 | a7399f66 | Iustin Pop | The constructor takes only keyword arguments and will set
|
215 | a7399f66 | Iustin Pop | attributes on this object based on the passed arguments. As such,
|
216 | a7399f66 | Iustin Pop | it means that you should not pass arguments which are not in the
|
217 | a7399f66 | Iustin Pop | __slots__ attribute for this class.
|
218 | a7399f66 | Iustin Pop |
|
219 | a7399f66 | Iustin Pop | """
|
220 | adf385c7 | Iustin Pop | slots = self._all_slots()
|
221 | a8083063 | Iustin Pop | for key in kwargs: |
222 | adf385c7 | Iustin Pop | if key not in slots: |
223 | df458e0b | Iustin Pop | raise TypeError("Object %s doesn't support the parameter '%s'" % |
224 | 3ecf6786 | Iustin Pop | (self.__class__.__name__, key))
|
225 | a8083063 | Iustin Pop | setattr(self, key, kwargs[key]) |
226 | a8083063 | Iustin Pop | |
227 | df458e0b | Iustin Pop | def __getstate__(self): |
228 | a7399f66 | Iustin Pop | """Generic serializer.
|
229 | a7399f66 | Iustin Pop |
|
230 | a7399f66 | Iustin Pop | This method just returns the contents of the instance as a
|
231 | a7399f66 | Iustin Pop | dictionary.
|
232 | a7399f66 | Iustin Pop |
|
233 | a7399f66 | Iustin Pop | @rtype: C{dict}
|
234 | a7399f66 | Iustin Pop | @return: the instance attributes and their values
|
235 | a7399f66 | Iustin Pop |
|
236 | a7399f66 | Iustin Pop | """
|
237 | df458e0b | Iustin Pop | state = {} |
238 | adf385c7 | Iustin Pop | for name in self._all_slots(): |
239 | df458e0b | Iustin Pop | if hasattr(self, name): |
240 | df458e0b | Iustin Pop | state[name] = getattr(self, name) |
241 | df458e0b | Iustin Pop | return state
|
242 | df458e0b | Iustin Pop | |
243 | df458e0b | Iustin Pop | def __setstate__(self, state): |
244 | a7399f66 | Iustin Pop | """Generic unserializer.
|
245 | a7399f66 | Iustin Pop |
|
246 | a7399f66 | Iustin Pop | This method just restores from the serialized state the attributes
|
247 | a7399f66 | Iustin Pop | of the current instance.
|
248 | a7399f66 | Iustin Pop |
|
249 | a7399f66 | Iustin Pop | @param state: the serialized opcode data
|
250 | a7399f66 | Iustin Pop | @type state: C{dict}
|
251 | a7399f66 | Iustin Pop |
|
252 | a7399f66 | Iustin Pop | """
|
253 | df458e0b | Iustin Pop | if not isinstance(state, dict): |
254 | df458e0b | Iustin Pop | raise ValueError("Invalid data to __setstate__: expected dict, got %s" % |
255 | df458e0b | Iustin Pop | type(state))
|
256 | df458e0b | Iustin Pop | |
257 | adf385c7 | Iustin Pop | for name in self._all_slots(): |
258 | 44db3a6f | Iustin Pop | if name not in state and hasattr(self, name): |
259 | df458e0b | Iustin Pop | delattr(self, name) |
260 | df458e0b | Iustin Pop | |
261 | df458e0b | Iustin Pop | for name in state: |
262 | df458e0b | Iustin Pop | setattr(self, name, state[name]) |
263 | df458e0b | Iustin Pop | |
264 | adf385c7 | Iustin Pop | @classmethod
|
265 | adf385c7 | Iustin Pop | def _all_slots(cls): |
266 | adf385c7 | Iustin Pop | """Compute the list of all declared slots for a class.
|
267 | adf385c7 | Iustin Pop |
|
268 | adf385c7 | Iustin Pop | """
|
269 | adf385c7 | Iustin Pop | slots = [] |
270 | adf385c7 | Iustin Pop | for parent in cls.__mro__: |
271 | adf385c7 | Iustin Pop | slots.extend(getattr(parent, "__slots__", [])) |
272 | adf385c7 | Iustin Pop | return slots
|
273 | adf385c7 | Iustin Pop | |
274 | 65e183af | Michael Hanselmann | @classmethod
|
275 | 65e183af | Michael Hanselmann | def GetAllParams(cls): |
276 | 65e183af | Michael Hanselmann | """Compute list of all parameters for an opcode.
|
277 | 65e183af | Michael Hanselmann |
|
278 | 65e183af | Michael Hanselmann | """
|
279 | 65e183af | Michael Hanselmann | slots = [] |
280 | 65e183af | Michael Hanselmann | for parent in cls.__mro__: |
281 | 65e183af | Michael Hanselmann | slots.extend(getattr(parent, "OP_PARAMS", [])) |
282 | 65e183af | Michael Hanselmann | return slots
|
283 | 65e183af | Michael Hanselmann | |
284 | 1cbef6d8 | Michael Hanselmann | def Validate(self, set_defaults): |
285 | 1cbef6d8 | Michael Hanselmann | """Validate opcode parameters, optionally setting default values.
|
286 | 1cbef6d8 | Michael Hanselmann |
|
287 | 1cbef6d8 | Michael Hanselmann | @type set_defaults: bool
|
288 | 1cbef6d8 | Michael Hanselmann | @param set_defaults: Whether to set default values
|
289 | 1cbef6d8 | Michael Hanselmann | @raise errors.OpPrereqError: When a parameter value doesn't match
|
290 | 1cbef6d8 | Michael Hanselmann | requirements
|
291 | 1cbef6d8 | Michael Hanselmann |
|
292 | 1cbef6d8 | Michael Hanselmann | """
|
293 | 1cbef6d8 | Michael Hanselmann | for (attr_name, default, test) in self.GetAllParams(): |
294 | 1cbef6d8 | Michael Hanselmann | assert test == ht.NoType or callable(test) |
295 | 1cbef6d8 | Michael Hanselmann | |
296 | 1cbef6d8 | Michael Hanselmann | if not hasattr(self, attr_name): |
297 | 1cbef6d8 | Michael Hanselmann | if default == ht.NoDefault:
|
298 | 1cbef6d8 | Michael Hanselmann | raise errors.OpPrereqError("Required parameter '%s.%s' missing" % |
299 | 1cbef6d8 | Michael Hanselmann | (self.OP_ID, attr_name),
|
300 | 1cbef6d8 | Michael Hanselmann | errors.ECODE_INVAL) |
301 | 1cbef6d8 | Michael Hanselmann | elif set_defaults:
|
302 | 1cbef6d8 | Michael Hanselmann | if callable(default): |
303 | 1cbef6d8 | Michael Hanselmann | dval = default() |
304 | 1cbef6d8 | Michael Hanselmann | else:
|
305 | 1cbef6d8 | Michael Hanselmann | dval = default |
306 | 1cbef6d8 | Michael Hanselmann | setattr(self, attr_name, dval) |
307 | 1cbef6d8 | Michael Hanselmann | |
308 | 1cbef6d8 | Michael Hanselmann | if test == ht.NoType:
|
309 | 1cbef6d8 | Michael Hanselmann | # no tests here
|
310 | 1cbef6d8 | Michael Hanselmann | continue
|
311 | 1cbef6d8 | Michael Hanselmann | |
312 | 1cbef6d8 | Michael Hanselmann | if set_defaults or hasattr(self, attr_name): |
313 | 1cbef6d8 | Michael Hanselmann | attr_val = getattr(self, attr_name) |
314 | 1cbef6d8 | Michael Hanselmann | if not test(attr_val): |
315 | 1cbef6d8 | Michael Hanselmann | logging.error("OpCode %s, parameter %s, has invalid type %s/value %s",
|
316 | 1cbef6d8 | Michael Hanselmann | self.OP_ID, attr_name, type(attr_val), attr_val) |
317 | 1cbef6d8 | Michael Hanselmann | raise errors.OpPrereqError("Parameter '%s.%s' fails validation" % |
318 | 1cbef6d8 | Michael Hanselmann | (self.OP_ID, attr_name),
|
319 | 1cbef6d8 | Michael Hanselmann | errors.ECODE_INVAL) |
320 | 1cbef6d8 | Michael Hanselmann | |
321 | df458e0b | Iustin Pop | |
322 | 0e46916d | Iustin Pop | class OpCode(BaseOpCode): |
323 | a7399f66 | Iustin Pop | """Abstract OpCode.
|
324 | a7399f66 | Iustin Pop |
|
325 | a7399f66 | Iustin Pop | This is the root of the actual OpCode hierarchy. All clases derived
|
326 | a7399f66 | Iustin Pop | from this class should override OP_ID.
|
327 | a7399f66 | Iustin Pop |
|
328 | a7399f66 | Iustin Pop | @cvar OP_ID: The ID of this opcode. This should be unique amongst all
|
329 | 20777413 | Iustin Pop | children of this class.
|
330 | bde8f481 | Adeodato Simo | @cvar OP_DSC_FIELD: The name of a field whose value will be included in the
|
331 | bde8f481 | Adeodato Simo | string returned by Summary(); see the docstring of that
|
332 | bde8f481 | Adeodato Simo | method for details).
|
333 | 65e183af | Michael Hanselmann | @cvar OP_PARAMS: List of opcode attributes, the default values they should
|
334 | 65e183af | Michael Hanselmann | get if not already defined, and types they must match.
|
335 | 687c10d9 | Iustin Pop | @cvar WITH_LU: Boolean that specifies whether this should be included in
|
336 | 687c10d9 | Iustin Pop | mcpu's dispatch table
|
337 | 20777413 | Iustin Pop | @ivar dry_run: Whether the LU should be run in dry-run mode, i.e. just
|
338 | 20777413 | Iustin Pop | the check steps
|
339 | 8f5c488d | Michael Hanselmann | @ivar priority: Opcode priority for queue
|
340 | a7399f66 | Iustin Pop |
|
341 | a7399f66 | Iustin Pop | """
|
342 | e89a9021 | Iustin Pop | # pylint: disable-msg=E1101
|
343 | e89a9021 | Iustin Pop | # as OP_ID is dynamically defined
|
344 | 687c10d9 | Iustin Pop | WITH_LU = True
|
345 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
346 | 65e183af | Michael Hanselmann | ("dry_run", None, ht.TMaybeBool), |
347 | 65e183af | Michael Hanselmann | ("debug_level", None, ht.TOr(ht.TNone, ht.TPositiveInt)), |
348 | 65e183af | Michael Hanselmann | ("priority", constants.OP_PRIO_DEFAULT,
|
349 | 65e183af | Michael Hanselmann | ht.TElemOf(constants.OP_PRIO_SUBMIT_VALID)), |
350 | 65e183af | Michael Hanselmann | ] |
351 | df458e0b | Iustin Pop | |
352 | df458e0b | Iustin Pop | def __getstate__(self): |
353 | df458e0b | Iustin Pop | """Specialized getstate for opcodes.
|
354 | df458e0b | Iustin Pop |
|
355 | a7399f66 | Iustin Pop | This method adds to the state dictionary the OP_ID of the class,
|
356 | a7399f66 | Iustin Pop | so that on unload we can identify the correct class for
|
357 | a7399f66 | Iustin Pop | instantiating the opcode.
|
358 | a7399f66 | Iustin Pop |
|
359 | a7399f66 | Iustin Pop | @rtype: C{dict}
|
360 | a7399f66 | Iustin Pop | @return: the state as a dictionary
|
361 | a7399f66 | Iustin Pop |
|
362 | df458e0b | Iustin Pop | """
|
363 | 0e46916d | Iustin Pop | data = BaseOpCode.__getstate__(self)
|
364 | df458e0b | Iustin Pop | data["OP_ID"] = self.OP_ID |
365 | df458e0b | Iustin Pop | return data
|
366 | df458e0b | Iustin Pop | |
367 | df458e0b | Iustin Pop | @classmethod
|
368 | 00abdc96 | Iustin Pop | def LoadOpCode(cls, data): |
369 | df458e0b | Iustin Pop | """Generic load opcode method.
|
370 | df458e0b | Iustin Pop |
|
371 | a7399f66 | Iustin Pop | The method identifies the correct opcode class from the dict-form
|
372 | a7399f66 | Iustin Pop | by looking for a OP_ID key, if this is not found, or its value is
|
373 | a7399f66 | Iustin Pop | not available in this module as a child of this class, we fail.
|
374 | a7399f66 | Iustin Pop |
|
375 | a7399f66 | Iustin Pop | @type data: C{dict}
|
376 | a7399f66 | Iustin Pop | @param data: the serialized opcode
|
377 | a7399f66 | Iustin Pop |
|
378 | df458e0b | Iustin Pop | """
|
379 | df458e0b | Iustin Pop | if not isinstance(data, dict): |
380 | df458e0b | Iustin Pop | raise ValueError("Invalid data to LoadOpCode (%s)" % type(data)) |
381 | df458e0b | Iustin Pop | if "OP_ID" not in data: |
382 | df458e0b | Iustin Pop | raise ValueError("Invalid data to LoadOpcode, missing OP_ID") |
383 | df458e0b | Iustin Pop | op_id = data["OP_ID"]
|
384 | df458e0b | Iustin Pop | op_class = None
|
385 | 363acb1e | Iustin Pop | if op_id in OP_MAPPING: |
386 | 363acb1e | Iustin Pop | op_class = OP_MAPPING[op_id] |
387 | 363acb1e | Iustin Pop | else:
|
388 | df458e0b | Iustin Pop | raise ValueError("Invalid data to LoadOpCode: OP_ID %s unsupported" % |
389 | df458e0b | Iustin Pop | op_id) |
390 | df458e0b | Iustin Pop | op = op_class() |
391 | df458e0b | Iustin Pop | new_data = data.copy() |
392 | df458e0b | Iustin Pop | del new_data["OP_ID"] |
393 | df458e0b | Iustin Pop | op.__setstate__(new_data) |
394 | df458e0b | Iustin Pop | return op
|
395 | df458e0b | Iustin Pop | |
396 | 60dd1473 | Iustin Pop | def Summary(self): |
397 | 60dd1473 | Iustin Pop | """Generates a summary description of this opcode.
|
398 | 60dd1473 | Iustin Pop |
|
399 | ff0d18e6 | Iustin Pop | The summary is the value of the OP_ID attribute (without the "OP_"
|
400 | ff0d18e6 | Iustin Pop | prefix), plus the value of the OP_DSC_FIELD attribute, if one was
|
401 | ff0d18e6 | Iustin Pop | defined; this field should allow to easily identify the operation
|
402 | ff0d18e6 | Iustin Pop | (for an instance creation job, e.g., it would be the instance
|
403 | ff0d18e6 | Iustin Pop | name).
|
404 | bde8f481 | Adeodato Simo |
|
405 | 60dd1473 | Iustin Pop | """
|
406 | ff0d18e6 | Iustin Pop | assert self.OP_ID is not None and len(self.OP_ID) > 3 |
407 | 60dd1473 | Iustin Pop | # all OP_ID start with OP_, we remove that
|
408 | 60dd1473 | Iustin Pop | txt = self.OP_ID[3:] |
409 | 60dd1473 | Iustin Pop | field_name = getattr(self, "OP_DSC_FIELD", None) |
410 | 60dd1473 | Iustin Pop | if field_name:
|
411 | 60dd1473 | Iustin Pop | field_value = getattr(self, field_name, None) |
412 | bc8bbda1 | Iustin Pop | if isinstance(field_value, (list, tuple)): |
413 | bc8bbda1 | Iustin Pop | field_value = ",".join(str(i) for i in field_value) |
414 | 60dd1473 | Iustin Pop | txt = "%s(%s)" % (txt, field_value)
|
415 | 60dd1473 | Iustin Pop | return txt
|
416 | 60dd1473 | Iustin Pop | |
417 | a8083063 | Iustin Pop | |
418 | afee0879 | Iustin Pop | # cluster opcodes
|
419 | afee0879 | Iustin Pop | |
420 | bc84ffa7 | Iustin Pop | class OpClusterPostInit(OpCode): |
421 | b5f5fae9 | Luca Bigliardi | """Post cluster initialization.
|
422 | b5f5fae9 | Luca Bigliardi |
|
423 | b5f5fae9 | Luca Bigliardi | This opcode does not touch the cluster at all. Its purpose is to run hooks
|
424 | b5f5fae9 | Luca Bigliardi | after the cluster has been initialized.
|
425 | b5f5fae9 | Luca Bigliardi |
|
426 | b5f5fae9 | Luca Bigliardi | """
|
427 | b5f5fae9 | Luca Bigliardi | |
428 | b5f5fae9 | Luca Bigliardi | |
429 | c6d43e9e | Iustin Pop | class OpClusterDestroy(OpCode): |
430 | a7399f66 | Iustin Pop | """Destroy the cluster.
|
431 | a7399f66 | Iustin Pop |
|
432 | a7399f66 | Iustin Pop | This opcode has no other parameters. All the state is irreversibly
|
433 | a7399f66 | Iustin Pop | lost after the execution of this opcode.
|
434 | a7399f66 | Iustin Pop |
|
435 | a7399f66 | Iustin Pop | """
|
436 | a8083063 | Iustin Pop | |
437 | a8083063 | Iustin Pop | |
438 | a2f7ab92 | Iustin Pop | class OpClusterQuery(OpCode): |
439 | fdc267f4 | Iustin Pop | """Query cluster information."""
|
440 | a8083063 | Iustin Pop | |
441 | a8083063 | Iustin Pop | |
442 | a3d32770 | Iustin Pop | class OpClusterVerify(OpCode): |
443 | a7399f66 | Iustin Pop | """Verify the cluster state.
|
444 | a7399f66 | Iustin Pop |
|
445 | a7399f66 | Iustin Pop | @type skip_checks: C{list}
|
446 | a7399f66 | Iustin Pop | @ivar skip_checks: steps to be skipped from the verify process; this
|
447 | a7399f66 | Iustin Pop | needs to be a subset of
|
448 | a7399f66 | Iustin Pop | L{constants.VERIFY_OPTIONAL_CHECKS}; currently
|
449 | a7399f66 | Iustin Pop | only L{constants.VERIFY_NPLUSONE_MEM} can be passed
|
450 | a7399f66 | Iustin Pop |
|
451 | a7399f66 | Iustin Pop | """
|
452 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
453 | 65e183af | Michael Hanselmann | ("skip_checks", ht.EmptyList,
|
454 | 65e183af | Michael Hanselmann | ht.TListOf(ht.TElemOf(constants.VERIFY_OPTIONAL_CHECKS))), |
455 | 65e183af | Michael Hanselmann | ("verbose", False, ht.TBool), |
456 | 65e183af | Michael Hanselmann | ("error_codes", False, ht.TBool), |
457 | 65e183af | Michael Hanselmann | ("debug_simulate_errors", False, ht.TBool), |
458 | 65e183af | Michael Hanselmann | ] |
459 | a8083063 | Iustin Pop | |
460 | a8083063 | Iustin Pop | |
461 | bd8210a7 | Iustin Pop | class OpClusterVerifyDisks(OpCode): |
462 | 150e978f | Iustin Pop | """Verify the cluster disks.
|
463 | 150e978f | Iustin Pop |
|
464 | 150e978f | Iustin Pop | Parameters: none
|
465 | 150e978f | Iustin Pop |
|
466 | 5188ab37 | Iustin Pop | Result: a tuple of four elements:
|
467 | 150e978f | Iustin Pop | - list of node names with bad data returned (unreachable, etc.)
|
468 | a7399f66 | Iustin Pop | - dict of node names with broken volume groups (values: error msg)
|
469 | 150e978f | Iustin Pop | - list of instances with degraded disks (that should be activated)
|
470 | b63ed789 | Iustin Pop | - dict of instances with missing logical volumes (values: (node, vol)
|
471 | b63ed789 | Iustin Pop | pairs with details about the missing volumes)
|
472 | 150e978f | Iustin Pop |
|
473 | b63ed789 | Iustin Pop | In normal operation, all lists should be empty. A non-empty instance
|
474 | b63ed789 | Iustin Pop | list (3rd element of the result) is still ok (errors were fixed) but
|
475 | b63ed789 | Iustin Pop | non-empty node list means some node is down, and probably there are
|
476 | b63ed789 | Iustin Pop | unfixable drbd errors.
|
477 | 150e978f | Iustin Pop |
|
478 | 150e978f | Iustin Pop | Note that only instances that are drbd-based are taken into
|
479 | 150e978f | Iustin Pop | consideration. This might need to be revisited in the future.
|
480 | 150e978f | Iustin Pop |
|
481 | 150e978f | Iustin Pop | """
|
482 | 150e978f | Iustin Pop | |
483 | 150e978f | Iustin Pop | |
484 | 5d01aca3 | Iustin Pop | class OpClusterRepairDiskSizes(OpCode): |
485 | 60975797 | Iustin Pop | """Verify the disk sizes of the instances and fixes configuration
|
486 | 60975797 | Iustin Pop | mimatches.
|
487 | 60975797 | Iustin Pop |
|
488 | 60975797 | Iustin Pop | Parameters: optional instances list, in case we want to restrict the
|
489 | 60975797 | Iustin Pop | checks to only a subset of the instances.
|
490 | 60975797 | Iustin Pop |
|
491 | 60975797 | Iustin Pop | Result: a list of tuples, (instance, disk, new-size) for changed
|
492 | 60975797 | Iustin Pop | configurations.
|
493 | 60975797 | Iustin Pop |
|
494 | 60975797 | Iustin Pop | In normal operation, the list should be empty.
|
495 | 60975797 | Iustin Pop |
|
496 | 60975797 | Iustin Pop | @type instances: list
|
497 | 60975797 | Iustin Pop | @ivar instances: the list of instances to check, or empty for all instances
|
498 | 60975797 | Iustin Pop |
|
499 | 60975797 | Iustin Pop | """
|
500 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
501 | 65e183af | Michael Hanselmann | ("instances", ht.EmptyList, ht.TListOf(ht.TNonEmptyString)),
|
502 | 65e183af | Michael Hanselmann | ] |
503 | 60975797 | Iustin Pop | |
504 | 60975797 | Iustin Pop | |
505 | 2f093ea0 | Iustin Pop | class OpClusterConfigQuery(OpCode): |
506 | ae5849b5 | Michael Hanselmann | """Query cluster configuration values."""
|
507 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
508 | 65e183af | Michael Hanselmann | _POutputFields |
509 | 65e183af | Michael Hanselmann | ] |
510 | a8083063 | Iustin Pop | |
511 | a8083063 | Iustin Pop | |
512 | e126df25 | Iustin Pop | class OpClusterRename(OpCode): |
513 | a7399f66 | Iustin Pop | """Rename the cluster.
|
514 | a7399f66 | Iustin Pop |
|
515 | a7399f66 | Iustin Pop | @type name: C{str}
|
516 | a7399f66 | Iustin Pop | @ivar name: The new name of the cluster. The name and/or the master IP
|
517 | a7399f66 | Iustin Pop | address will be changed to match the new name and its IP
|
518 | a7399f66 | Iustin Pop | address.
|
519 | a7399f66 | Iustin Pop |
|
520 | a7399f66 | Iustin Pop | """
|
521 | 60dd1473 | Iustin Pop | OP_DSC_FIELD = "name"
|
522 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
523 | 65e183af | Michael Hanselmann | ("name", ht.NoDefault, ht.TNonEmptyString),
|
524 | 65e183af | Michael Hanselmann | ] |
525 | 07bd8a51 | Iustin Pop | |
526 | 07bd8a51 | Iustin Pop | |
527 | a6682fdc | Iustin Pop | class OpClusterSetParams(OpCode): |
528 | a7399f66 | Iustin Pop | """Change the parameters of the cluster.
|
529 | a7399f66 | Iustin Pop |
|
530 | a7399f66 | Iustin Pop | @type vg_name: C{str} or C{None}
|
531 | a7399f66 | Iustin Pop | @ivar vg_name: The new volume group name or None to disable LVM usage.
|
532 | a7399f66 | Iustin Pop |
|
533 | a7399f66 | Iustin Pop | """
|
534 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
535 | 65e183af | Michael Hanselmann | ("vg_name", None, ht.TMaybeString), |
536 | 65e183af | Michael Hanselmann | ("enabled_hypervisors", None, |
537 | 65e183af | Michael Hanselmann | ht.TOr(ht.TAnd(ht.TListOf(ht.TElemOf(constants.HYPER_TYPES)), ht.TTrue), |
538 | 65e183af | Michael Hanselmann | ht.TNone)), |
539 | 65e183af | Michael Hanselmann | ("hvparams", None, ht.TOr(ht.TDictOf(ht.TNonEmptyString, ht.TDict), |
540 | 65e183af | Michael Hanselmann | ht.TNone)), |
541 | 65e183af | Michael Hanselmann | ("beparams", None, ht.TOr(ht.TDict, ht.TNone)), |
542 | 65e183af | Michael Hanselmann | ("os_hvp", None, ht.TOr(ht.TDictOf(ht.TNonEmptyString, ht.TDict), |
543 | 65e183af | Michael Hanselmann | ht.TNone)), |
544 | 65e183af | Michael Hanselmann | ("osparams", None, ht.TOr(ht.TDictOf(ht.TNonEmptyString, ht.TDict), |
545 | 65e183af | Michael Hanselmann | ht.TNone)), |
546 | 65e183af | Michael Hanselmann | ("candidate_pool_size", None, ht.TOr(ht.TStrictPositiveInt, ht.TNone)), |
547 | 65e183af | Michael Hanselmann | ("uid_pool", None, ht.NoType), |
548 | 65e183af | Michael Hanselmann | ("add_uids", None, ht.NoType), |
549 | 65e183af | Michael Hanselmann | ("remove_uids", None, ht.NoType), |
550 | 65e183af | Michael Hanselmann | ("maintain_node_health", None, ht.TMaybeBool), |
551 | 65e183af | Michael Hanselmann | ("prealloc_wipe_disks", None, ht.TMaybeBool), |
552 | 5f074973 | Michael Hanselmann | ("nicparams", None, ht.TMaybeDict), |
553 | 5f074973 | Michael Hanselmann | ("ndparams", None, ht.TMaybeDict), |
554 | 65e183af | Michael Hanselmann | ("drbd_helper", None, ht.TOr(ht.TString, ht.TNone)), |
555 | 65e183af | Michael Hanselmann | ("default_iallocator", None, ht.TOr(ht.TString, ht.TNone)), |
556 | 65e183af | Michael Hanselmann | ("master_netdev", None, ht.TOr(ht.TString, ht.TNone)), |
557 | 65e183af | Michael Hanselmann | ("reserved_lvs", None, ht.TOr(ht.TListOf(ht.TNonEmptyString), ht.TNone)), |
558 | 65e183af | Michael Hanselmann | ("hidden_os", None, ht.TOr(ht.TListOf( |
559 | 65e183af | Michael Hanselmann | ht.TAnd(ht.TList, |
560 | 65e183af | Michael Hanselmann | ht.TIsLength(2),
|
561 | 65e183af | Michael Hanselmann | ht.TMap(lambda v: v[0], ht.TElemOf(constants.DDMS_VALUES)))), |
562 | 65e183af | Michael Hanselmann | ht.TNone)), |
563 | 65e183af | Michael Hanselmann | ("blacklisted_os", None, ht.TOr(ht.TListOf( |
564 | 65e183af | Michael Hanselmann | ht.TAnd(ht.TList, |
565 | 65e183af | Michael Hanselmann | ht.TIsLength(2),
|
566 | 65e183af | Michael Hanselmann | ht.TMap(lambda v: v[0], ht.TElemOf(constants.DDMS_VALUES)))), |
567 | 65e183af | Michael Hanselmann | ht.TNone)), |
568 | 4b7735f9 | Iustin Pop | ] |
569 | 12515db7 | Manuel Franceschini | |
570 | 12515db7 | Manuel Franceschini | |
571 | d1240007 | Iustin Pop | class OpClusterRedistConf(OpCode): |
572 | afee0879 | Iustin Pop | """Force a full push of the cluster configuration.
|
573 | afee0879 | Iustin Pop |
|
574 | afee0879 | Iustin Pop | """
|
575 | afee0879 | Iustin Pop | |
576 | 83f72637 | Michael Hanselmann | |
577 | 83f72637 | Michael Hanselmann | class OpQuery(OpCode): |
578 | 83f72637 | Michael Hanselmann | """Query for resources/items.
|
579 | 83f72637 | Michael Hanselmann |
|
580 | 83f72637 | Michael Hanselmann | @ivar what: Resources to query for, must be one of L{constants.QR_OP_QUERY}
|
581 | 83f72637 | Michael Hanselmann | @ivar fields: List of fields to retrieve
|
582 | 83f72637 | Michael Hanselmann | @ivar filter: Query filter
|
583 | 83f72637 | Michael Hanselmann |
|
584 | 83f72637 | Michael Hanselmann | """
|
585 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
586 | 65e183af | Michael Hanselmann | ("what", ht.NoDefault, ht.TElemOf(constants.QR_OP_QUERY)),
|
587 | 65e183af | Michael Hanselmann | ("fields", ht.NoDefault, ht.TListOf(ht.TNonEmptyString)),
|
588 | 65e183af | Michael Hanselmann | ("filter", None, ht.TOr(ht.TNone, |
589 | 65e183af | Michael Hanselmann | ht.TListOf(ht.TOr(ht.TNonEmptyString, ht.TList)))), |
590 | 83f72637 | Michael Hanselmann | ] |
591 | 83f72637 | Michael Hanselmann | |
592 | 83f72637 | Michael Hanselmann | |
593 | 83f72637 | Michael Hanselmann | class OpQueryFields(OpCode): |
594 | 83f72637 | Michael Hanselmann | """Query for available resource/item fields.
|
595 | 83f72637 | Michael Hanselmann |
|
596 | 83f72637 | Michael Hanselmann | @ivar what: Resources to query for, must be one of L{constants.QR_OP_QUERY}
|
597 | 83f72637 | Michael Hanselmann | @ivar fields: List of fields to retrieve
|
598 | 83f72637 | Michael Hanselmann |
|
599 | 83f72637 | Michael Hanselmann | """
|
600 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
601 | 65e183af | Michael Hanselmann | ("what", ht.NoDefault, ht.TElemOf(constants.QR_OP_QUERY)),
|
602 | 65e183af | Michael Hanselmann | ("fields", None, ht.TOr(ht.TNone, ht.TListOf(ht.TNonEmptyString))), |
603 | 83f72637 | Michael Hanselmann | ] |
604 | 83f72637 | Michael Hanselmann | |
605 | 83f72637 | Michael Hanselmann | |
606 | 792af3ad | Renรฉ Nussbaumer | class OpOobCommand(OpCode): |
607 | eb64da59 | Renรฉ Nussbaumer | """Interact with OOB."""
|
608 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
609 | b04808ea | Renรฉ Nussbaumer | ("node_names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString)),
|
610 | 65e183af | Michael Hanselmann | ("command", None, ht.TElemOf(constants.OOB_COMMANDS)), |
611 | 65e183af | Michael Hanselmann | ("timeout", constants.OOB_TIMEOUT, ht.TInt),
|
612 | eb64da59 | Renรฉ Nussbaumer | ] |
613 | eb64da59 | Renรฉ Nussbaumer | |
614 | eb64da59 | Renรฉ Nussbaumer | |
615 | 07bd8a51 | Iustin Pop | # node opcodes
|
616 | 07bd8a51 | Iustin Pop | |
617 | 73d565a3 | Iustin Pop | class OpNodeRemove(OpCode): |
618 | a7399f66 | Iustin Pop | """Remove a node.
|
619 | a7399f66 | Iustin Pop |
|
620 | a7399f66 | Iustin Pop | @type node_name: C{str}
|
621 | a7399f66 | Iustin Pop | @ivar node_name: The name of the node to remove. If the node still has
|
622 | a7399f66 | Iustin Pop | instances on it, the operation will fail.
|
623 | a7399f66 | Iustin Pop |
|
624 | a7399f66 | Iustin Pop | """
|
625 | 60dd1473 | Iustin Pop | OP_DSC_FIELD = "node_name"
|
626 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
627 | 65e183af | Michael Hanselmann | _PNodeName, |
628 | 65e183af | Michael Hanselmann | ] |
629 | a8083063 | Iustin Pop | |
630 | a8083063 | Iustin Pop | |
631 | d817d49f | Iustin Pop | class OpNodeAdd(OpCode): |
632 | a7399f66 | Iustin Pop | """Add a node to the cluster.
|
633 | a7399f66 | Iustin Pop |
|
634 | a7399f66 | Iustin Pop | @type node_name: C{str}
|
635 | a7399f66 | Iustin Pop | @ivar node_name: The name of the node to add. This can be a short name,
|
636 | a7399f66 | Iustin Pop | but it will be expanded to the FQDN.
|
637 | a7399f66 | Iustin Pop | @type primary_ip: IP address
|
638 | a7399f66 | Iustin Pop | @ivar primary_ip: The primary IP of the node. This will be ignored when the
|
639 | a7399f66 | Iustin Pop | opcode is submitted, but will be filled during the node
|
640 | a7399f66 | Iustin Pop | add (so it will be visible in the job query).
|
641 | a7399f66 | Iustin Pop | @type secondary_ip: IP address
|
642 | a7399f66 | Iustin Pop | @ivar secondary_ip: The secondary IP of the node. This needs to be passed
|
643 | a7399f66 | Iustin Pop | if the cluster has been initialized in 'dual-network'
|
644 | a7399f66 | Iustin Pop | mode, otherwise it must not be given.
|
645 | a7399f66 | Iustin Pop | @type readd: C{bool}
|
646 | a7399f66 | Iustin Pop | @ivar readd: Whether to re-add an existing node to the cluster. If
|
647 | a7399f66 | Iustin Pop | this is not passed, then the operation will abort if the node
|
648 | a7399f66 | Iustin Pop | name is already in the cluster; use this parameter to 'repair'
|
649 | a7399f66 | Iustin Pop | a node that had its configuration broken, or was reinstalled
|
650 | a7399f66 | Iustin Pop | without removal from the cluster.
|
651 | f936c153 | Iustin Pop | @type group: C{str}
|
652 | f936c153 | Iustin Pop | @ivar group: The node group to which this node will belong.
|
653 | fd3d37b6 | Iustin Pop | @type vm_capable: C{bool}
|
654 | fd3d37b6 | Iustin Pop | @ivar vm_capable: The vm_capable node attribute
|
655 | fd3d37b6 | Iustin Pop | @type master_capable: C{bool}
|
656 | fd3d37b6 | Iustin Pop | @ivar master_capable: The master_capable node attribute
|
657 | a7399f66 | Iustin Pop |
|
658 | a7399f66 | Iustin Pop | """
|
659 | 60dd1473 | Iustin Pop | OP_DSC_FIELD = "node_name"
|
660 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
661 | 65e183af | Michael Hanselmann | _PNodeName, |
662 | 65e183af | Michael Hanselmann | ("primary_ip", None, ht.NoType), |
663 | 65e183af | Michael Hanselmann | ("secondary_ip", None, ht.TMaybeString), |
664 | 65e183af | Michael Hanselmann | ("readd", False, ht.TBool), |
665 | 65e183af | Michael Hanselmann | ("group", None, ht.TMaybeString), |
666 | 65e183af | Michael Hanselmann | ("master_capable", None, ht.TMaybeBool), |
667 | 65e183af | Michael Hanselmann | ("vm_capable", None, ht.TMaybeBool), |
668 | 5f074973 | Michael Hanselmann | ("ndparams", None, ht.TMaybeDict), |
669 | 65e183af | Michael Hanselmann | ] |
670 | a8083063 | Iustin Pop | |
671 | a8083063 | Iustin Pop | |
672 | 2237687b | Iustin Pop | class OpNodeQuery(OpCode): |
673 | a8083063 | Iustin Pop | """Compute the list of nodes."""
|
674 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
675 | 65e183af | Michael Hanselmann | _POutputFields, |
676 | 65e183af | Michael Hanselmann | ("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString)),
|
677 | 65e183af | Michael Hanselmann | ("use_locking", False, ht.TBool), |
678 | 65e183af | Michael Hanselmann | ] |
679 | a8083063 | Iustin Pop | |
680 | a8083063 | Iustin Pop | |
681 | 8ed55bfd | Iustin Pop | class OpNodeQueryvols(OpCode): |
682 | dcb93971 | Michael Hanselmann | """Get list of volumes on node."""
|
683 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
684 | 65e183af | Michael Hanselmann | _POutputFields, |
685 | 65e183af | Michael Hanselmann | ("nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString)),
|
686 | 65e183af | Michael Hanselmann | ] |
687 | dcb93971 | Michael Hanselmann | |
688 | dcb93971 | Michael Hanselmann | |
689 | ad8d0595 | Iustin Pop | class OpNodeQueryStorage(OpCode): |
690 | 9e5442ce | Michael Hanselmann | """Get information on storage for node(s)."""
|
691 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
692 | 65e183af | Michael Hanselmann | _POutputFields, |
693 | 65e183af | Michael Hanselmann | _PStorageType, |
694 | 65e183af | Michael Hanselmann | ("nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString)),
|
695 | 65e183af | Michael Hanselmann | ("name", None, ht.TMaybeString), |
696 | 9e5442ce | Michael Hanselmann | ] |
697 | 9e5442ce | Michael Hanselmann | |
698 | 9e5442ce | Michael Hanselmann | |
699 | 2cee4077 | Iustin Pop | class OpNodeModifyStorage(OpCode): |
700 | 099c52ad | Iustin Pop | """Modifies the properies of a storage unit"""
|
701 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
702 | 65e183af | Michael Hanselmann | _PNodeName, |
703 | 65e183af | Michael Hanselmann | _PStorageType, |
704 | 65e183af | Michael Hanselmann | ("name", ht.NoDefault, ht.TNonEmptyString),
|
705 | 65e183af | Michael Hanselmann | ("changes", ht.NoDefault, ht.TDict),
|
706 | efb8da02 | Michael Hanselmann | ] |
707 | efb8da02 | Michael Hanselmann | |
708 | efb8da02 | Michael Hanselmann | |
709 | 76aef8fc | Michael Hanselmann | class OpRepairNodeStorage(OpCode): |
710 | 76aef8fc | Michael Hanselmann | """Repairs the volume group on a node."""
|
711 | 76aef8fc | Michael Hanselmann | OP_DSC_FIELD = "node_name"
|
712 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
713 | 65e183af | Michael Hanselmann | _PNodeName, |
714 | 65e183af | Michael Hanselmann | _PStorageType, |
715 | 65e183af | Michael Hanselmann | ("name", ht.NoDefault, ht.TNonEmptyString),
|
716 | 65e183af | Michael Hanselmann | ("ignore_consistency", False, ht.TBool), |
717 | 76aef8fc | Michael Hanselmann | ] |
718 | 76aef8fc | Michael Hanselmann | |
719 | 76aef8fc | Michael Hanselmann | |
720 | f13973c4 | Iustin Pop | class OpNodeSetParams(OpCode): |
721 | b31c8676 | Iustin Pop | """Change the parameters of a node."""
|
722 | b31c8676 | Iustin Pop | OP_DSC_FIELD = "node_name"
|
723 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
724 | 65e183af | Michael Hanselmann | _PNodeName, |
725 | 65e183af | Michael Hanselmann | _PForce, |
726 | 65e183af | Michael Hanselmann | ("master_candidate", None, ht.TMaybeBool), |
727 | 65e183af | Michael Hanselmann | ("offline", None, ht.TMaybeBool), |
728 | 65e183af | Michael Hanselmann | ("drained", None, ht.TMaybeBool), |
729 | 65e183af | Michael Hanselmann | ("auto_promote", False, ht.TBool), |
730 | 65e183af | Michael Hanselmann | ("master_capable", None, ht.TMaybeBool), |
731 | 65e183af | Michael Hanselmann | ("vm_capable", None, ht.TMaybeBool), |
732 | 65e183af | Michael Hanselmann | ("secondary_ip", None, ht.TMaybeString), |
733 | 5f074973 | Michael Hanselmann | ("ndparams", None, ht.TMaybeDict), |
734 | 65e183af | Michael Hanselmann | ("powered", None, ht.TMaybeBool), |
735 | b31c8676 | Iustin Pop | ] |
736 | b31c8676 | Iustin Pop | |
737 | f5118ade | Iustin Pop | |
738 | e0d4735f | Iustin Pop | class OpNodePowercycle(OpCode): |
739 | f5118ade | Iustin Pop | """Tries to powercycle a node."""
|
740 | f5118ade | Iustin Pop | OP_DSC_FIELD = "node_name"
|
741 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
742 | 65e183af | Michael Hanselmann | _PNodeName, |
743 | 65e183af | Michael Hanselmann | _PForce, |
744 | f5118ade | Iustin Pop | ] |
745 | f5118ade | Iustin Pop | |
746 | 7ffc5a86 | Michael Hanselmann | |
747 | 5b14a488 | Iustin Pop | class OpNodeMigrate(OpCode): |
748 | 80cb875c | Michael Hanselmann | """Migrate all instances from a node."""
|
749 | 80cb875c | Michael Hanselmann | OP_DSC_FIELD = "node_name"
|
750 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
751 | 65e183af | Michael Hanselmann | _PNodeName, |
752 | 65e183af | Michael Hanselmann | _PMigrationMode, |
753 | 65e183af | Michael Hanselmann | _PMigrationLive, |
754 | 36a072e8 | Apollon Oikonomopoulos | ("iallocator", None, ht.TMaybeString), |
755 | 80cb875c | Michael Hanselmann | ] |
756 | 80cb875c | Michael Hanselmann | |
757 | 80cb875c | Michael Hanselmann | |
758 | 0ae89533 | Iustin Pop | class OpNodeEvacStrategy(OpCode): |
759 | d6aaa598 | Iustin Pop | """Compute the evacuation strategy for a list of nodes."""
|
760 | d6aaa598 | Iustin Pop | OP_DSC_FIELD = "nodes"
|
761 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
762 | 65e183af | Michael Hanselmann | ("nodes", ht.NoDefault, ht.TListOf(ht.TNonEmptyString)),
|
763 | 65e183af | Michael Hanselmann | ("remote_node", None, ht.TMaybeString), |
764 | 65e183af | Michael Hanselmann | ("iallocator", None, ht.TMaybeString), |
765 | 65e183af | Michael Hanselmann | ] |
766 | d6aaa598 | Iustin Pop | |
767 | d6aaa598 | Iustin Pop | |
768 | a8083063 | Iustin Pop | # instance opcodes
|
769 | a8083063 | Iustin Pop | |
770 | e1530b10 | Iustin Pop | class OpInstanceCreate(OpCode): |
771 | 9bf56d77 | Michael Hanselmann | """Create an instance.
|
772 | 9bf56d77 | Michael Hanselmann |
|
773 | 9bf56d77 | Michael Hanselmann | @ivar instance_name: Instance name
|
774 | 9bf56d77 | Michael Hanselmann | @ivar mode: Instance creation mode (one of L{constants.INSTANCE_CREATE_MODES})
|
775 | 9bf56d77 | Michael Hanselmann | @ivar source_handshake: Signed handshake from source (remote import only)
|
776 | 9bf56d77 | Michael Hanselmann | @ivar source_x509_ca: Source X509 CA in PEM format (remote import only)
|
777 | 9bf56d77 | Michael Hanselmann | @ivar source_instance_name: Previous name of instance (remote import only)
|
778 | dae91d02 | Michael Hanselmann | @ivar source_shutdown_timeout: Shutdown timeout used for source instance
|
779 | dae91d02 | Michael Hanselmann | (remote import only)
|
780 | 9bf56d77 | Michael Hanselmann |
|
781 | 9bf56d77 | Michael Hanselmann | """
|
782 | 60dd1473 | Iustin Pop | OP_DSC_FIELD = "instance_name"
|
783 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
784 | 65e183af | Michael Hanselmann | _PInstanceName, |
785 | 65e183af | Michael Hanselmann | ("beparams", ht.EmptyDict, ht.TDict),
|
786 | 65e183af | Michael Hanselmann | ("disks", ht.NoDefault, ht.TListOf(ht.TDict)),
|
787 | 65e183af | Michael Hanselmann | ("disk_template", ht.NoDefault, _CheckDiskTemplate),
|
788 | 65e183af | Michael Hanselmann | ("file_driver", None, ht.TOr(ht.TNone, ht.TElemOf(constants.FILE_DRIVER))), |
789 | 65e183af | Michael Hanselmann | ("file_storage_dir", None, ht.TMaybeString), |
790 | 65e183af | Michael Hanselmann | ("force_variant", False, ht.TBool), |
791 | 65e183af | Michael Hanselmann | ("hvparams", ht.EmptyDict, ht.TDict),
|
792 | 65e183af | Michael Hanselmann | ("hypervisor", None, ht.TMaybeString), |
793 | 65e183af | Michael Hanselmann | ("iallocator", None, ht.TMaybeString), |
794 | 65e183af | Michael Hanselmann | ("identify_defaults", False, ht.TBool), |
795 | 65e183af | Michael Hanselmann | ("ip_check", True, ht.TBool), |
796 | 65e183af | Michael Hanselmann | ("mode", ht.NoDefault, ht.TElemOf(constants.INSTANCE_CREATE_MODES)),
|
797 | 65e183af | Michael Hanselmann | ("name_check", True, ht.TBool), |
798 | 65e183af | Michael Hanselmann | ("nics", ht.NoDefault, ht.TListOf(ht.TDict)),
|
799 | 65e183af | Michael Hanselmann | ("no_install", None, ht.TMaybeBool), |
800 | 65e183af | Michael Hanselmann | ("osparams", ht.EmptyDict, ht.TDict),
|
801 | 65e183af | Michael Hanselmann | ("os_type", None, ht.TMaybeString), |
802 | 65e183af | Michael Hanselmann | ("pnode", None, ht.TMaybeString), |
803 | 65e183af | Michael Hanselmann | ("snode", None, ht.TMaybeString), |
804 | 65e183af | Michael Hanselmann | ("source_handshake", None, ht.TOr(ht.TList, ht.TNone)), |
805 | 65e183af | Michael Hanselmann | ("source_instance_name", None, ht.TMaybeString), |
806 | 65e183af | Michael Hanselmann | ("source_shutdown_timeout", constants.DEFAULT_SHUTDOWN_TIMEOUT,
|
807 | 65e183af | Michael Hanselmann | ht.TPositiveInt), |
808 | 65e183af | Michael Hanselmann | ("source_x509_ca", None, ht.TMaybeString), |
809 | 65e183af | Michael Hanselmann | ("src_node", None, ht.TMaybeString), |
810 | 65e183af | Michael Hanselmann | ("src_path", None, ht.TMaybeString), |
811 | 65e183af | Michael Hanselmann | ("start", True, ht.TBool), |
812 | 65e183af | Michael Hanselmann | ("wait_for_sync", True, ht.TBool), |
813 | 3b6d8c9b | Iustin Pop | ] |
814 | a8083063 | Iustin Pop | |
815 | a8083063 | Iustin Pop | |
816 | 5073fd8f | Iustin Pop | class OpInstanceReinstall(OpCode): |
817 | fdc267f4 | Iustin Pop | """Reinstall an instance's OS."""
|
818 | 60dd1473 | Iustin Pop | OP_DSC_FIELD = "instance_name"
|
819 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
820 | 65e183af | Michael Hanselmann | _PInstanceName, |
821 | 65e183af | Michael Hanselmann | ("os_type", None, ht.TMaybeString), |
822 | 65e183af | Michael Hanselmann | ("force_variant", False, ht.TBool), |
823 | 5f074973 | Michael Hanselmann | ("osparams", None, ht.TMaybeDict), |
824 | 65e183af | Michael Hanselmann | ] |
825 | fe7b0351 | Michael Hanselmann | |
826 | fe7b0351 | Michael Hanselmann | |
827 | 3cd2d4b1 | Iustin Pop | class OpInstanceRemove(OpCode): |
828 | a8083063 | Iustin Pop | """Remove an instance."""
|
829 | 60dd1473 | Iustin Pop | OP_DSC_FIELD = "instance_name"
|
830 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
831 | 65e183af | Michael Hanselmann | _PInstanceName, |
832 | 65e183af | Michael Hanselmann | _PShutdownTimeout, |
833 | 65e183af | Michael Hanselmann | ("ignore_failures", False, ht.TBool), |
834 | fc1baca9 | Michael Hanselmann | ] |
835 | a8083063 | Iustin Pop | |
836 | a8083063 | Iustin Pop | |
837 | 5659e2e2 | Iustin Pop | class OpInstanceRename(OpCode): |
838 | decd5f45 | Iustin Pop | """Rename an instance."""
|
839 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
840 | 65e183af | Michael Hanselmann | _PInstanceName, |
841 | 65e183af | Michael Hanselmann | ("new_name", ht.NoDefault, ht.TNonEmptyString),
|
842 | 65e183af | Michael Hanselmann | ("ip_check", False, ht.TBool), |
843 | 65e183af | Michael Hanselmann | ("name_check", True, ht.TBool), |
844 | 4f05fd3b | Iustin Pop | ] |
845 | decd5f45 | Iustin Pop | |
846 | decd5f45 | Iustin Pop | |
847 | c873d91c | Iustin Pop | class OpInstanceStartup(OpCode): |
848 | fdc267f4 | Iustin Pop | """Startup an instance."""
|
849 | 60dd1473 | Iustin Pop | OP_DSC_FIELD = "instance_name"
|
850 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
851 | 65e183af | Michael Hanselmann | _PInstanceName, |
852 | 65e183af | Michael Hanselmann | _PForce, |
853 | 65e183af | Michael Hanselmann | _PIgnoreOfflineNodes, |
854 | 65e183af | Michael Hanselmann | ("hvparams", ht.EmptyDict, ht.TDict),
|
855 | 65e183af | Michael Hanselmann | ("beparams", ht.EmptyDict, ht.TDict),
|
856 | 4f05fd3b | Iustin Pop | ] |
857 | a8083063 | Iustin Pop | |
858 | a8083063 | Iustin Pop | |
859 | ee3e37a7 | Iustin Pop | class OpInstanceShutdown(OpCode): |
860 | fdc267f4 | Iustin Pop | """Shutdown an instance."""
|
861 | 60dd1473 | Iustin Pop | OP_DSC_FIELD = "instance_name"
|
862 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
863 | 65e183af | Michael Hanselmann | _PInstanceName, |
864 | 65e183af | Michael Hanselmann | _PIgnoreOfflineNodes, |
865 | 65e183af | Michael Hanselmann | ("timeout", constants.DEFAULT_SHUTDOWN_TIMEOUT, ht.TPositiveInt),
|
866 | b44bd844 | Michael Hanselmann | ] |
867 | a8083063 | Iustin Pop | |
868 | a8083063 | Iustin Pop | |
869 | 90ab1a95 | Iustin Pop | class OpInstanceReboot(OpCode): |
870 | bf6929a2 | Alexander Schreiber | """Reboot an instance."""
|
871 | 60dd1473 | Iustin Pop | OP_DSC_FIELD = "instance_name"
|
872 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
873 | 65e183af | Michael Hanselmann | _PInstanceName, |
874 | 65e183af | Michael Hanselmann | _PShutdownTimeout, |
875 | 65e183af | Michael Hanselmann | ("ignore_secondaries", False, ht.TBool), |
876 | 65e183af | Michael Hanselmann | ("reboot_type", ht.NoDefault, ht.TElemOf(constants.REBOOT_TYPES)),
|
877 | 4f05fd3b | Iustin Pop | ] |
878 | bf6929a2 | Alexander Schreiber | |
879 | bf6929a2 | Alexander Schreiber | |
880 | 668f755d | Iustin Pop | class OpInstanceReplaceDisks(OpCode): |
881 | fdc267f4 | Iustin Pop | """Replace the disks of an instance."""
|
882 | 60dd1473 | Iustin Pop | OP_DSC_FIELD = "instance_name"
|
883 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
884 | 65e183af | Michael Hanselmann | _PInstanceName, |
885 | 65e183af | Michael Hanselmann | ("mode", ht.NoDefault, ht.TElemOf(constants.REPLACE_MODES)),
|
886 | 65e183af | Michael Hanselmann | ("disks", ht.EmptyList, ht.TListOf(ht.TPositiveInt)),
|
887 | 65e183af | Michael Hanselmann | ("remote_node", None, ht.TMaybeString), |
888 | 65e183af | Michael Hanselmann | ("iallocator", None, ht.TMaybeString), |
889 | 65e183af | Michael Hanselmann | ("early_release", False, ht.TBool), |
890 | 4f05fd3b | Iustin Pop | ] |
891 | a8083063 | Iustin Pop | |
892 | a8083063 | Iustin Pop | |
893 | 019dbee1 | Iustin Pop | class OpInstanceFailover(OpCode): |
894 | a8083063 | Iustin Pop | """Failover an instance."""
|
895 | 60dd1473 | Iustin Pop | OP_DSC_FIELD = "instance_name"
|
896 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
897 | 65e183af | Michael Hanselmann | _PInstanceName, |
898 | 65e183af | Michael Hanselmann | _PShutdownTimeout, |
899 | 65e183af | Michael Hanselmann | ("ignore_consistency", False, ht.TBool), |
900 | 36a072e8 | Apollon Oikonomopoulos | ("iallocator", None, ht.TMaybeString), |
901 | 36a072e8 | Apollon Oikonomopoulos | ("target_node", None, ht.TMaybeString), |
902 | 17c3f802 | Guido Trotter | ] |
903 | a8083063 | Iustin Pop | |
904 | a8083063 | Iustin Pop | |
905 | 75c866c2 | Iustin Pop | class OpInstanceMigrate(OpCode): |
906 | 53c776b5 | Iustin Pop | """Migrate an instance.
|
907 | 53c776b5 | Iustin Pop |
|
908 | 53c776b5 | Iustin Pop | This migrates (without shutting down an instance) to its secondary
|
909 | 53c776b5 | Iustin Pop | node.
|
910 | 53c776b5 | Iustin Pop |
|
911 | 2f907a8c | Iustin Pop | @ivar instance_name: the name of the instance
|
912 | 8c35561f | Iustin Pop | @ivar mode: the migration mode (live, non-live or None for auto)
|
913 | 53c776b5 | Iustin Pop |
|
914 | 53c776b5 | Iustin Pop | """
|
915 | ee69c97f | Iustin Pop | OP_DSC_FIELD = "instance_name"
|
916 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
917 | 65e183af | Michael Hanselmann | _PInstanceName, |
918 | 65e183af | Michael Hanselmann | _PMigrationMode, |
919 | 65e183af | Michael Hanselmann | _PMigrationLive, |
920 | 65e183af | Michael Hanselmann | ("cleanup", False, ht.TBool), |
921 | 36a072e8 | Apollon Oikonomopoulos | ("iallocator", None, ht.TMaybeString), |
922 | 36a072e8 | Apollon Oikonomopoulos | ("target_node", None, ht.TMaybeString), |
923 | 65e183af | Michael Hanselmann | ] |
924 | 53c776b5 | Iustin Pop | |
925 | 53c776b5 | Iustin Pop | |
926 | 0091b480 | Iustin Pop | class OpInstanceMove(OpCode): |
927 | 313bcead | Iustin Pop | """Move an instance.
|
928 | 313bcead | Iustin Pop |
|
929 | 313bcead | Iustin Pop | This move (with shutting down an instance and data copying) to an
|
930 | 313bcead | Iustin Pop | arbitrary node.
|
931 | 313bcead | Iustin Pop |
|
932 | 313bcead | Iustin Pop | @ivar instance_name: the name of the instance
|
933 | 313bcead | Iustin Pop | @ivar target_node: the destination node
|
934 | 313bcead | Iustin Pop |
|
935 | 313bcead | Iustin Pop | """
|
936 | 313bcead | Iustin Pop | OP_DSC_FIELD = "instance_name"
|
937 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
938 | 65e183af | Michael Hanselmann | _PInstanceName, |
939 | 65e183af | Michael Hanselmann | _PShutdownTimeout, |
940 | 65e183af | Michael Hanselmann | ("target_node", ht.NoDefault, ht.TNonEmptyString),
|
941 | 154b9580 | Balazs Lecz | ] |
942 | 313bcead | Iustin Pop | |
943 | 313bcead | Iustin Pop | |
944 | cc0dec7b | Iustin Pop | class OpInstanceConsole(OpCode): |
945 | fdc267f4 | Iustin Pop | """Connect to an instance's console."""
|
946 | 60dd1473 | Iustin Pop | OP_DSC_FIELD = "instance_name"
|
947 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
948 | 65e183af | Michael Hanselmann | _PInstanceName |
949 | 65e183af | Michael Hanselmann | ] |
950 | a8083063 | Iustin Pop | |
951 | a8083063 | Iustin Pop | |
952 | 83f5d475 | Iustin Pop | class OpInstanceActivateDisks(OpCode): |
953 | fdc267f4 | Iustin Pop | """Activate an instance's disks."""
|
954 | 60dd1473 | Iustin Pop | OP_DSC_FIELD = "instance_name"
|
955 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
956 | 65e183af | Michael Hanselmann | _PInstanceName, |
957 | 65e183af | Michael Hanselmann | ("ignore_size", False, ht.TBool), |
958 | 65e183af | Michael Hanselmann | ] |
959 | a8083063 | Iustin Pop | |
960 | a8083063 | Iustin Pop | |
961 | e176281f | Iustin Pop | class OpInstanceDeactivateDisks(OpCode): |
962 | fdc267f4 | Iustin Pop | """Deactivate an instance's disks."""
|
963 | 60dd1473 | Iustin Pop | OP_DSC_FIELD = "instance_name"
|
964 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
965 | c9c41373 | Iustin Pop | _PInstanceName, |
966 | c9c41373 | Iustin Pop | _PForce, |
967 | 65e183af | Michael Hanselmann | ] |
968 | a8083063 | Iustin Pop | |
969 | a8083063 | Iustin Pop | |
970 | 6b273e78 | Iustin Pop | class OpInstanceRecreateDisks(OpCode): |
971 | bd315bfa | Iustin Pop | """Deactivate an instance's disks."""
|
972 | bd315bfa | Iustin Pop | OP_DSC_FIELD = "instance_name"
|
973 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
974 | 65e183af | Michael Hanselmann | _PInstanceName, |
975 | 65e183af | Michael Hanselmann | ("disks", ht.EmptyList, ht.TListOf(ht.TPositiveInt)),
|
976 | 65e183af | Michael Hanselmann | ] |
977 | bd315bfa | Iustin Pop | |
978 | bd315bfa | Iustin Pop | |
979 | f2af0bec | Iustin Pop | class OpInstanceQuery(OpCode): |
980 | a8083063 | Iustin Pop | """Compute the list of instances."""
|
981 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
982 | 65e183af | Michael Hanselmann | _POutputFields, |
983 | 65e183af | Michael Hanselmann | ("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString)),
|
984 | 65e183af | Michael Hanselmann | ("use_locking", False, ht.TBool), |
985 | 65e183af | Michael Hanselmann | ] |
986 | a8083063 | Iustin Pop | |
987 | a8083063 | Iustin Pop | |
988 | dc28c4e4 | Iustin Pop | class OpInstanceQueryData(OpCode): |
989 | a8083063 | Iustin Pop | """Compute the run-time status of instances."""
|
990 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
991 | 65e183af | Michael Hanselmann | ("instances", ht.EmptyList, ht.TListOf(ht.TNonEmptyString)),
|
992 | 65e183af | Michael Hanselmann | ("static", False, ht.TBool), |
993 | 65e183af | Michael Hanselmann | ] |
994 | a8083063 | Iustin Pop | |
995 | a8083063 | Iustin Pop | |
996 | 9a3cc7ae | Iustin Pop | class OpInstanceSetParams(OpCode): |
997 | a8083063 | Iustin Pop | """Change the parameters of an instance."""
|
998 | 60dd1473 | Iustin Pop | OP_DSC_FIELD = "instance_name"
|
999 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
1000 | 65e183af | Michael Hanselmann | _PInstanceName, |
1001 | 65e183af | Michael Hanselmann | _PForce, |
1002 | 65e183af | Michael Hanselmann | ("nics", ht.EmptyList, ht.TList),
|
1003 | 65e183af | Michael Hanselmann | ("disks", ht.EmptyList, ht.TList),
|
1004 | 65e183af | Michael Hanselmann | ("beparams", ht.EmptyDict, ht.TDict),
|
1005 | 65e183af | Michael Hanselmann | ("hvparams", ht.EmptyDict, ht.TDict),
|
1006 | f7c8f153 | Michael Hanselmann | ("disk_template", None, ht.TOr(ht.TNone, _CheckDiskTemplate)), |
1007 | 65e183af | Michael Hanselmann | ("remote_node", None, ht.TMaybeString), |
1008 | 65e183af | Michael Hanselmann | ("os_name", None, ht.TMaybeString), |
1009 | 65e183af | Michael Hanselmann | ("force_variant", False, ht.TBool), |
1010 | 5f074973 | Michael Hanselmann | ("osparams", None, ht.TMaybeDict), |
1011 | 973d7867 | Iustin Pop | ] |
1012 | a8083063 | Iustin Pop | |
1013 | a8083063 | Iustin Pop | |
1014 | 60472d29 | Iustin Pop | class OpInstanceGrowDisk(OpCode): |
1015 | 8729e0d7 | Iustin Pop | """Grow a disk of an instance."""
|
1016 | 60dd1473 | Iustin Pop | OP_DSC_FIELD = "instance_name"
|
1017 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
1018 | 65e183af | Michael Hanselmann | _PInstanceName, |
1019 | 65e183af | Michael Hanselmann | ("disk", ht.NoDefault, ht.TInt),
|
1020 | 65e183af | Michael Hanselmann | ("amount", ht.NoDefault, ht.TInt),
|
1021 | 65e183af | Michael Hanselmann | ("wait_for_sync", True, ht.TBool), |
1022 | 4f05fd3b | Iustin Pop | ] |
1023 | 8729e0d7 | Iustin Pop | |
1024 | 8729e0d7 | Iustin Pop | |
1025 | 70a6a926 | Adeodato Simo | # Node group opcodes
|
1026 | 70a6a926 | Adeodato Simo | |
1027 | fabf1731 | Iustin Pop | class OpGroupAdd(OpCode): |
1028 | b1ee5610 | Adeodato Simo | """Add a node group to the cluster."""
|
1029 | b1ee5610 | Adeodato Simo | OP_DSC_FIELD = "group_name"
|
1030 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
1031 | 65e183af | Michael Hanselmann | _PGroupName, |
1032 | 5f074973 | Michael Hanselmann | ("ndparams", None, ht.TMaybeDict), |
1033 | 65e183af | Michael Hanselmann | ("alloc_policy", None, |
1034 | 65e183af | Michael Hanselmann | ht.TOr(ht.TNone, ht.TElemOf(constants.VALID_ALLOC_POLICIES))), |
1035 | 483be60d | Adeodato Simo | ] |
1036 | b1ee5610 | Adeodato Simo | |
1037 | b1ee5610 | Adeodato Simo | |
1038 | 934704ae | Iustin Pop | class OpGroupAssignNodes(OpCode): |
1039 | 96276ae7 | Adeodato Simo | """Assign nodes to a node group."""
|
1040 | 96276ae7 | Adeodato Simo | OP_DSC_FIELD = "group_name"
|
1041 | 96276ae7 | Adeodato Simo | OP_PARAMS = [ |
1042 | 96276ae7 | Adeodato Simo | _PGroupName, |
1043 | 96276ae7 | Adeodato Simo | _PForce, |
1044 | 96276ae7 | Adeodato Simo | ("nodes", ht.NoDefault, ht.TListOf(ht.TNonEmptyString)),
|
1045 | 96276ae7 | Adeodato Simo | ] |
1046 | 96276ae7 | Adeodato Simo | |
1047 | 96276ae7 | Adeodato Simo | |
1048 | d4d654bd | Iustin Pop | class OpGroupQuery(OpCode): |
1049 | 70a6a926 | Adeodato Simo | """Compute the list of node groups."""
|
1050 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
1051 | 65e183af | Michael Hanselmann | _POutputFields, |
1052 | 65e183af | Michael Hanselmann | ("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString)),
|
1053 | 65e183af | Michael Hanselmann | ] |
1054 | 70a6a926 | Adeodato Simo | |
1055 | 70a6a926 | Adeodato Simo | |
1056 | 7cbf74f0 | Iustin Pop | class OpGroupSetParams(OpCode): |
1057 | 4da7909a | Adeodato Simo | """Change the parameters of a node group."""
|
1058 | 4da7909a | Adeodato Simo | OP_DSC_FIELD = "group_name"
|
1059 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
1060 | 65e183af | Michael Hanselmann | _PGroupName, |
1061 | 5f074973 | Michael Hanselmann | ("ndparams", None, ht.TMaybeDict), |
1062 | 65e183af | Michael Hanselmann | ("alloc_policy", None, ht.TOr(ht.TNone, |
1063 | 65e183af | Michael Hanselmann | ht.TElemOf(constants.VALID_ALLOC_POLICIES))), |
1064 | 4da7909a | Adeodato Simo | ] |
1065 | 4da7909a | Adeodato Simo | |
1066 | 4da7909a | Adeodato Simo | |
1067 | 4d1baa51 | Iustin Pop | class OpGroupRemove(OpCode): |
1068 | 94bd652a | Adeodato Simo | """Remove a node group from the cluster."""
|
1069 | 94bd652a | Adeodato Simo | OP_DSC_FIELD = "group_name"
|
1070 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
1071 | 65e183af | Michael Hanselmann | _PGroupName, |
1072 | 65e183af | Michael Hanselmann | ] |
1073 | 94bd652a | Adeodato Simo | |
1074 | 94bd652a | Adeodato Simo | |
1075 | a8173e82 | Iustin Pop | class OpGroupRename(OpCode): |
1076 | 4fe5cf90 | Adeodato Simo | """Rename a node group in the cluster."""
|
1077 | 4fe5cf90 | Adeodato Simo | OP_DSC_FIELD = "old_name"
|
1078 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
1079 | 65e183af | Michael Hanselmann | ("old_name", ht.NoDefault, ht.TNonEmptyString),
|
1080 | 65e183af | Michael Hanselmann | ("new_name", ht.NoDefault, ht.TNonEmptyString),
|
1081 | 65e183af | Michael Hanselmann | ] |
1082 | 4fe5cf90 | Adeodato Simo | |
1083 | 4fe5cf90 | Adeodato Simo | |
1084 | a8083063 | Iustin Pop | # OS opcodes
|
1085 | da2d02e7 | Iustin Pop | class OpOsDiagnose(OpCode): |
1086 | a8083063 | Iustin Pop | """Compute the list of guest operating systems."""
|
1087 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
1088 | 65e183af | Michael Hanselmann | _POutputFields, |
1089 | 65e183af | Michael Hanselmann | ("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString)),
|
1090 | 65e183af | Michael Hanselmann | ] |
1091 | a8083063 | Iustin Pop | |
1092 | 7c0d6283 | Michael Hanselmann | |
1093 | a8083063 | Iustin Pop | # Exports opcodes
|
1094 | 7ca2d4d8 | Iustin Pop | class OpBackupQuery(OpCode): |
1095 | a8083063 | Iustin Pop | """Compute the list of exported images."""
|
1096 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
1097 | 65e183af | Michael Hanselmann | ("nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString)),
|
1098 | 65e183af | Michael Hanselmann | ("use_locking", False, ht.TBool), |
1099 | 65e183af | Michael Hanselmann | ] |
1100 | a8083063 | Iustin Pop | |
1101 | 7c0d6283 | Michael Hanselmann | |
1102 | 71910715 | Iustin Pop | class OpBackupPrepare(OpCode): |
1103 | 1410fa8d | Michael Hanselmann | """Prepares an instance export.
|
1104 | 1410fa8d | Michael Hanselmann |
|
1105 | 1410fa8d | Michael Hanselmann | @ivar instance_name: Instance name
|
1106 | 1410fa8d | Michael Hanselmann | @ivar mode: Export mode (one of L{constants.EXPORT_MODES})
|
1107 | 1410fa8d | Michael Hanselmann |
|
1108 | 1410fa8d | Michael Hanselmann | """
|
1109 | 1410fa8d | Michael Hanselmann | OP_DSC_FIELD = "instance_name"
|
1110 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
1111 | 65e183af | Michael Hanselmann | _PInstanceName, |
1112 | 65e183af | Michael Hanselmann | ("mode", ht.NoDefault, ht.TElemOf(constants.EXPORT_MODES)),
|
1113 | 1410fa8d | Michael Hanselmann | ] |
1114 | 1410fa8d | Michael Hanselmann | |
1115 | 1410fa8d | Michael Hanselmann | |
1116 | 4ff922a2 | Iustin Pop | class OpBackupExport(OpCode): |
1117 | 4a96f1d1 | Michael Hanselmann | """Export an instance.
|
1118 | 4a96f1d1 | Michael Hanselmann |
|
1119 | 4a96f1d1 | Michael Hanselmann | For local exports, the export destination is the node name. For remote
|
1120 | 4a96f1d1 | Michael Hanselmann | exports, the export destination is a list of tuples, each consisting of
|
1121 | 4a96f1d1 | Michael Hanselmann | hostname/IP address, port, HMAC and HMAC salt. The HMAC is calculated using
|
1122 | 4a96f1d1 | Michael Hanselmann | the cluster domain secret over the value "${index}:${hostname}:${port}". The
|
1123 | 4a96f1d1 | Michael Hanselmann | destination X509 CA must be a signed certificate.
|
1124 | 4a96f1d1 | Michael Hanselmann |
|
1125 | 4a96f1d1 | Michael Hanselmann | @ivar mode: Export mode (one of L{constants.EXPORT_MODES})
|
1126 | 4a96f1d1 | Michael Hanselmann | @ivar target_node: Export destination
|
1127 | 4a96f1d1 | Michael Hanselmann | @ivar x509_key_name: X509 key to use (remote export only)
|
1128 | 4a96f1d1 | Michael Hanselmann | @ivar destination_x509_ca: Destination X509 CA in PEM format (remote export
|
1129 | 4a96f1d1 | Michael Hanselmann | only)
|
1130 | 4a96f1d1 | Michael Hanselmann |
|
1131 | 4a96f1d1 | Michael Hanselmann | """
|
1132 | 60dd1473 | Iustin Pop | OP_DSC_FIELD = "instance_name"
|
1133 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
1134 | 65e183af | Michael Hanselmann | _PInstanceName, |
1135 | 65e183af | Michael Hanselmann | _PShutdownTimeout, |
1136 | 4a96f1d1 | Michael Hanselmann | # TODO: Rename target_node as it changes meaning for different export modes
|
1137 | 4a96f1d1 | Michael Hanselmann | # (e.g. "destination")
|
1138 | 65e183af | Michael Hanselmann | ("target_node", ht.NoDefault, ht.TOr(ht.TNonEmptyString, ht.TList)),
|
1139 | 65e183af | Michael Hanselmann | ("shutdown", True, ht.TBool), |
1140 | 65e183af | Michael Hanselmann | ("remove_instance", False, ht.TBool), |
1141 | 65e183af | Michael Hanselmann | ("ignore_remove_failures", False, ht.TBool), |
1142 | 65e183af | Michael Hanselmann | ("mode", constants.EXPORT_MODE_LOCAL, ht.TElemOf(constants.EXPORT_MODES)),
|
1143 | 65e183af | Michael Hanselmann | ("x509_key_name", None, ht.TOr(ht.TList, ht.TNone)), |
1144 | 65e183af | Michael Hanselmann | ("destination_x509_ca", None, ht.TMaybeString), |
1145 | 17c3f802 | Guido Trotter | ] |
1146 | 5c947f38 | Iustin Pop | |
1147 | 0a7bed64 | Michael Hanselmann | |
1148 | ca5890ad | Iustin Pop | class OpBackupRemove(OpCode): |
1149 | 9ac99fda | Guido Trotter | """Remove an instance's export."""
|
1150 | 60dd1473 | Iustin Pop | OP_DSC_FIELD = "instance_name"
|
1151 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
1152 | 65e183af | Michael Hanselmann | _PInstanceName, |
1153 | 65e183af | Michael Hanselmann | ] |
1154 | 5c947f38 | Iustin Pop | |
1155 | 0a7bed64 | Michael Hanselmann | |
1156 | 5c947f38 | Iustin Pop | # Tags opcodes
|
1157 | c6afb1ca | Iustin Pop | class OpTagsGet(OpCode): |
1158 | 5c947f38 | Iustin Pop | """Returns the tags of the given object."""
|
1159 | 60dd1473 | Iustin Pop | OP_DSC_FIELD = "name"
|
1160 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
1161 | 65e183af | Michael Hanselmann | _PTagKind, |
1162 | 65e183af | Michael Hanselmann | # Name is only meaningful for nodes and instances
|
1163 | 65e183af | Michael Hanselmann | ("name", ht.NoDefault, ht.TMaybeString),
|
1164 | 65e183af | Michael Hanselmann | ] |
1165 | 5c947f38 | Iustin Pop | |
1166 | 5c947f38 | Iustin Pop | |
1167 | 715462e7 | Iustin Pop | class OpTagsSearch(OpCode): |
1168 | 73415719 | Iustin Pop | """Searches the tags in the cluster for a given pattern."""
|
1169 | 60dd1473 | Iustin Pop | OP_DSC_FIELD = "pattern"
|
1170 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
1171 | 65e183af | Michael Hanselmann | ("pattern", ht.NoDefault, ht.TNonEmptyString),
|
1172 | 65e183af | Michael Hanselmann | ] |
1173 | 73415719 | Iustin Pop | |
1174 | 73415719 | Iustin Pop | |
1175 | d1602edc | Iustin Pop | class OpTagsSet(OpCode): |
1176 | f27302fa | Iustin Pop | """Add a list of tags on a given object."""
|
1177 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
1178 | 65e183af | Michael Hanselmann | _PTagKind, |
1179 | 65e183af | Michael Hanselmann | _PTags, |
1180 | 65e183af | Michael Hanselmann | # Name is only meaningful for nodes and instances
|
1181 | 65e183af | Michael Hanselmann | ("name", ht.NoDefault, ht.TMaybeString),
|
1182 | 65e183af | Michael Hanselmann | ] |
1183 | 5c947f38 | Iustin Pop | |
1184 | 5c947f38 | Iustin Pop | |
1185 | 3f0ab95f | Iustin Pop | class OpTagsDel(OpCode): |
1186 | f27302fa | Iustin Pop | """Remove a list of tags from a given object."""
|
1187 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
1188 | 65e183af | Michael Hanselmann | _PTagKind, |
1189 | 65e183af | Michael Hanselmann | _PTags, |
1190 | 65e183af | Michael Hanselmann | # Name is only meaningful for nodes and instances
|
1191 | 65e183af | Michael Hanselmann | ("name", ht.NoDefault, ht.TMaybeString),
|
1192 | 65e183af | Michael Hanselmann | ] |
1193 | 06009e27 | Iustin Pop | |
1194 | 06009e27 | Iustin Pop | # Test opcodes
|
1195 | 06009e27 | Iustin Pop | class OpTestDelay(OpCode): |
1196 | 06009e27 | Iustin Pop | """Sleeps for a configured amount of time.
|
1197 | 06009e27 | Iustin Pop |
|
1198 | 06009e27 | Iustin Pop | This is used just for debugging and testing.
|
1199 | 06009e27 | Iustin Pop |
|
1200 | 06009e27 | Iustin Pop | Parameters:
|
1201 | 06009e27 | Iustin Pop | - duration: the time to sleep
|
1202 | 06009e27 | Iustin Pop | - on_master: if true, sleep on the master
|
1203 | 06009e27 | Iustin Pop | - on_nodes: list of nodes in which to sleep
|
1204 | 06009e27 | Iustin Pop |
|
1205 | 06009e27 | Iustin Pop | If the on_master parameter is true, it will execute a sleep on the
|
1206 | 06009e27 | Iustin Pop | master (before any node sleep).
|
1207 | 06009e27 | Iustin Pop |
|
1208 | 06009e27 | Iustin Pop | If the on_nodes list is not empty, it will sleep on those nodes
|
1209 | 06009e27 | Iustin Pop | (after the sleep on the master, if that is enabled).
|
1210 | 06009e27 | Iustin Pop |
|
1211 | 06009e27 | Iustin Pop | As an additional feature, the case of duration < 0 will be reported
|
1212 | 06009e27 | Iustin Pop | as an execution error, so this opcode can be used as a failure
|
1213 | 06009e27 | Iustin Pop | generator. The case of duration == 0 will not be treated specially.
|
1214 | 06009e27 | Iustin Pop |
|
1215 | 06009e27 | Iustin Pop | """
|
1216 | 60dd1473 | Iustin Pop | OP_DSC_FIELD = "duration"
|
1217 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
1218 | 65e183af | Michael Hanselmann | ("duration", ht.NoDefault, ht.TFloat),
|
1219 | 65e183af | Michael Hanselmann | ("on_master", True, ht.TBool), |
1220 | 65e183af | Michael Hanselmann | ("on_nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString)),
|
1221 | 65e183af | Michael Hanselmann | ("repeat", 0, ht.TPositiveInt) |
1222 | 65e183af | Michael Hanselmann | ] |
1223 | d61df03e | Iustin Pop | |
1224 | d61df03e | Iustin Pop | |
1225 | d61df03e | Iustin Pop | class OpTestAllocator(OpCode): |
1226 | d61df03e | Iustin Pop | """Allocator framework testing.
|
1227 | d61df03e | Iustin Pop |
|
1228 | d61df03e | Iustin Pop | This opcode has two modes:
|
1229 | d61df03e | Iustin Pop | - gather and return allocator input for a given mode (allocate new
|
1230 | d61df03e | Iustin Pop | or replace secondary) and a given instance definition (direction
|
1231 | d61df03e | Iustin Pop | 'in')
|
1232 | d61df03e | Iustin Pop | - run a selected allocator for a given operation (as above) and
|
1233 | d61df03e | Iustin Pop | return the allocator output (direction 'out')
|
1234 | d61df03e | Iustin Pop |
|
1235 | d61df03e | Iustin Pop | """
|
1236 | 60dd1473 | Iustin Pop | OP_DSC_FIELD = "allocator"
|
1237 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
1238 | 65e183af | Michael Hanselmann | ("direction", ht.NoDefault,
|
1239 | 65e183af | Michael Hanselmann | ht.TElemOf(constants.VALID_IALLOCATOR_DIRECTIONS)), |
1240 | 65e183af | Michael Hanselmann | ("mode", ht.NoDefault, ht.TElemOf(constants.VALID_IALLOCATOR_MODES)),
|
1241 | 65e183af | Michael Hanselmann | ("name", ht.NoDefault, ht.TNonEmptyString),
|
1242 | 65e183af | Michael Hanselmann | ("nics", ht.NoDefault, ht.TOr(ht.TNone, ht.TListOf(
|
1243 | 65e183af | Michael Hanselmann | ht.TDictOf(ht.TElemOf(["mac", "ip", "bridge"]), |
1244 | 65e183af | Michael Hanselmann | ht.TOr(ht.TNone, ht.TNonEmptyString))))), |
1245 | 65e183af | Michael Hanselmann | ("disks", ht.NoDefault, ht.TOr(ht.TNone, ht.TList)),
|
1246 | 65e183af | Michael Hanselmann | ("hypervisor", None, ht.TMaybeString), |
1247 | 65e183af | Michael Hanselmann | ("allocator", None, ht.TMaybeString), |
1248 | 65e183af | Michael Hanselmann | ("tags", ht.EmptyList, ht.TListOf(ht.TNonEmptyString)),
|
1249 | 65e183af | Michael Hanselmann | ("mem_size", None, ht.TOr(ht.TNone, ht.TPositiveInt)), |
1250 | 65e183af | Michael Hanselmann | ("vcpus", None, ht.TOr(ht.TNone, ht.TPositiveInt)), |
1251 | 65e183af | Michael Hanselmann | ("os", None, ht.TMaybeString), |
1252 | 65e183af | Michael Hanselmann | ("disk_template", None, ht.TMaybeString), |
1253 | 65e183af | Michael Hanselmann | ("evac_nodes", None, ht.TOr(ht.TNone, ht.TListOf(ht.TNonEmptyString))), |
1254 | d61df03e | Iustin Pop | ] |
1255 | 363acb1e | Iustin Pop | |
1256 | 76aef8fc | Michael Hanselmann | |
1257 | b469eb4d | Iustin Pop | class OpTestJqueue(OpCode): |
1258 | e58f87a9 | Michael Hanselmann | """Utility opcode to test some aspects of the job queue.
|
1259 | e58f87a9 | Michael Hanselmann |
|
1260 | e58f87a9 | Michael Hanselmann | """
|
1261 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
1262 | 65e183af | Michael Hanselmann | ("notify_waitlock", False, ht.TBool), |
1263 | 65e183af | Michael Hanselmann | ("notify_exec", False, ht.TBool), |
1264 | 65e183af | Michael Hanselmann | ("log_messages", ht.EmptyList, ht.TListOf(ht.TString)),
|
1265 | 65e183af | Michael Hanselmann | ("fail", False, ht.TBool), |
1266 | e58f87a9 | Michael Hanselmann | ] |
1267 | e58f87a9 | Michael Hanselmann | |
1268 | e58f87a9 | Michael Hanselmann | |
1269 | be760ba8 | Michael Hanselmann | class OpTestDummy(OpCode): |
1270 | be760ba8 | Michael Hanselmann | """Utility opcode used by unittests.
|
1271 | be760ba8 | Michael Hanselmann |
|
1272 | be760ba8 | Michael Hanselmann | """
|
1273 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
1274 | 65e183af | Michael Hanselmann | ("result", ht.NoDefault, ht.NoType),
|
1275 | 65e183af | Michael Hanselmann | ("messages", ht.NoDefault, ht.NoType),
|
1276 | 65e183af | Michael Hanselmann | ("fail", ht.NoDefault, ht.NoType),
|
1277 | be760ba8 | Michael Hanselmann | ] |
1278 | 687c10d9 | Iustin Pop | WITH_LU = False
|
1279 | be760ba8 | Michael Hanselmann | |
1280 | be760ba8 | Michael Hanselmann | |
1281 | dbc96028 | Michael Hanselmann | def _GetOpList(): |
1282 | dbc96028 | Michael Hanselmann | """Returns list of all defined opcodes.
|
1283 | dbc96028 | Michael Hanselmann |
|
1284 | dbc96028 | Michael Hanselmann | Does not eliminate duplicates by C{OP_ID}.
|
1285 | dbc96028 | Michael Hanselmann |
|
1286 | dbc96028 | Michael Hanselmann | """
|
1287 | dbc96028 | Michael Hanselmann | return [v for v in globals().values() |
1288 | dbc96028 | Michael Hanselmann | if (isinstance(v, type) and issubclass(v, OpCode) and |
1289 | 687c10d9 | Iustin Pop | hasattr(v, "OP_ID") and v is not OpCode)] |
1290 | dbc96028 | Michael Hanselmann | |
1291 | dbc96028 | Michael Hanselmann | |
1292 | dbc96028 | Michael Hanselmann | OP_MAPPING = dict((v.OP_ID, v) for v in _GetOpList()) |