root / lib / opcodes.py @ c363310d
History | View | Annotate | Download (56.1 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=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 |
"Selected output fields")
|
49 |
|
50 |
#: the shutdown timeout
|
51 |
_PShutdownTimeout = \ |
52 |
("shutdown_timeout", constants.DEFAULT_SHUTDOWN_TIMEOUT, ht.TPositiveInt,
|
53 |
"How long to wait for instance to shut down")
|
54 |
|
55 |
#: the force parameter
|
56 |
_PForce = ("force", False, ht.TBool, "Whether to force the operation") |
57 |
|
58 |
#: a required instance name (for single-instance LUs)
|
59 |
_PInstanceName = ("instance_name", ht.NoDefault, ht.TNonEmptyString,
|
60 |
"Instance name")
|
61 |
|
62 |
#: Whether to ignore offline nodes
|
63 |
_PIgnoreOfflineNodes = ("ignore_offline_nodes", False, ht.TBool, |
64 |
"Whether to ignore offline nodes")
|
65 |
|
66 |
#: a required node name (for single-node LUs)
|
67 |
_PNodeName = ("node_name", ht.NoDefault, ht.TNonEmptyString, "Node name") |
68 |
|
69 |
#: a required node group name (for single-group LUs)
|
70 |
_PGroupName = ("group_name", ht.NoDefault, ht.TNonEmptyString, "Group name") |
71 |
|
72 |
#: Migration type (live/non-live)
|
73 |
_PMigrationMode = ("mode", None, |
74 |
ht.TOr(ht.TNone, ht.TElemOf(constants.HT_MIGRATION_MODES)), |
75 |
"Migration mode")
|
76 |
|
77 |
#: Obsolete 'live' migration mode (boolean)
|
78 |
_PMigrationLive = ("live", None, ht.TMaybeBool, |
79 |
"Legacy setting for live migration, do not use")
|
80 |
|
81 |
#: Tag type
|
82 |
_PTagKind = ("kind", ht.NoDefault, ht.TElemOf(constants.VALID_TAG_TYPES), None) |
83 |
|
84 |
#: List of tag strings
|
85 |
_PTags = ("tags", ht.NoDefault, ht.TListOf(ht.TNonEmptyString), None) |
86 |
|
87 |
_PForceVariant = ("force_variant", False, ht.TBool, |
88 |
"Whether to force an unknown OS variant")
|
89 |
|
90 |
_PWaitForSync = ("wait_for_sync", True, ht.TBool, |
91 |
"Whether to wait for the disk to synchronize")
|
92 |
|
93 |
_PIgnoreConsistency = ("ignore_consistency", False, ht.TBool, |
94 |
"Whether to ignore disk consistency")
|
95 |
|
96 |
_PStorageName = ("name", ht.NoDefault, ht.TMaybeString, "Storage name") |
97 |
|
98 |
_PUseLocking = ("use_locking", False, ht.TBool, |
99 |
"Whether to use synchronization")
|
100 |
|
101 |
_PNameCheck = ("name_check", True, ht.TBool, "Whether to check name") |
102 |
|
103 |
_PNodeGroupAllocPolicy = \ |
104 |
("alloc_policy", None, |
105 |
ht.TOr(ht.TNone, ht.TElemOf(constants.VALID_ALLOC_POLICIES)), |
106 |
"Instance allocation policy")
|
107 |
|
108 |
_PGroupNodeParams = ("ndparams", None, ht.TMaybeDict, |
109 |
"Default node parameters for group")
|
110 |
|
111 |
_PQueryWhat = ("what", ht.NoDefault, ht.TElemOf(constants.QR_VIA_OP),
|
112 |
"Resource(s) to query for")
|
113 |
|
114 |
_PEarlyRelease = ("early_release", False, ht.TBool, |
115 |
"Whether to release locks as soon as possible")
|
116 |
|
117 |
_PIpCheckDoc = "Whether to ensure instance's IP address is inactive"
|
118 |
|
119 |
#: Do not remember instance state changes
|
120 |
_PNoRemember = ("no_remember", False, ht.TBool, |
121 |
"Do not remember the state change")
|
122 |
|
123 |
#: Target node for instance migration/failover
|
124 |
_PMigrationTargetNode = ("target_node", None, ht.TMaybeString, |
125 |
"Target node for shared-storage instances")
|
126 |
|
127 |
_PStartupPaused = ("startup_paused", False, ht.TBool, |
128 |
"Pause instance at startup")
|
129 |
|
130 |
_PVerbose = ("verbose", False, ht.TBool, "Verbose mode") |
131 |
|
132 |
# Parameters for cluster verification
|
133 |
_PDebugSimulateErrors = ("debug_simulate_errors", False, ht.TBool, |
134 |
"Whether to simulate errors (useful for debugging)")
|
135 |
_PErrorCodes = ("error_codes", False, ht.TBool, "Error codes") |
136 |
_PSkipChecks = ("skip_checks", ht.EmptyList,
|
137 |
ht.TListOf(ht.TElemOf(constants.VERIFY_OPTIONAL_CHECKS)), |
138 |
"Which checks to skip")
|
139 |
_PIgnoreErrors = ("ignore_errors", ht.EmptyList,
|
140 |
ht.TListOf(ht.TElemOf(constants.CV_ALL_ECODES_STRINGS)), |
141 |
"List of error codes that should be treated as warnings")
|
142 |
|
143 |
# Disk parameters
|
144 |
_PDiskParams = ("diskparams", None, |
145 |
ht.TOr( |
146 |
ht.TDictOf(ht.TElemOf(constants.DISK_TEMPLATES), ht.TDict), |
147 |
ht.TNone), |
148 |
"Disk templates' parameter defaults")
|
149 |
|
150 |
# Parameters for node resource model
|
151 |
_PHvState = ("hv_state", None, ht.TMaybeDict, "Set hypervisor states") |
152 |
_PDiskState = ("disk_state", None, ht.TMaybeDict, "Set disk states") |
153 |
|
154 |
|
155 |
_PIgnoreIpolicy = ("ignore_ipolicy", False, ht.TBool, |
156 |
"Whether to ignore ipolicy violations")
|
157 |
|
158 |
# Allow runtime changes while migrating
|
159 |
_PAllowRuntimeChgs = ("allow_runtime_changes", True, ht.TBool, |
160 |
"Allow runtime changes (eg. memory ballooning)")
|
161 |
|
162 |
|
163 |
#: OP_ID conversion regular expression
|
164 |
_OPID_RE = re.compile("([a-z])([A-Z])")
|
165 |
|
166 |
#: Utility function for L{OpClusterSetParams}
|
167 |
_TestClusterOsListItem = \ |
168 |
ht.TAnd(ht.TIsLength(2), ht.TItems([
|
169 |
ht.TElemOf(constants.DDMS_VALUES), |
170 |
ht.TNonEmptyString, |
171 |
])) |
172 |
|
173 |
_TestClusterOsList = ht.TMaybeListOf(_TestClusterOsListItem) |
174 |
|
175 |
# TODO: Generate check from constants.INIC_PARAMS_TYPES
|
176 |
#: Utility function for testing NIC definitions
|
177 |
_TestNicDef = \ |
178 |
ht.Comment("NIC parameters")(ht.TDictOf(ht.TElemOf(constants.INIC_PARAMS),
|
179 |
ht.TOr(ht.TNone, ht.TNonEmptyString))) |
180 |
|
181 |
_TSetParamsResultItemItems = [ |
182 |
ht.Comment("name of changed parameter")(ht.TNonEmptyString),
|
183 |
ht.Comment("new value")(ht.TAny),
|
184 |
] |
185 |
|
186 |
_TSetParamsResult = \ |
187 |
ht.TListOf(ht.TAnd(ht.TIsLength(len(_TSetParamsResultItemItems)),
|
188 |
ht.TItems(_TSetParamsResultItemItems))) |
189 |
|
190 |
# TODO: Generate check from constants.IDISK_PARAMS_TYPES (however, not all users
|
191 |
# of this check support all parameters)
|
192 |
_TDiskParams = \ |
193 |
ht.Comment("Disk parameters")(ht.TDictOf(ht.TElemOf(constants.IDISK_PARAMS),
|
194 |
ht.TOr(ht.TNonEmptyString, ht.TInt))) |
195 |
|
196 |
_SUMMARY_PREFIX = { |
197 |
"CLUSTER_": "C_", |
198 |
"GROUP_": "G_", |
199 |
"NODE_": "N_", |
200 |
"INSTANCE_": "I_", |
201 |
} |
202 |
|
203 |
#: Attribute name for dependencies
|
204 |
DEPEND_ATTR = "depends"
|
205 |
|
206 |
#: Attribute name for comment
|
207 |
COMMENT_ATTR = "comment"
|
208 |
|
209 |
|
210 |
def _NameToId(name): |
211 |
"""Convert an opcode class name to an OP_ID.
|
212 |
|
213 |
@type name: string
|
214 |
@param name: the class name, as OpXxxYyy
|
215 |
@rtype: string
|
216 |
@return: the name in the OP_XXXX_YYYY format
|
217 |
|
218 |
"""
|
219 |
if not name.startswith("Op"): |
220 |
return None |
221 |
# Note: (?<=[a-z])(?=[A-Z]) would be ideal, since it wouldn't
|
222 |
# consume any input, and hence we would just have all the elements
|
223 |
# in the list, one by one; but it seems that split doesn't work on
|
224 |
# non-consuming input, hence we have to process the input string a
|
225 |
# bit
|
226 |
name = _OPID_RE.sub(r"\1,\2", name)
|
227 |
elems = name.split(",")
|
228 |
return "_".join(n.upper() for n in elems) |
229 |
|
230 |
|
231 |
def RequireFileStorage(): |
232 |
"""Checks that file storage is enabled.
|
233 |
|
234 |
While it doesn't really fit into this module, L{utils} was deemed too large
|
235 |
of a dependency to be imported for just one or two functions.
|
236 |
|
237 |
@raise errors.OpPrereqError: when file storage is disabled
|
238 |
|
239 |
"""
|
240 |
if not constants.ENABLE_FILE_STORAGE: |
241 |
raise errors.OpPrereqError("File storage disabled at configure time", |
242 |
errors.ECODE_INVAL) |
243 |
|
244 |
|
245 |
def RequireSharedFileStorage(): |
246 |
"""Checks that shared file storage is enabled.
|
247 |
|
248 |
While it doesn't really fit into this module, L{utils} was deemed too large
|
249 |
of a dependency to be imported for just one or two functions.
|
250 |
|
251 |
@raise errors.OpPrereqError: when shared file storage is disabled
|
252 |
|
253 |
"""
|
254 |
if not constants.ENABLE_SHARED_FILE_STORAGE: |
255 |
raise errors.OpPrereqError("Shared file storage disabled at" |
256 |
" configure time", errors.ECODE_INVAL)
|
257 |
|
258 |
|
259 |
@ht.WithDesc("CheckFileStorage") |
260 |
def _CheckFileStorage(value): |
261 |
"""Ensures file storage is enabled if used.
|
262 |
|
263 |
"""
|
264 |
if value == constants.DT_FILE:
|
265 |
RequireFileStorage() |
266 |
elif value == constants.DT_SHARED_FILE:
|
267 |
RequireSharedFileStorage() |
268 |
return True |
269 |
|
270 |
|
271 |
def _BuildDiskTemplateCheck(accept_none): |
272 |
"""Builds check for disk template.
|
273 |
|
274 |
@type accept_none: bool
|
275 |
@param accept_none: whether to accept None as a correct value
|
276 |
@rtype: callable
|
277 |
|
278 |
"""
|
279 |
template_check = ht.TElemOf(constants.DISK_TEMPLATES) |
280 |
|
281 |
if accept_none:
|
282 |
template_check = ht.TOr(template_check, ht.TNone) |
283 |
|
284 |
return ht.TAnd(template_check, _CheckFileStorage)
|
285 |
|
286 |
|
287 |
def _CheckStorageType(storage_type): |
288 |
"""Ensure a given storage type is valid.
|
289 |
|
290 |
"""
|
291 |
if storage_type not in constants.VALID_STORAGE_TYPES: |
292 |
raise errors.OpPrereqError("Unknown storage type: %s" % storage_type, |
293 |
errors.ECODE_INVAL) |
294 |
if storage_type == constants.ST_FILE:
|
295 |
RequireFileStorage() |
296 |
return True |
297 |
|
298 |
|
299 |
#: Storage type parameter
|
300 |
_PStorageType = ("storage_type", ht.NoDefault, _CheckStorageType,
|
301 |
"Storage type")
|
302 |
|
303 |
|
304 |
class _AutoOpParamSlots(type): |
305 |
"""Meta class for opcode definitions.
|
306 |
|
307 |
"""
|
308 |
def __new__(mcs, name, bases, attrs): |
309 |
"""Called when a class should be created.
|
310 |
|
311 |
@param mcs: The meta class
|
312 |
@param name: Name of created class
|
313 |
@param bases: Base classes
|
314 |
@type attrs: dict
|
315 |
@param attrs: Class attributes
|
316 |
|
317 |
"""
|
318 |
assert "__slots__" not in attrs, \ |
319 |
"Class '%s' defines __slots__ when it should use OP_PARAMS" % name
|
320 |
assert "OP_ID" not in attrs, "Class '%s' defining OP_ID" % name |
321 |
|
322 |
attrs["OP_ID"] = _NameToId(name)
|
323 |
|
324 |
# Always set OP_PARAMS to avoid duplicates in BaseOpCode.GetAllParams
|
325 |
params = attrs.setdefault("OP_PARAMS", [])
|
326 |
|
327 |
# Use parameter names as slots
|
328 |
slots = [pname for (pname, _, _, _) in params] |
329 |
|
330 |
assert "OP_DSC_FIELD" not in attrs or attrs["OP_DSC_FIELD"] in slots, \ |
331 |
"Class '%s' uses unknown field in OP_DSC_FIELD" % name
|
332 |
|
333 |
attrs["__slots__"] = slots
|
334 |
|
335 |
return type.__new__(mcs, name, bases, attrs) |
336 |
|
337 |
|
338 |
class BaseOpCode(object): |
339 |
"""A simple serializable object.
|
340 |
|
341 |
This object serves as a parent class for OpCode without any custom
|
342 |
field handling.
|
343 |
|
344 |
"""
|
345 |
# pylint: disable=E1101
|
346 |
# as OP_ID is dynamically defined
|
347 |
__metaclass__ = _AutoOpParamSlots |
348 |
|
349 |
def __init__(self, **kwargs): |
350 |
"""Constructor for BaseOpCode.
|
351 |
|
352 |
The constructor takes only keyword arguments and will set
|
353 |
attributes on this object based on the passed arguments. As such,
|
354 |
it means that you should not pass arguments which are not in the
|
355 |
__slots__ attribute for this class.
|
356 |
|
357 |
"""
|
358 |
slots = self._all_slots()
|
359 |
for key in kwargs: |
360 |
if key not in slots: |
361 |
raise TypeError("Object %s doesn't support the parameter '%s'" % |
362 |
(self.__class__.__name__, key))
|
363 |
setattr(self, key, kwargs[key]) |
364 |
|
365 |
def __getstate__(self): |
366 |
"""Generic serializer.
|
367 |
|
368 |
This method just returns the contents of the instance as a
|
369 |
dictionary.
|
370 |
|
371 |
@rtype: C{dict}
|
372 |
@return: the instance attributes and their values
|
373 |
|
374 |
"""
|
375 |
state = {} |
376 |
for name in self._all_slots(): |
377 |
if hasattr(self, name): |
378 |
state[name] = getattr(self, name) |
379 |
return state
|
380 |
|
381 |
def __setstate__(self, state): |
382 |
"""Generic unserializer.
|
383 |
|
384 |
This method just restores from the serialized state the attributes
|
385 |
of the current instance.
|
386 |
|
387 |
@param state: the serialized opcode data
|
388 |
@type state: C{dict}
|
389 |
|
390 |
"""
|
391 |
if not isinstance(state, dict): |
392 |
raise ValueError("Invalid data to __setstate__: expected dict, got %s" % |
393 |
type(state))
|
394 |
|
395 |
for name in self._all_slots(): |
396 |
if name not in state and hasattr(self, name): |
397 |
delattr(self, name) |
398 |
|
399 |
for name in state: |
400 |
setattr(self, name, state[name]) |
401 |
|
402 |
@classmethod
|
403 |
def _all_slots(cls): |
404 |
"""Compute the list of all declared slots for a class.
|
405 |
|
406 |
"""
|
407 |
slots = [] |
408 |
for parent in cls.__mro__: |
409 |
slots.extend(getattr(parent, "__slots__", [])) |
410 |
return slots
|
411 |
|
412 |
@classmethod
|
413 |
def GetAllParams(cls): |
414 |
"""Compute list of all parameters for an opcode.
|
415 |
|
416 |
"""
|
417 |
slots = [] |
418 |
for parent in cls.__mro__: |
419 |
slots.extend(getattr(parent, "OP_PARAMS", [])) |
420 |
return slots
|
421 |
|
422 |
def Validate(self, set_defaults): |
423 |
"""Validate opcode parameters, optionally setting default values.
|
424 |
|
425 |
@type set_defaults: bool
|
426 |
@param set_defaults: Whether to set default values
|
427 |
@raise errors.OpPrereqError: When a parameter value doesn't match
|
428 |
requirements
|
429 |
|
430 |
"""
|
431 |
for (attr_name, default, test, _) in self.GetAllParams(): |
432 |
assert test == ht.NoType or callable(test) |
433 |
|
434 |
if not hasattr(self, attr_name): |
435 |
if default == ht.NoDefault:
|
436 |
raise errors.OpPrereqError("Required parameter '%s.%s' missing" % |
437 |
(self.OP_ID, attr_name),
|
438 |
errors.ECODE_INVAL) |
439 |
elif set_defaults:
|
440 |
if callable(default): |
441 |
dval = default() |
442 |
else:
|
443 |
dval = default |
444 |
setattr(self, attr_name, dval) |
445 |
|
446 |
if test == ht.NoType:
|
447 |
# no tests here
|
448 |
continue
|
449 |
|
450 |
if set_defaults or hasattr(self, attr_name): |
451 |
attr_val = getattr(self, attr_name) |
452 |
if not test(attr_val): |
453 |
logging.error("OpCode %s, parameter %s, has invalid type %s/value %s",
|
454 |
self.OP_ID, attr_name, type(attr_val), attr_val) |
455 |
raise errors.OpPrereqError("Parameter '%s.%s' fails validation" % |
456 |
(self.OP_ID, attr_name),
|
457 |
errors.ECODE_INVAL) |
458 |
|
459 |
|
460 |
def _BuildJobDepCheck(relative): |
461 |
"""Builds check for job dependencies (L{DEPEND_ATTR}).
|
462 |
|
463 |
@type relative: bool
|
464 |
@param relative: Whether to accept relative job IDs (negative)
|
465 |
@rtype: callable
|
466 |
|
467 |
"""
|
468 |
if relative:
|
469 |
job_id = ht.TOr(ht.TJobId, ht.TRelativeJobId) |
470 |
else:
|
471 |
job_id = ht.TJobId |
472 |
|
473 |
job_dep = \ |
474 |
ht.TAnd(ht.TIsLength(2),
|
475 |
ht.TItems([job_id, |
476 |
ht.TListOf(ht.TElemOf(constants.JOBS_FINALIZED))])) |
477 |
|
478 |
return ht.TMaybeListOf(job_dep)
|
479 |
|
480 |
|
481 |
TNoRelativeJobDependencies = _BuildJobDepCheck(False)
|
482 |
|
483 |
#: List of submission status and job ID as returned by C{SubmitManyJobs}
|
484 |
_TJobIdListItem = \ |
485 |
ht.TAnd(ht.TIsLength(2),
|
486 |
ht.TItems([ht.Comment("success")(ht.TBool),
|
487 |
ht.Comment("Job ID if successful, error message"
|
488 |
" otherwise")(ht.TOr(ht.TString,
|
489 |
ht.TJobId))])) |
490 |
TJobIdList = ht.TListOf(_TJobIdListItem) |
491 |
|
492 |
#: Result containing only list of submitted jobs
|
493 |
TJobIdListOnly = ht.TStrictDict(True, True, { |
494 |
constants.JOB_IDS_KEY: ht.Comment("List of submitted jobs")(TJobIdList),
|
495 |
}) |
496 |
|
497 |
|
498 |
class OpCode(BaseOpCode): |
499 |
"""Abstract OpCode.
|
500 |
|
501 |
This is the root of the actual OpCode hierarchy. All clases derived
|
502 |
from this class should override OP_ID.
|
503 |
|
504 |
@cvar OP_ID: The ID of this opcode. This should be unique amongst all
|
505 |
children of this class.
|
506 |
@cvar OP_DSC_FIELD: The name of a field whose value will be included in the
|
507 |
string returned by Summary(); see the docstring of that
|
508 |
method for details).
|
509 |
@cvar OP_PARAMS: List of opcode attributes, the default values they should
|
510 |
get if not already defined, and types they must match.
|
511 |
@cvar OP_RESULT: Callable to verify opcode result
|
512 |
@cvar WITH_LU: Boolean that specifies whether this should be included in
|
513 |
mcpu's dispatch table
|
514 |
@ivar dry_run: Whether the LU should be run in dry-run mode, i.e. just
|
515 |
the check steps
|
516 |
@ivar priority: Opcode priority for queue
|
517 |
|
518 |
"""
|
519 |
# pylint: disable=E1101
|
520 |
# as OP_ID is dynamically defined
|
521 |
WITH_LU = True
|
522 |
OP_PARAMS = [ |
523 |
("dry_run", None, ht.TMaybeBool, "Run checks only, don't execute"), |
524 |
("debug_level", None, ht.TOr(ht.TNone, ht.TPositiveInt), "Debug level"), |
525 |
("priority", constants.OP_PRIO_DEFAULT,
|
526 |
ht.TElemOf(constants.OP_PRIO_SUBMIT_VALID), "Opcode priority"),
|
527 |
(DEPEND_ATTR, None, _BuildJobDepCheck(True), |
528 |
"Job dependencies; if used through ``SubmitManyJobs`` relative (negative)"
|
529 |
" job IDs can be used; see :doc:`design document <design-chained-jobs>`"
|
530 |
" for details"),
|
531 |
(COMMENT_ATTR, None, ht.TMaybeString,
|
532 |
"Comment describing the purpose of the opcode"),
|
533 |
] |
534 |
OP_RESULT = None
|
535 |
|
536 |
def __getstate__(self): |
537 |
"""Specialized getstate for opcodes.
|
538 |
|
539 |
This method adds to the state dictionary the OP_ID of the class,
|
540 |
so that on unload we can identify the correct class for
|
541 |
instantiating the opcode.
|
542 |
|
543 |
@rtype: C{dict}
|
544 |
@return: the state as a dictionary
|
545 |
|
546 |
"""
|
547 |
data = BaseOpCode.__getstate__(self)
|
548 |
data["OP_ID"] = self.OP_ID |
549 |
return data
|
550 |
|
551 |
@classmethod
|
552 |
def LoadOpCode(cls, data): |
553 |
"""Generic load opcode method.
|
554 |
|
555 |
The method identifies the correct opcode class from the dict-form
|
556 |
by looking for a OP_ID key, if this is not found, or its value is
|
557 |
not available in this module as a child of this class, we fail.
|
558 |
|
559 |
@type data: C{dict}
|
560 |
@param data: the serialized opcode
|
561 |
|
562 |
"""
|
563 |
if not isinstance(data, dict): |
564 |
raise ValueError("Invalid data to LoadOpCode (%s)" % type(data)) |
565 |
if "OP_ID" not in data: |
566 |
raise ValueError("Invalid data to LoadOpcode, missing OP_ID") |
567 |
op_id = data["OP_ID"]
|
568 |
op_class = None
|
569 |
if op_id in OP_MAPPING: |
570 |
op_class = OP_MAPPING[op_id] |
571 |
else:
|
572 |
raise ValueError("Invalid data to LoadOpCode: OP_ID %s unsupported" % |
573 |
op_id) |
574 |
op = op_class() |
575 |
new_data = data.copy() |
576 |
del new_data["OP_ID"] |
577 |
op.__setstate__(new_data) |
578 |
return op
|
579 |
|
580 |
def Summary(self): |
581 |
"""Generates a summary description of this opcode.
|
582 |
|
583 |
The summary is the value of the OP_ID attribute (without the "OP_"
|
584 |
prefix), plus the value of the OP_DSC_FIELD attribute, if one was
|
585 |
defined; this field should allow to easily identify the operation
|
586 |
(for an instance creation job, e.g., it would be the instance
|
587 |
name).
|
588 |
|
589 |
"""
|
590 |
assert self.OP_ID is not None and len(self.OP_ID) > 3 |
591 |
# all OP_ID start with OP_, we remove that
|
592 |
txt = self.OP_ID[3:] |
593 |
field_name = getattr(self, "OP_DSC_FIELD", None) |
594 |
if field_name:
|
595 |
field_value = getattr(self, field_name, None) |
596 |
if isinstance(field_value, (list, tuple)): |
597 |
field_value = ",".join(str(i) for i in field_value) |
598 |
txt = "%s(%s)" % (txt, field_value)
|
599 |
return txt
|
600 |
|
601 |
def TinySummary(self): |
602 |
"""Generates a compact summary description of the opcode.
|
603 |
|
604 |
"""
|
605 |
assert self.OP_ID.startswith("OP_") |
606 |
|
607 |
text = self.OP_ID[3:] |
608 |
|
609 |
for (prefix, supplement) in _SUMMARY_PREFIX.items(): |
610 |
if text.startswith(prefix):
|
611 |
return supplement + text[len(prefix):] |
612 |
|
613 |
return text
|
614 |
|
615 |
|
616 |
# cluster opcodes
|
617 |
|
618 |
class OpClusterPostInit(OpCode): |
619 |
"""Post cluster initialization.
|
620 |
|
621 |
This opcode does not touch the cluster at all. Its purpose is to run hooks
|
622 |
after the cluster has been initialized.
|
623 |
|
624 |
"""
|
625 |
OP_RESULT = ht.TBool |
626 |
|
627 |
|
628 |
class OpClusterDestroy(OpCode): |
629 |
"""Destroy the cluster.
|
630 |
|
631 |
This opcode has no other parameters. All the state is irreversibly
|
632 |
lost after the execution of this opcode.
|
633 |
|
634 |
"""
|
635 |
OP_RESULT = ht.TNonEmptyString |
636 |
|
637 |
|
638 |
class OpClusterQuery(OpCode): |
639 |
"""Query cluster information."""
|
640 |
|
641 |
|
642 |
class OpClusterVerify(OpCode): |
643 |
"""Submits all jobs necessary to verify the cluster.
|
644 |
|
645 |
"""
|
646 |
OP_PARAMS = [ |
647 |
_PDebugSimulateErrors, |
648 |
_PErrorCodes, |
649 |
_PSkipChecks, |
650 |
_PIgnoreErrors, |
651 |
_PVerbose, |
652 |
("group_name", None, ht.TMaybeString, "Group to verify") |
653 |
] |
654 |
OP_RESULT = TJobIdListOnly |
655 |
|
656 |
|
657 |
class OpClusterVerifyConfig(OpCode): |
658 |
"""Verify the cluster config.
|
659 |
|
660 |
"""
|
661 |
OP_PARAMS = [ |
662 |
_PDebugSimulateErrors, |
663 |
_PErrorCodes, |
664 |
_PIgnoreErrors, |
665 |
_PVerbose, |
666 |
] |
667 |
OP_RESULT = ht.TBool |
668 |
|
669 |
|
670 |
class OpClusterVerifyGroup(OpCode): |
671 |
"""Run verify on a node group from the cluster.
|
672 |
|
673 |
@type skip_checks: C{list}
|
674 |
@ivar skip_checks: steps to be skipped from the verify process; this
|
675 |
needs to be a subset of
|
676 |
L{constants.VERIFY_OPTIONAL_CHECKS}; currently
|
677 |
only L{constants.VERIFY_NPLUSONE_MEM} can be passed
|
678 |
|
679 |
"""
|
680 |
OP_DSC_FIELD = "group_name"
|
681 |
OP_PARAMS = [ |
682 |
_PGroupName, |
683 |
_PDebugSimulateErrors, |
684 |
_PErrorCodes, |
685 |
_PSkipChecks, |
686 |
_PIgnoreErrors, |
687 |
_PVerbose, |
688 |
] |
689 |
OP_RESULT = ht.TBool |
690 |
|
691 |
|
692 |
class OpClusterVerifyDisks(OpCode): |
693 |
"""Verify the cluster disks.
|
694 |
|
695 |
"""
|
696 |
OP_RESULT = TJobIdListOnly |
697 |
|
698 |
|
699 |
class OpGroupVerifyDisks(OpCode): |
700 |
"""Verifies the status of all disks in a node group.
|
701 |
|
702 |
Result: a tuple of three elements:
|
703 |
- dict of node names with issues (values: error msg)
|
704 |
- list of instances with degraded disks (that should be activated)
|
705 |
- dict of instances with missing logical volumes (values: (node, vol)
|
706 |
pairs with details about the missing volumes)
|
707 |
|
708 |
In normal operation, all lists should be empty. A non-empty instance
|
709 |
list (3rd element of the result) is still ok (errors were fixed) but
|
710 |
non-empty node list means some node is down, and probably there are
|
711 |
unfixable drbd errors.
|
712 |
|
713 |
Note that only instances that are drbd-based are taken into
|
714 |
consideration. This might need to be revisited in the future.
|
715 |
|
716 |
"""
|
717 |
OP_DSC_FIELD = "group_name"
|
718 |
OP_PARAMS = [ |
719 |
_PGroupName, |
720 |
] |
721 |
OP_RESULT = \ |
722 |
ht.TAnd(ht.TIsLength(3),
|
723 |
ht.TItems([ht.TDictOf(ht.TString, ht.TString), |
724 |
ht.TListOf(ht.TString), |
725 |
ht.TDictOf(ht.TString, |
726 |
ht.TListOf(ht.TListOf(ht.TString)))])) |
727 |
|
728 |
|
729 |
class OpClusterRepairDiskSizes(OpCode): |
730 |
"""Verify the disk sizes of the instances and fixes configuration
|
731 |
mimatches.
|
732 |
|
733 |
Parameters: optional instances list, in case we want to restrict the
|
734 |
checks to only a subset of the instances.
|
735 |
|
736 |
Result: a list of tuples, (instance, disk, new-size) for changed
|
737 |
configurations.
|
738 |
|
739 |
In normal operation, the list should be empty.
|
740 |
|
741 |
@type instances: list
|
742 |
@ivar instances: the list of instances to check, or empty for all instances
|
743 |
|
744 |
"""
|
745 |
OP_PARAMS = [ |
746 |
("instances", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), None), |
747 |
] |
748 |
OP_RESULT = ht.TListOf(ht.TAnd(ht.TIsLength(3),
|
749 |
ht.TItems([ht.TNonEmptyString, |
750 |
ht.TPositiveInt, |
751 |
ht.TPositiveInt]))) |
752 |
|
753 |
|
754 |
class OpClusterConfigQuery(OpCode): |
755 |
"""Query cluster configuration values."""
|
756 |
OP_PARAMS = [ |
757 |
_POutputFields |
758 |
] |
759 |
OP_RESULT = ht.TListOf(ht.TAny) |
760 |
|
761 |
|
762 |
class OpClusterRename(OpCode): |
763 |
"""Rename the cluster.
|
764 |
|
765 |
@type name: C{str}
|
766 |
@ivar name: The new name of the cluster. The name and/or the master IP
|
767 |
address will be changed to match the new name and its IP
|
768 |
address.
|
769 |
|
770 |
"""
|
771 |
OP_DSC_FIELD = "name"
|
772 |
OP_PARAMS = [ |
773 |
("name", ht.NoDefault, ht.TNonEmptyString, None), |
774 |
] |
775 |
OP_RESULT = ht.TNonEmptyString |
776 |
|
777 |
|
778 |
class OpClusterSetParams(OpCode): |
779 |
"""Change the parameters of the cluster.
|
780 |
|
781 |
@type vg_name: C{str} or C{None}
|
782 |
@ivar vg_name: The new volume group name or None to disable LVM usage.
|
783 |
|
784 |
"""
|
785 |
OP_PARAMS = [ |
786 |
_PHvState, |
787 |
_PDiskState, |
788 |
("vg_name", None, ht.TMaybeString, "Volume group name"), |
789 |
("enabled_hypervisors", None, |
790 |
ht.TOr(ht.TAnd(ht.TListOf(ht.TElemOf(constants.HYPER_TYPES)), ht.TTrue), |
791 |
ht.TNone), |
792 |
"List of enabled hypervisors"),
|
793 |
("hvparams", None, ht.TOr(ht.TDictOf(ht.TNonEmptyString, ht.TDict), |
794 |
ht.TNone), |
795 |
"Cluster-wide hypervisor parameter defaults, hypervisor-dependent"),
|
796 |
("beparams", None, ht.TOr(ht.TDict, ht.TNone), |
797 |
"Cluster-wide backend parameter defaults"),
|
798 |
("os_hvp", None, ht.TOr(ht.TDictOf(ht.TNonEmptyString, ht.TDict), |
799 |
ht.TNone), |
800 |
"Cluster-wide per-OS hypervisor parameter defaults"),
|
801 |
("osparams", None, ht.TOr(ht.TDictOf(ht.TNonEmptyString, ht.TDict), |
802 |
ht.TNone), |
803 |
"Cluster-wide OS parameter defaults"),
|
804 |
_PDiskParams, |
805 |
("candidate_pool_size", None, ht.TOr(ht.TStrictPositiveInt, ht.TNone), |
806 |
"Master candidate pool size"),
|
807 |
("uid_pool", None, ht.NoType, |
808 |
"Set UID pool, must be list of lists describing UID ranges (two items,"
|
809 |
" start and end inclusive)"),
|
810 |
("add_uids", None, ht.NoType, |
811 |
"Extend UID pool, must be list of lists describing UID ranges (two"
|
812 |
" items, start and end inclusive) to be added"),
|
813 |
("remove_uids", None, ht.NoType, |
814 |
"Shrink UID pool, must be list of lists describing UID ranges (two"
|
815 |
" items, start and end inclusive) to be removed"),
|
816 |
("maintain_node_health", None, ht.TMaybeBool, |
817 |
"Whether to automatically maintain node health"),
|
818 |
("prealloc_wipe_disks", None, ht.TMaybeBool, |
819 |
"Whether to wipe disks before allocating them to instances"),
|
820 |
("nicparams", None, ht.TMaybeDict, "Cluster-wide NIC parameter defaults"), |
821 |
("ndparams", None, ht.TMaybeDict, "Cluster-wide node parameter defaults"), |
822 |
("ipolicy", None, ht.TMaybeDict, |
823 |
"Cluster-wide :ref:`instance policy <rapi-ipolicy>` specs"),
|
824 |
("drbd_helper", None, ht.TOr(ht.TString, ht.TNone), "DRBD helper program"), |
825 |
("default_iallocator", None, ht.TOr(ht.TString, ht.TNone), |
826 |
"Default iallocator for cluster"),
|
827 |
("master_netdev", None, ht.TOr(ht.TString, ht.TNone), |
828 |
"Master network device"),
|
829 |
("master_netmask", None, ht.TOr(ht.TInt, ht.TNone), |
830 |
"Netmask of the master IP"),
|
831 |
("reserved_lvs", None, ht.TMaybeListOf(ht.TNonEmptyString), |
832 |
"List of reserved LVs"),
|
833 |
("hidden_os", None, _TestClusterOsList, |
834 |
"Modify list of hidden operating systems. Each modification must have"
|
835 |
" two items, the operation and the OS name. The operation can be"
|
836 |
" ``%s`` or ``%s``." % (constants.DDM_ADD, constants.DDM_REMOVE)),
|
837 |
("blacklisted_os", None, _TestClusterOsList, |
838 |
"Modify list of blacklisted operating systems. Each modification must have"
|
839 |
" two items, the operation and the OS name. The operation can be"
|
840 |
" ``%s`` or ``%s``." % (constants.DDM_ADD, constants.DDM_REMOVE)),
|
841 |
("use_external_mip_script", None, ht.TMaybeBool, |
842 |
"Whether to use an external master IP address setup script"),
|
843 |
] |
844 |
OP_RESULT = ht.TNone |
845 |
|
846 |
|
847 |
class OpClusterRedistConf(OpCode): |
848 |
"""Force a full push of the cluster configuration.
|
849 |
|
850 |
"""
|
851 |
OP_RESULT = ht.TNone |
852 |
|
853 |
|
854 |
class OpClusterActivateMasterIp(OpCode): |
855 |
"""Activate the master IP on the master node.
|
856 |
|
857 |
"""
|
858 |
OP_RESULT = ht.TNone |
859 |
|
860 |
|
861 |
class OpClusterDeactivateMasterIp(OpCode): |
862 |
"""Deactivate the master IP on the master node.
|
863 |
|
864 |
"""
|
865 |
OP_RESULT = ht.TNone |
866 |
|
867 |
|
868 |
class OpQuery(OpCode): |
869 |
"""Query for resources/items.
|
870 |
|
871 |
@ivar what: Resources to query for, must be one of L{constants.QR_VIA_OP}
|
872 |
@ivar fields: List of fields to retrieve
|
873 |
@ivar qfilter: Query filter
|
874 |
|
875 |
"""
|
876 |
OP_DSC_FIELD = "what"
|
877 |
OP_PARAMS = [ |
878 |
_PQueryWhat, |
879 |
_PUseLocking, |
880 |
("fields", ht.NoDefault, ht.TListOf(ht.TNonEmptyString),
|
881 |
"Requested fields"),
|
882 |
("qfilter", None, ht.TOr(ht.TNone, ht.TListOf), |
883 |
"Query filter"),
|
884 |
] |
885 |
|
886 |
|
887 |
class OpQueryFields(OpCode): |
888 |
"""Query for available resource/item fields.
|
889 |
|
890 |
@ivar what: Resources to query for, must be one of L{constants.QR_VIA_OP}
|
891 |
@ivar fields: List of fields to retrieve
|
892 |
|
893 |
"""
|
894 |
OP_DSC_FIELD = "what"
|
895 |
OP_PARAMS = [ |
896 |
_PQueryWhat, |
897 |
("fields", None, ht.TMaybeListOf(ht.TNonEmptyString), |
898 |
"Requested fields; if not given, all are returned"),
|
899 |
] |
900 |
|
901 |
|
902 |
class OpOobCommand(OpCode): |
903 |
"""Interact with OOB."""
|
904 |
OP_PARAMS = [ |
905 |
("node_names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
|
906 |
"List of nodes to run the OOB command against"),
|
907 |
("command", None, ht.TElemOf(constants.OOB_COMMANDS), |
908 |
"OOB command to be run"),
|
909 |
("timeout", constants.OOB_TIMEOUT, ht.TInt,
|
910 |
"Timeout before the OOB helper will be terminated"),
|
911 |
("ignore_status", False, ht.TBool, |
912 |
"Ignores the node offline status for power off"),
|
913 |
("power_delay", constants.OOB_POWER_DELAY, ht.TPositiveFloat,
|
914 |
"Time in seconds to wait between powering on nodes"),
|
915 |
] |
916 |
# Fixme: Make it more specific with all the special cases in LUOobCommand
|
917 |
OP_RESULT = ht.TListOf(ht.TAnd(ht.TIsLength(2),
|
918 |
ht.TItems([ht.TElemOf(constants.RS_ALL), |
919 |
ht.TAny]))) |
920 |
|
921 |
|
922 |
# node opcodes
|
923 |
|
924 |
class OpNodeRemove(OpCode): |
925 |
"""Remove a node.
|
926 |
|
927 |
@type node_name: C{str}
|
928 |
@ivar node_name: The name of the node to remove. If the node still has
|
929 |
instances on it, the operation will fail.
|
930 |
|
931 |
"""
|
932 |
OP_DSC_FIELD = "node_name"
|
933 |
OP_PARAMS = [ |
934 |
_PNodeName, |
935 |
] |
936 |
OP_RESULT = ht.TNone |
937 |
|
938 |
|
939 |
class OpNodeAdd(OpCode): |
940 |
"""Add a node to the cluster.
|
941 |
|
942 |
@type node_name: C{str}
|
943 |
@ivar node_name: The name of the node to add. This can be a short name,
|
944 |
but it will be expanded to the FQDN.
|
945 |
@type primary_ip: IP address
|
946 |
@ivar primary_ip: The primary IP of the node. This will be ignored when the
|
947 |
opcode is submitted, but will be filled during the node
|
948 |
add (so it will be visible in the job query).
|
949 |
@type secondary_ip: IP address
|
950 |
@ivar secondary_ip: The secondary IP of the node. This needs to be passed
|
951 |
if the cluster has been initialized in 'dual-network'
|
952 |
mode, otherwise it must not be given.
|
953 |
@type readd: C{bool}
|
954 |
@ivar readd: Whether to re-add an existing node to the cluster. If
|
955 |
this is not passed, then the operation will abort if the node
|
956 |
name is already in the cluster; use this parameter to 'repair'
|
957 |
a node that had its configuration broken, or was reinstalled
|
958 |
without removal from the cluster.
|
959 |
@type group: C{str}
|
960 |
@ivar group: The node group to which this node will belong.
|
961 |
@type vm_capable: C{bool}
|
962 |
@ivar vm_capable: The vm_capable node attribute
|
963 |
@type master_capable: C{bool}
|
964 |
@ivar master_capable: The master_capable node attribute
|
965 |
|
966 |
"""
|
967 |
OP_DSC_FIELD = "node_name"
|
968 |
OP_PARAMS = [ |
969 |
_PNodeName, |
970 |
_PHvState, |
971 |
_PDiskState, |
972 |
("primary_ip", None, ht.NoType, "Primary IP address"), |
973 |
("secondary_ip", None, ht.TMaybeString, "Secondary IP address"), |
974 |
("readd", False, ht.TBool, "Whether node is re-added to cluster"), |
975 |
("group", None, ht.TMaybeString, "Initial node group"), |
976 |
("master_capable", None, ht.TMaybeBool, |
977 |
"Whether node can become master or master candidate"),
|
978 |
("vm_capable", None, ht.TMaybeBool, |
979 |
"Whether node can host instances"),
|
980 |
("ndparams", None, ht.TMaybeDict, "Node parameters"), |
981 |
] |
982 |
OP_RESULT = ht.TNone |
983 |
|
984 |
|
985 |
class OpNodeQuery(OpCode): |
986 |
"""Compute the list of nodes."""
|
987 |
OP_PARAMS = [ |
988 |
_POutputFields, |
989 |
_PUseLocking, |
990 |
("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
|
991 |
"Empty list to query all nodes, node names otherwise"),
|
992 |
] |
993 |
|
994 |
|
995 |
class OpNodeQueryvols(OpCode): |
996 |
"""Get list of volumes on node."""
|
997 |
OP_PARAMS = [ |
998 |
_POutputFields, |
999 |
("nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
|
1000 |
"Empty list to query all nodes, node names otherwise"),
|
1001 |
] |
1002 |
OP_RESULT = ht.TListOf(ht.TAny) |
1003 |
|
1004 |
|
1005 |
class OpNodeQueryStorage(OpCode): |
1006 |
"""Get information on storage for node(s)."""
|
1007 |
OP_PARAMS = [ |
1008 |
_POutputFields, |
1009 |
_PStorageType, |
1010 |
("nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), "List of nodes"), |
1011 |
("name", None, ht.TMaybeString, "Storage name"), |
1012 |
] |
1013 |
|
1014 |
|
1015 |
class OpNodeModifyStorage(OpCode): |
1016 |
"""Modifies the properies of a storage unit"""
|
1017 |
OP_PARAMS = [ |
1018 |
_PNodeName, |
1019 |
_PStorageType, |
1020 |
_PStorageName, |
1021 |
("changes", ht.NoDefault, ht.TDict, "Requested changes"), |
1022 |
] |
1023 |
OP_RESULT = ht.TNone |
1024 |
|
1025 |
|
1026 |
class OpRepairNodeStorage(OpCode): |
1027 |
"""Repairs the volume group on a node."""
|
1028 |
OP_DSC_FIELD = "node_name"
|
1029 |
OP_PARAMS = [ |
1030 |
_PNodeName, |
1031 |
_PStorageType, |
1032 |
_PStorageName, |
1033 |
_PIgnoreConsistency, |
1034 |
] |
1035 |
OP_RESULT = ht.TNone |
1036 |
|
1037 |
|
1038 |
class OpNodeSetParams(OpCode): |
1039 |
"""Change the parameters of a node."""
|
1040 |
OP_DSC_FIELD = "node_name"
|
1041 |
OP_PARAMS = [ |
1042 |
_PNodeName, |
1043 |
_PForce, |
1044 |
_PHvState, |
1045 |
_PDiskState, |
1046 |
("master_candidate", None, ht.TMaybeBool, |
1047 |
"Whether the node should become a master candidate"),
|
1048 |
("offline", None, ht.TMaybeBool, |
1049 |
"Whether the node should be marked as offline"),
|
1050 |
("drained", None, ht.TMaybeBool, |
1051 |
"Whether the node should be marked as drained"),
|
1052 |
("auto_promote", False, ht.TBool, |
1053 |
"Whether node(s) should be promoted to master candidate if necessary"),
|
1054 |
("master_capable", None, ht.TMaybeBool, |
1055 |
"Denote whether node can become master or master candidate"),
|
1056 |
("vm_capable", None, ht.TMaybeBool, |
1057 |
"Denote whether node can host instances"),
|
1058 |
("secondary_ip", None, ht.TMaybeString, |
1059 |
"Change node's secondary IP address"),
|
1060 |
("ndparams", None, ht.TMaybeDict, "Set node parameters"), |
1061 |
("powered", None, ht.TMaybeBool, |
1062 |
"Whether the node should be marked as powered"),
|
1063 |
] |
1064 |
OP_RESULT = _TSetParamsResult |
1065 |
|
1066 |
|
1067 |
class OpNodePowercycle(OpCode): |
1068 |
"""Tries to powercycle a node."""
|
1069 |
OP_DSC_FIELD = "node_name"
|
1070 |
OP_PARAMS = [ |
1071 |
_PNodeName, |
1072 |
_PForce, |
1073 |
] |
1074 |
OP_RESULT = ht.TMaybeString |
1075 |
|
1076 |
|
1077 |
class OpNodeMigrate(OpCode): |
1078 |
"""Migrate all instances from a node."""
|
1079 |
OP_DSC_FIELD = "node_name"
|
1080 |
OP_PARAMS = [ |
1081 |
_PNodeName, |
1082 |
_PMigrationMode, |
1083 |
_PMigrationLive, |
1084 |
_PMigrationTargetNode, |
1085 |
_PAllowRuntimeChgs, |
1086 |
_PIgnoreIpolicy, |
1087 |
("iallocator", None, ht.TMaybeString, |
1088 |
"Iallocator for deciding the target node for shared-storage instances"),
|
1089 |
] |
1090 |
OP_RESULT = TJobIdListOnly |
1091 |
|
1092 |
|
1093 |
class OpNodeEvacuate(OpCode): |
1094 |
"""Evacuate instances off a number of nodes."""
|
1095 |
OP_DSC_FIELD = "node_name"
|
1096 |
OP_PARAMS = [ |
1097 |
_PEarlyRelease, |
1098 |
_PNodeName, |
1099 |
("remote_node", None, ht.TMaybeString, "New secondary node"), |
1100 |
("iallocator", None, ht.TMaybeString, "Iallocator for computing solution"), |
1101 |
("mode", ht.NoDefault, ht.TElemOf(constants.NODE_EVAC_MODES),
|
1102 |
"Node evacuation mode"),
|
1103 |
] |
1104 |
OP_RESULT = TJobIdListOnly |
1105 |
|
1106 |
|
1107 |
# instance opcodes
|
1108 |
|
1109 |
class OpInstanceCreate(OpCode): |
1110 |
"""Create an instance.
|
1111 |
|
1112 |
@ivar instance_name: Instance name
|
1113 |
@ivar mode: Instance creation mode (one of L{constants.INSTANCE_CREATE_MODES})
|
1114 |
@ivar source_handshake: Signed handshake from source (remote import only)
|
1115 |
@ivar source_x509_ca: Source X509 CA in PEM format (remote import only)
|
1116 |
@ivar source_instance_name: Previous name of instance (remote import only)
|
1117 |
@ivar source_shutdown_timeout: Shutdown timeout used for source instance
|
1118 |
(remote import only)
|
1119 |
|
1120 |
"""
|
1121 |
OP_DSC_FIELD = "instance_name"
|
1122 |
OP_PARAMS = [ |
1123 |
_PInstanceName, |
1124 |
_PForceVariant, |
1125 |
_PWaitForSync, |
1126 |
_PNameCheck, |
1127 |
_PIgnoreIpolicy, |
1128 |
("beparams", ht.EmptyDict, ht.TDict, "Backend parameters for instance"), |
1129 |
("disks", ht.NoDefault, ht.TListOf(_TDiskParams),
|
1130 |
"Disk descriptions, for example ``[{\"%s\": 100}, {\"%s\": 5}]``;"
|
1131 |
" each disk definition must contain a ``%s`` value and"
|
1132 |
" can contain an optional ``%s`` value denoting the disk access mode"
|
1133 |
" (%s)" %
|
1134 |
(constants.IDISK_SIZE, constants.IDISK_SIZE, constants.IDISK_SIZE, |
1135 |
constants.IDISK_MODE, |
1136 |
" or ".join("``%s``" % i for i in sorted(constants.DISK_ACCESS_SET)))), |
1137 |
("disk_template", ht.NoDefault, _BuildDiskTemplateCheck(True), |
1138 |
"Disk template"),
|
1139 |
("file_driver", None, ht.TOr(ht.TNone, ht.TElemOf(constants.FILE_DRIVER)), |
1140 |
"Driver for file-backed disks"),
|
1141 |
("file_storage_dir", None, ht.TMaybeString, |
1142 |
"Directory for storing file-backed disks"),
|
1143 |
("hvparams", ht.EmptyDict, ht.TDict,
|
1144 |
"Hypervisor parameters for instance, hypervisor-dependent"),
|
1145 |
("hypervisor", None, ht.TMaybeString, "Hypervisor"), |
1146 |
("iallocator", None, ht.TMaybeString, |
1147 |
"Iallocator for deciding which node(s) to use"),
|
1148 |
("identify_defaults", False, ht.TBool, |
1149 |
"Reset instance parameters to default if equal"),
|
1150 |
("ip_check", True, ht.TBool, _PIpCheckDoc), |
1151 |
("mode", ht.NoDefault, ht.TElemOf(constants.INSTANCE_CREATE_MODES),
|
1152 |
"Instance creation mode"),
|
1153 |
("nics", ht.NoDefault, ht.TListOf(_TestNicDef),
|
1154 |
"List of NIC (network interface) definitions, for example"
|
1155 |
" ``[{}, {}, {\"%s\": \"198.51.100.4\"}]``; each NIC definition can"
|
1156 |
" contain the optional values %s" %
|
1157 |
(constants.INIC_IP, |
1158 |
", ".join("``%s``" % i for i in sorted(constants.INIC_PARAMS)))), |
1159 |
("no_install", None, ht.TMaybeBool, |
1160 |
"Do not install the OS (will disable automatic start)"),
|
1161 |
("osparams", ht.EmptyDict, ht.TDict, "OS parameters for instance"), |
1162 |
("os_type", None, ht.TMaybeString, "Operating system"), |
1163 |
("pnode", None, ht.TMaybeString, "Primary node"), |
1164 |
("snode", None, ht.TMaybeString, "Secondary node"), |
1165 |
("source_handshake", None, ht.TOr(ht.TList, ht.TNone), |
1166 |
"Signed handshake from source (remote import only)"),
|
1167 |
("source_instance_name", None, ht.TMaybeString, |
1168 |
"Source instance name (remote import only)"),
|
1169 |
("source_shutdown_timeout", constants.DEFAULT_SHUTDOWN_TIMEOUT,
|
1170 |
ht.TPositiveInt, |
1171 |
"How long source instance was given to shut down (remote import only)"),
|
1172 |
("source_x509_ca", None, ht.TMaybeString, |
1173 |
"Source X509 CA in PEM format (remote import only)"),
|
1174 |
("src_node", None, ht.TMaybeString, "Source node for import"), |
1175 |
("src_path", None, ht.TMaybeString, "Source directory for import"), |
1176 |
("start", True, ht.TBool, "Whether to start instance after creation"), |
1177 |
("tags", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), "Instance tags"), |
1178 |
] |
1179 |
OP_RESULT = ht.Comment("instance nodes")(ht.TListOf(ht.TNonEmptyString))
|
1180 |
|
1181 |
|
1182 |
class OpInstanceReinstall(OpCode): |
1183 |
"""Reinstall an instance's OS."""
|
1184 |
OP_DSC_FIELD = "instance_name"
|
1185 |
OP_PARAMS = [ |
1186 |
_PInstanceName, |
1187 |
_PForceVariant, |
1188 |
("os_type", None, ht.TMaybeString, "Instance operating system"), |
1189 |
("osparams", None, ht.TMaybeDict, "Temporary OS parameters"), |
1190 |
] |
1191 |
OP_RESULT = ht.TNone |
1192 |
|
1193 |
|
1194 |
class OpInstanceRemove(OpCode): |
1195 |
"""Remove an instance."""
|
1196 |
OP_DSC_FIELD = "instance_name"
|
1197 |
OP_PARAMS = [ |
1198 |
_PInstanceName, |
1199 |
_PShutdownTimeout, |
1200 |
("ignore_failures", False, ht.TBool, |
1201 |
"Whether to ignore failures during removal"),
|
1202 |
] |
1203 |
OP_RESULT = ht.TNone |
1204 |
|
1205 |
|
1206 |
class OpInstanceRename(OpCode): |
1207 |
"""Rename an instance."""
|
1208 |
OP_PARAMS = [ |
1209 |
_PInstanceName, |
1210 |
_PNameCheck, |
1211 |
("new_name", ht.NoDefault, ht.TNonEmptyString, "New instance name"), |
1212 |
("ip_check", False, ht.TBool, _PIpCheckDoc), |
1213 |
] |
1214 |
OP_RESULT = ht.Comment("New instance name")(ht.TNonEmptyString)
|
1215 |
|
1216 |
|
1217 |
class OpInstanceStartup(OpCode): |
1218 |
"""Startup an instance."""
|
1219 |
OP_DSC_FIELD = "instance_name"
|
1220 |
OP_PARAMS = [ |
1221 |
_PInstanceName, |
1222 |
_PForce, |
1223 |
_PIgnoreOfflineNodes, |
1224 |
("hvparams", ht.EmptyDict, ht.TDict,
|
1225 |
"Temporary hypervisor parameters, hypervisor-dependent"),
|
1226 |
("beparams", ht.EmptyDict, ht.TDict, "Temporary backend parameters"), |
1227 |
_PNoRemember, |
1228 |
_PStartupPaused, |
1229 |
] |
1230 |
OP_RESULT = ht.TNone |
1231 |
|
1232 |
|
1233 |
class OpInstanceShutdown(OpCode): |
1234 |
"""Shutdown an instance."""
|
1235 |
OP_DSC_FIELD = "instance_name"
|
1236 |
OP_PARAMS = [ |
1237 |
_PInstanceName, |
1238 |
_PIgnoreOfflineNodes, |
1239 |
("timeout", constants.DEFAULT_SHUTDOWN_TIMEOUT, ht.TPositiveInt,
|
1240 |
"How long to wait for instance to shut down"),
|
1241 |
_PNoRemember, |
1242 |
] |
1243 |
OP_RESULT = ht.TNone |
1244 |
|
1245 |
|
1246 |
class OpInstanceReboot(OpCode): |
1247 |
"""Reboot an instance."""
|
1248 |
OP_DSC_FIELD = "instance_name"
|
1249 |
OP_PARAMS = [ |
1250 |
_PInstanceName, |
1251 |
_PShutdownTimeout, |
1252 |
("ignore_secondaries", False, ht.TBool, |
1253 |
"Whether to start the instance even if secondary disks are failing"),
|
1254 |
("reboot_type", ht.NoDefault, ht.TElemOf(constants.REBOOT_TYPES),
|
1255 |
"How to reboot instance"),
|
1256 |
] |
1257 |
OP_RESULT = ht.TNone |
1258 |
|
1259 |
|
1260 |
class OpInstanceReplaceDisks(OpCode): |
1261 |
"""Replace the disks of an instance."""
|
1262 |
OP_DSC_FIELD = "instance_name"
|
1263 |
OP_PARAMS = [ |
1264 |
_PInstanceName, |
1265 |
_PEarlyRelease, |
1266 |
_PIgnoreIpolicy, |
1267 |
("mode", ht.NoDefault, ht.TElemOf(constants.REPLACE_MODES),
|
1268 |
"Replacement mode"),
|
1269 |
("disks", ht.EmptyList, ht.TListOf(ht.TPositiveInt),
|
1270 |
"Disk indexes"),
|
1271 |
("remote_node", None, ht.TMaybeString, "New secondary node"), |
1272 |
("iallocator", None, ht.TMaybeString, |
1273 |
"Iallocator for deciding new secondary node"),
|
1274 |
] |
1275 |
OP_RESULT = ht.TNone |
1276 |
|
1277 |
|
1278 |
class OpInstanceFailover(OpCode): |
1279 |
"""Failover an instance."""
|
1280 |
OP_DSC_FIELD = "instance_name"
|
1281 |
OP_PARAMS = [ |
1282 |
_PInstanceName, |
1283 |
_PShutdownTimeout, |
1284 |
_PIgnoreConsistency, |
1285 |
_PMigrationTargetNode, |
1286 |
_PIgnoreIpolicy, |
1287 |
("iallocator", None, ht.TMaybeString, |
1288 |
"Iallocator for deciding the target node for shared-storage instances"),
|
1289 |
] |
1290 |
OP_RESULT = ht.TNone |
1291 |
|
1292 |
|
1293 |
class OpInstanceMigrate(OpCode): |
1294 |
"""Migrate an instance.
|
1295 |
|
1296 |
This migrates (without shutting down an instance) to its secondary
|
1297 |
node.
|
1298 |
|
1299 |
@ivar instance_name: the name of the instance
|
1300 |
@ivar mode: the migration mode (live, non-live or None for auto)
|
1301 |
|
1302 |
"""
|
1303 |
OP_DSC_FIELD = "instance_name"
|
1304 |
OP_PARAMS = [ |
1305 |
_PInstanceName, |
1306 |
_PMigrationMode, |
1307 |
_PMigrationLive, |
1308 |
_PMigrationTargetNode, |
1309 |
_PAllowRuntimeChgs, |
1310 |
_PIgnoreIpolicy, |
1311 |
("cleanup", False, ht.TBool, |
1312 |
"Whether a previously failed migration should be cleaned up"),
|
1313 |
("iallocator", None, ht.TMaybeString, |
1314 |
"Iallocator for deciding the target node for shared-storage instances"),
|
1315 |
("allow_failover", False, ht.TBool, |
1316 |
"Whether we can fallback to failover if migration is not possible"),
|
1317 |
] |
1318 |
OP_RESULT = ht.TNone |
1319 |
|
1320 |
|
1321 |
class OpInstanceMove(OpCode): |
1322 |
"""Move an instance.
|
1323 |
|
1324 |
This move (with shutting down an instance and data copying) to an
|
1325 |
arbitrary node.
|
1326 |
|
1327 |
@ivar instance_name: the name of the instance
|
1328 |
@ivar target_node: the destination node
|
1329 |
|
1330 |
"""
|
1331 |
OP_DSC_FIELD = "instance_name"
|
1332 |
OP_PARAMS = [ |
1333 |
_PInstanceName, |
1334 |
_PShutdownTimeout, |
1335 |
_PIgnoreIpolicy, |
1336 |
("target_node", ht.NoDefault, ht.TNonEmptyString, "Target node"), |
1337 |
_PIgnoreConsistency, |
1338 |
] |
1339 |
OP_RESULT = ht.TNone |
1340 |
|
1341 |
|
1342 |
class OpInstanceConsole(OpCode): |
1343 |
"""Connect to an instance's console."""
|
1344 |
OP_DSC_FIELD = "instance_name"
|
1345 |
OP_PARAMS = [ |
1346 |
_PInstanceName |
1347 |
] |
1348 |
OP_RESULT = ht.TDict |
1349 |
|
1350 |
|
1351 |
class OpInstanceActivateDisks(OpCode): |
1352 |
"""Activate an instance's disks."""
|
1353 |
OP_DSC_FIELD = "instance_name"
|
1354 |
OP_PARAMS = [ |
1355 |
_PInstanceName, |
1356 |
("ignore_size", False, ht.TBool, "Whether to ignore recorded size"), |
1357 |
] |
1358 |
OP_RESULT = ht.TListOf(ht.TAnd(ht.TIsLength(3),
|
1359 |
ht.TItems([ht.TNonEmptyString, |
1360 |
ht.TNonEmptyString, |
1361 |
ht.TNonEmptyString]))) |
1362 |
|
1363 |
|
1364 |
class OpInstanceDeactivateDisks(OpCode): |
1365 |
"""Deactivate an instance's disks."""
|
1366 |
OP_DSC_FIELD = "instance_name"
|
1367 |
OP_PARAMS = [ |
1368 |
_PInstanceName, |
1369 |
_PForce, |
1370 |
] |
1371 |
OP_RESULT = ht.TNone |
1372 |
|
1373 |
|
1374 |
class OpInstanceRecreateDisks(OpCode): |
1375 |
"""Recreate an instance's disks."""
|
1376 |
_TDiskChanges = \ |
1377 |
ht.TAnd(ht.TIsLength(2),
|
1378 |
ht.TItems([ht.Comment("Disk index")(ht.TPositiveInt),
|
1379 |
ht.Comment("Parameters")(_TDiskParams)]))
|
1380 |
|
1381 |
OP_DSC_FIELD = "instance_name"
|
1382 |
OP_PARAMS = [ |
1383 |
_PInstanceName, |
1384 |
("disks", ht.EmptyList,
|
1385 |
ht.TOr(ht.TListOf(ht.TPositiveInt), ht.TListOf(_TDiskChanges)), |
1386 |
"List of disk indexes (deprecated) or a list of tuples containing a disk"
|
1387 |
" index and a possibly empty dictionary with disk parameter changes"),
|
1388 |
("nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
|
1389 |
"New instance nodes, if relocation is desired"),
|
1390 |
] |
1391 |
OP_RESULT = ht.TNone |
1392 |
|
1393 |
|
1394 |
class OpInstanceQuery(OpCode): |
1395 |
"""Compute the list of instances."""
|
1396 |
OP_PARAMS = [ |
1397 |
_POutputFields, |
1398 |
_PUseLocking, |
1399 |
("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
|
1400 |
"Empty list to query all instances, instance names otherwise"),
|
1401 |
] |
1402 |
|
1403 |
|
1404 |
class OpInstanceQueryData(OpCode): |
1405 |
"""Compute the run-time status of instances."""
|
1406 |
OP_PARAMS = [ |
1407 |
_PUseLocking, |
1408 |
("instances", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
|
1409 |
"Instance names"),
|
1410 |
("static", False, ht.TBool, |
1411 |
"Whether to only return configuration data without querying"
|
1412 |
" nodes"),
|
1413 |
] |
1414 |
|
1415 |
|
1416 |
def _TestInstSetParamsModList(fn): |
1417 |
"""Generates a check for modification lists.
|
1418 |
|
1419 |
"""
|
1420 |
# Old format
|
1421 |
# TODO: Remove in version 2.8 including support in LUInstanceSetParams
|
1422 |
old_mod_item_fn = \ |
1423 |
ht.TAnd(ht.TIsLength(2), ht.TItems([
|
1424 |
ht.TOr(ht.TElemOf(constants.DDMS_VALUES), ht.TPositiveInt), |
1425 |
fn, |
1426 |
])) |
1427 |
|
1428 |
# New format, supporting adding/removing disks/NICs at arbitrary indices
|
1429 |
mod_item_fn = \ |
1430 |
ht.TAnd(ht.TIsLength(3), ht.TItems([
|
1431 |
ht.TElemOf(constants.DDMS_VALUES_WITH_MODIFY), |
1432 |
ht.Comment("Disk index, can be negative, e.g. -1 for last disk")(ht.TInt),
|
1433 |
fn, |
1434 |
])) |
1435 |
|
1436 |
return ht.TOr(ht.Comment("Recommended")(ht.TListOf(mod_item_fn)), |
1437 |
ht.Comment("Deprecated")(ht.TListOf(old_mod_item_fn)))
|
1438 |
|
1439 |
|
1440 |
class OpInstanceSetParams(OpCode): |
1441 |
"""Change the parameters of an instance.
|
1442 |
|
1443 |
"""
|
1444 |
TestNicModifications = _TestInstSetParamsModList(_TestNicDef) |
1445 |
TestDiskModifications = _TestInstSetParamsModList(_TDiskParams) |
1446 |
|
1447 |
OP_DSC_FIELD = "instance_name"
|
1448 |
OP_PARAMS = [ |
1449 |
_PInstanceName, |
1450 |
_PForce, |
1451 |
_PForceVariant, |
1452 |
_PIgnoreIpolicy, |
1453 |
("nics", ht.EmptyList, TestNicModifications,
|
1454 |
"List of NIC changes. Each item is of the form ``(op, index, settings)``."
|
1455 |
" ``op`` is one of ``%s``, ``%s`` or ``%s``. ``index`` can be either -1 to"
|
1456 |
" refer to the last position, or a zero-based index number. A deprecated"
|
1457 |
" version of this parameter used the form ``(op, settings)``, where "
|
1458 |
" ``op`` can be ``%s`` to add a new NIC with the specified settings,"
|
1459 |
" ``%s`` to remove the last NIC or a number to modify the settings"
|
1460 |
" of the NIC with that index." %
|
1461 |
(constants.DDM_ADD, constants.DDM_MODIFY, constants.DDM_REMOVE, |
1462 |
constants.DDM_ADD, constants.DDM_REMOVE)), |
1463 |
("disks", ht.EmptyList, TestDiskModifications,
|
1464 |
"List of disk changes. See ``nics``."),
|
1465 |
("beparams", ht.EmptyDict, ht.TDict, "Per-instance backend parameters"), |
1466 |
("runtime_mem", None, ht.TMaybeStrictPositiveInt, "New runtime memory"), |
1467 |
("hvparams", ht.EmptyDict, ht.TDict,
|
1468 |
"Per-instance hypervisor parameters, hypervisor-dependent"),
|
1469 |
("disk_template", None, ht.TOr(ht.TNone, _BuildDiskTemplateCheck(False)), |
1470 |
"Disk template for instance"),
|
1471 |
("remote_node", None, ht.TMaybeString, |
1472 |
"Secondary node (used when changing disk template)"),
|
1473 |
("os_name", None, ht.TMaybeString, |
1474 |
"Change instance's OS name. Does not reinstall the instance."),
|
1475 |
("osparams", None, ht.TMaybeDict, "Per-instance OS parameters"), |
1476 |
("wait_for_sync", True, ht.TBool, |
1477 |
"Whether to wait for the disk to synchronize, when changing template"),
|
1478 |
("offline", None, ht.TMaybeBool, "Whether to mark instance as offline"), |
1479 |
] |
1480 |
OP_RESULT = _TSetParamsResult |
1481 |
|
1482 |
|
1483 |
class OpInstanceGrowDisk(OpCode): |
1484 |
"""Grow a disk of an instance."""
|
1485 |
OP_DSC_FIELD = "instance_name"
|
1486 |
OP_PARAMS = [ |
1487 |
_PInstanceName, |
1488 |
_PWaitForSync, |
1489 |
("disk", ht.NoDefault, ht.TInt, "Disk index"), |
1490 |
("amount", ht.NoDefault, ht.TInt,
|
1491 |
"Amount of disk space to add (megabytes)"),
|
1492 |
] |
1493 |
OP_RESULT = ht.TNone |
1494 |
|
1495 |
|
1496 |
class OpInstanceChangeGroup(OpCode): |
1497 |
"""Moves an instance to another node group."""
|
1498 |
OP_DSC_FIELD = "instance_name"
|
1499 |
OP_PARAMS = [ |
1500 |
_PInstanceName, |
1501 |
_PEarlyRelease, |
1502 |
("iallocator", None, ht.TMaybeString, "Iallocator for computing solution"), |
1503 |
("target_groups", None, ht.TMaybeListOf(ht.TNonEmptyString), |
1504 |
"Destination group names or UUIDs (defaults to \"all but current group\""),
|
1505 |
] |
1506 |
OP_RESULT = TJobIdListOnly |
1507 |
|
1508 |
|
1509 |
# Node group opcodes
|
1510 |
|
1511 |
class OpGroupAdd(OpCode): |
1512 |
"""Add a node group to the cluster."""
|
1513 |
OP_DSC_FIELD = "group_name"
|
1514 |
OP_PARAMS = [ |
1515 |
_PGroupName, |
1516 |
_PNodeGroupAllocPolicy, |
1517 |
_PGroupNodeParams, |
1518 |
_PDiskParams, |
1519 |
_PHvState, |
1520 |
_PDiskState, |
1521 |
("ipolicy", None, ht.TMaybeDict, |
1522 |
"Group-wide :ref:`instance policy <rapi-ipolicy>` specs"),
|
1523 |
] |
1524 |
OP_RESULT = ht.TNone |
1525 |
|
1526 |
|
1527 |
class OpGroupAssignNodes(OpCode): |
1528 |
"""Assign nodes to a node group."""
|
1529 |
OP_DSC_FIELD = "group_name"
|
1530 |
OP_PARAMS = [ |
1531 |
_PGroupName, |
1532 |
_PForce, |
1533 |
("nodes", ht.NoDefault, ht.TListOf(ht.TNonEmptyString),
|
1534 |
"List of nodes to assign"),
|
1535 |
] |
1536 |
OP_RESULT = ht.TNone |
1537 |
|
1538 |
|
1539 |
class OpGroupQuery(OpCode): |
1540 |
"""Compute the list of node groups."""
|
1541 |
OP_PARAMS = [ |
1542 |
_POutputFields, |
1543 |
("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
|
1544 |
"Empty list to query all groups, group names otherwise"),
|
1545 |
] |
1546 |
|
1547 |
|
1548 |
class OpGroupSetParams(OpCode): |
1549 |
"""Change the parameters of a node group."""
|
1550 |
OP_DSC_FIELD = "group_name"
|
1551 |
OP_PARAMS = [ |
1552 |
_PGroupName, |
1553 |
_PNodeGroupAllocPolicy, |
1554 |
_PGroupNodeParams, |
1555 |
_PDiskParams, |
1556 |
_PHvState, |
1557 |
_PDiskState, |
1558 |
("ipolicy", None, ht.TMaybeDict, "Group-wide instance policy specs"), |
1559 |
] |
1560 |
OP_RESULT = _TSetParamsResult |
1561 |
|
1562 |
|
1563 |
class OpGroupRemove(OpCode): |
1564 |
"""Remove a node group from the cluster."""
|
1565 |
OP_DSC_FIELD = "group_name"
|
1566 |
OP_PARAMS = [ |
1567 |
_PGroupName, |
1568 |
] |
1569 |
OP_RESULT = ht.TNone |
1570 |
|
1571 |
|
1572 |
class OpGroupRename(OpCode): |
1573 |
"""Rename a node group in the cluster."""
|
1574 |
OP_PARAMS = [ |
1575 |
_PGroupName, |
1576 |
("new_name", ht.NoDefault, ht.TNonEmptyString, "New group name"), |
1577 |
] |
1578 |
OP_RESULT = ht.Comment("New group name")(ht.TNonEmptyString)
|
1579 |
|
1580 |
|
1581 |
class OpGroupEvacuate(OpCode): |
1582 |
"""Evacuate a node group in the cluster."""
|
1583 |
OP_DSC_FIELD = "group_name"
|
1584 |
OP_PARAMS = [ |
1585 |
_PGroupName, |
1586 |
_PEarlyRelease, |
1587 |
("iallocator", None, ht.TMaybeString, "Iallocator for computing solution"), |
1588 |
("target_groups", None, ht.TMaybeListOf(ht.TNonEmptyString), |
1589 |
"Destination group names or UUIDs"),
|
1590 |
] |
1591 |
OP_RESULT = TJobIdListOnly |
1592 |
|
1593 |
|
1594 |
# OS opcodes
|
1595 |
class OpOsDiagnose(OpCode): |
1596 |
"""Compute the list of guest operating systems."""
|
1597 |
OP_PARAMS = [ |
1598 |
_POutputFields, |
1599 |
("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
|
1600 |
"Which operating systems to diagnose"),
|
1601 |
] |
1602 |
|
1603 |
|
1604 |
# Exports opcodes
|
1605 |
class OpBackupQuery(OpCode): |
1606 |
"""Compute the list of exported images."""
|
1607 |
OP_PARAMS = [ |
1608 |
_PUseLocking, |
1609 |
("nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
|
1610 |
"Empty list to query all nodes, node names otherwise"),
|
1611 |
] |
1612 |
|
1613 |
|
1614 |
class OpBackupPrepare(OpCode): |
1615 |
"""Prepares an instance export.
|
1616 |
|
1617 |
@ivar instance_name: Instance name
|
1618 |
@ivar mode: Export mode (one of L{constants.EXPORT_MODES})
|
1619 |
|
1620 |
"""
|
1621 |
OP_DSC_FIELD = "instance_name"
|
1622 |
OP_PARAMS = [ |
1623 |
_PInstanceName, |
1624 |
("mode", ht.NoDefault, ht.TElemOf(constants.EXPORT_MODES),
|
1625 |
"Export mode"),
|
1626 |
] |
1627 |
OP_RESULT = ht.TOr(ht.TNone, ht.TDict) |
1628 |
|
1629 |
|
1630 |
class OpBackupExport(OpCode): |
1631 |
"""Export an instance.
|
1632 |
|
1633 |
For local exports, the export destination is the node name. For remote
|
1634 |
exports, the export destination is a list of tuples, each consisting of
|
1635 |
hostname/IP address, port, HMAC and HMAC salt. The HMAC is calculated using
|
1636 |
the cluster domain secret over the value "${index}:${hostname}:${port}". The
|
1637 |
destination X509 CA must be a signed certificate.
|
1638 |
|
1639 |
@ivar mode: Export mode (one of L{constants.EXPORT_MODES})
|
1640 |
@ivar target_node: Export destination
|
1641 |
@ivar x509_key_name: X509 key to use (remote export only)
|
1642 |
@ivar destination_x509_ca: Destination X509 CA in PEM format (remote export
|
1643 |
only)
|
1644 |
|
1645 |
"""
|
1646 |
OP_DSC_FIELD = "instance_name"
|
1647 |
OP_PARAMS = [ |
1648 |
_PInstanceName, |
1649 |
_PShutdownTimeout, |
1650 |
# TODO: Rename target_node as it changes meaning for different export modes
|
1651 |
# (e.g. "destination")
|
1652 |
("target_node", ht.NoDefault, ht.TOr(ht.TNonEmptyString, ht.TList),
|
1653 |
"Destination information, depends on export mode"),
|
1654 |
("shutdown", True, ht.TBool, "Whether to shutdown instance before export"), |
1655 |
("remove_instance", False, ht.TBool, |
1656 |
"Whether to remove instance after export"),
|
1657 |
("ignore_remove_failures", False, ht.TBool, |
1658 |
"Whether to ignore failures while removing instances"),
|
1659 |
("mode", constants.EXPORT_MODE_LOCAL, ht.TElemOf(constants.EXPORT_MODES),
|
1660 |
"Export mode"),
|
1661 |
("x509_key_name", None, ht.TOr(ht.TList, ht.TNone), |
1662 |
"Name of X509 key (remote export only)"),
|
1663 |
("destination_x509_ca", None, ht.TMaybeString, |
1664 |
"Destination X509 CA (remote export only)"),
|
1665 |
] |
1666 |
|
1667 |
|
1668 |
class OpBackupRemove(OpCode): |
1669 |
"""Remove an instance's export."""
|
1670 |
OP_DSC_FIELD = "instance_name"
|
1671 |
OP_PARAMS = [ |
1672 |
_PInstanceName, |
1673 |
] |
1674 |
|
1675 |
|
1676 |
# Tags opcodes
|
1677 |
class OpTagsGet(OpCode): |
1678 |
"""Returns the tags of the given object."""
|
1679 |
OP_DSC_FIELD = "name"
|
1680 |
OP_PARAMS = [ |
1681 |
_PTagKind, |
1682 |
# Name is only meaningful for nodes and instances
|
1683 |
("name", ht.NoDefault, ht.TMaybeString, None), |
1684 |
] |
1685 |
|
1686 |
|
1687 |
class OpTagsSearch(OpCode): |
1688 |
"""Searches the tags in the cluster for a given pattern."""
|
1689 |
OP_DSC_FIELD = "pattern"
|
1690 |
OP_PARAMS = [ |
1691 |
("pattern", ht.NoDefault, ht.TNonEmptyString, None), |
1692 |
] |
1693 |
|
1694 |
|
1695 |
class OpTagsSet(OpCode): |
1696 |
"""Add a list of tags on a given object."""
|
1697 |
OP_PARAMS = [ |
1698 |
_PTagKind, |
1699 |
_PTags, |
1700 |
# Name is only meaningful for nodes and instances
|
1701 |
("name", ht.NoDefault, ht.TMaybeString, None), |
1702 |
] |
1703 |
|
1704 |
|
1705 |
class OpTagsDel(OpCode): |
1706 |
"""Remove a list of tags from a given object."""
|
1707 |
OP_PARAMS = [ |
1708 |
_PTagKind, |
1709 |
_PTags, |
1710 |
# Name is only meaningful for nodes and instances
|
1711 |
("name", ht.NoDefault, ht.TMaybeString, None), |
1712 |
] |
1713 |
|
1714 |
|
1715 |
# Test opcodes
|
1716 |
class OpTestDelay(OpCode): |
1717 |
"""Sleeps for a configured amount of time.
|
1718 |
|
1719 |
This is used just for debugging and testing.
|
1720 |
|
1721 |
Parameters:
|
1722 |
- duration: the time to sleep
|
1723 |
- on_master: if true, sleep on the master
|
1724 |
- on_nodes: list of nodes in which to sleep
|
1725 |
|
1726 |
If the on_master parameter is true, it will execute a sleep on the
|
1727 |
master (before any node sleep).
|
1728 |
|
1729 |
If the on_nodes list is not empty, it will sleep on those nodes
|
1730 |
(after the sleep on the master, if that is enabled).
|
1731 |
|
1732 |
As an additional feature, the case of duration < 0 will be reported
|
1733 |
as an execution error, so this opcode can be used as a failure
|
1734 |
generator. The case of duration == 0 will not be treated specially.
|
1735 |
|
1736 |
"""
|
1737 |
OP_DSC_FIELD = "duration"
|
1738 |
OP_PARAMS = [ |
1739 |
("duration", ht.NoDefault, ht.TNumber, None), |
1740 |
("on_master", True, ht.TBool, None), |
1741 |
("on_nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), None), |
1742 |
("repeat", 0, ht.TPositiveInt, None), |
1743 |
] |
1744 |
|
1745 |
|
1746 |
class OpTestAllocator(OpCode): |
1747 |
"""Allocator framework testing.
|
1748 |
|
1749 |
This opcode has two modes:
|
1750 |
- gather and return allocator input for a given mode (allocate new
|
1751 |
or replace secondary) and a given instance definition (direction
|
1752 |
'in')
|
1753 |
- run a selected allocator for a given operation (as above) and
|
1754 |
return the allocator output (direction 'out')
|
1755 |
|
1756 |
"""
|
1757 |
OP_DSC_FIELD = "allocator"
|
1758 |
OP_PARAMS = [ |
1759 |
("direction", ht.NoDefault,
|
1760 |
ht.TElemOf(constants.VALID_IALLOCATOR_DIRECTIONS), None),
|
1761 |
("mode", ht.NoDefault, ht.TElemOf(constants.VALID_IALLOCATOR_MODES), None), |
1762 |
("name", ht.NoDefault, ht.TNonEmptyString, None), |
1763 |
("nics", ht.NoDefault,
|
1764 |
ht.TMaybeListOf(ht.TDictOf(ht.TElemOf([constants.INIC_MAC, |
1765 |
constants.INIC_IP, |
1766 |
"bridge"]),
|
1767 |
ht.TOr(ht.TNone, ht.TNonEmptyString))), |
1768 |
None),
|
1769 |
("disks", ht.NoDefault, ht.TOr(ht.TNone, ht.TList), None), |
1770 |
("hypervisor", None, ht.TMaybeString, None), |
1771 |
("allocator", None, ht.TMaybeString, None), |
1772 |
("tags", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), None), |
1773 |
("memory", None, ht.TOr(ht.TNone, ht.TPositiveInt), None), |
1774 |
("vcpus", None, ht.TOr(ht.TNone, ht.TPositiveInt), None), |
1775 |
("os", None, ht.TMaybeString, None), |
1776 |
("disk_template", None, ht.TMaybeString, None), |
1777 |
("instances", None, ht.TMaybeListOf(ht.TNonEmptyString), None), |
1778 |
("evac_mode", None, |
1779 |
ht.TOr(ht.TNone, ht.TElemOf(constants.IALLOCATOR_NEVAC_MODES)), None),
|
1780 |
("target_groups", None, ht.TMaybeListOf(ht.TNonEmptyString), None), |
1781 |
] |
1782 |
|
1783 |
|
1784 |
class OpTestJqueue(OpCode): |
1785 |
"""Utility opcode to test some aspects of the job queue.
|
1786 |
|
1787 |
"""
|
1788 |
OP_PARAMS = [ |
1789 |
("notify_waitlock", False, ht.TBool, None), |
1790 |
("notify_exec", False, ht.TBool, None), |
1791 |
("log_messages", ht.EmptyList, ht.TListOf(ht.TString), None), |
1792 |
("fail", False, ht.TBool, None), |
1793 |
] |
1794 |
|
1795 |
|
1796 |
class OpTestDummy(OpCode): |
1797 |
"""Utility opcode used by unittests.
|
1798 |
|
1799 |
"""
|
1800 |
OP_PARAMS = [ |
1801 |
("result", ht.NoDefault, ht.NoType, None), |
1802 |
("messages", ht.NoDefault, ht.NoType, None), |
1803 |
("fail", ht.NoDefault, ht.NoType, None), |
1804 |
("submit_jobs", None, ht.NoType, None), |
1805 |
] |
1806 |
WITH_LU = False
|
1807 |
|
1808 |
|
1809 |
def _GetOpList(): |
1810 |
"""Returns list of all defined opcodes.
|
1811 |
|
1812 |
Does not eliminate duplicates by C{OP_ID}.
|
1813 |
|
1814 |
"""
|
1815 |
return [v for v in globals().values() |
1816 |
if (isinstance(v, type) and issubclass(v, OpCode) and |
1817 |
hasattr(v, "OP_ID") and v is not OpCode)] |
1818 |
|
1819 |
|
1820 |
OP_MAPPING = dict((v.OP_ID, v) for v in _GetOpList()) |