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