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