root / lib / opcodes.py @ 08a61d91
History | View | Annotate | Download (21.8 kB)
1 |
#
|
---|---|
2 |
#
|
3 |
|
4 |
# Copyright (C) 2006, 2007, 2008, 2009, 2010 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 |
|
37 |
class BaseOpCode(object): |
38 |
"""A simple serializable object.
|
39 |
|
40 |
This object serves as a parent class for OpCode without any custom
|
41 |
field handling.
|
42 |
|
43 |
"""
|
44 |
__slots__ = [] |
45 |
|
46 |
def __init__(self, **kwargs): |
47 |
"""Constructor for BaseOpCode.
|
48 |
|
49 |
The constructor takes only keyword arguments and will set
|
50 |
attributes on this object based on the passed arguments. As such,
|
51 |
it means that you should not pass arguments which are not in the
|
52 |
__slots__ attribute for this class.
|
53 |
|
54 |
"""
|
55 |
slots = self._all_slots()
|
56 |
for key in kwargs: |
57 |
if key not in slots: |
58 |
raise TypeError("Object %s doesn't support the parameter '%s'" % |
59 |
(self.__class__.__name__, key))
|
60 |
setattr(self, key, kwargs[key]) |
61 |
|
62 |
def __getstate__(self): |
63 |
"""Generic serializer.
|
64 |
|
65 |
This method just returns the contents of the instance as a
|
66 |
dictionary.
|
67 |
|
68 |
@rtype: C{dict}
|
69 |
@return: the instance attributes and their values
|
70 |
|
71 |
"""
|
72 |
state = {} |
73 |
for name in self._all_slots(): |
74 |
if hasattr(self, name): |
75 |
state[name] = getattr(self, name) |
76 |
return state
|
77 |
|
78 |
def __setstate__(self, state): |
79 |
"""Generic unserializer.
|
80 |
|
81 |
This method just restores from the serialized state the attributes
|
82 |
of the current instance.
|
83 |
|
84 |
@param state: the serialized opcode data
|
85 |
@type state: C{dict}
|
86 |
|
87 |
"""
|
88 |
if not isinstance(state, dict): |
89 |
raise ValueError("Invalid data to __setstate__: expected dict, got %s" % |
90 |
type(state))
|
91 |
|
92 |
for name in self._all_slots(): |
93 |
if name not in state and hasattr(self, name): |
94 |
delattr(self, name) |
95 |
|
96 |
for name in state: |
97 |
setattr(self, name, state[name]) |
98 |
|
99 |
@classmethod
|
100 |
def _all_slots(cls): |
101 |
"""Compute the list of all declared slots for a class.
|
102 |
|
103 |
"""
|
104 |
slots = [] |
105 |
for parent in cls.__mro__: |
106 |
slots.extend(getattr(parent, "__slots__", [])) |
107 |
return slots
|
108 |
|
109 |
|
110 |
class OpCode(BaseOpCode): |
111 |
"""Abstract OpCode.
|
112 |
|
113 |
This is the root of the actual OpCode hierarchy. All clases derived
|
114 |
from this class should override OP_ID.
|
115 |
|
116 |
@cvar OP_ID: The ID of this opcode. This should be unique amongst all
|
117 |
children of this class.
|
118 |
@ivar dry_run: Whether the LU should be run in dry-run mode, i.e. just
|
119 |
the check steps
|
120 |
@ivar priority: Opcode priority for queue
|
121 |
|
122 |
"""
|
123 |
OP_ID = "OP_ABSTRACT"
|
124 |
__slots__ = ["dry_run", "debug_level", "priority"] |
125 |
|
126 |
def __getstate__(self): |
127 |
"""Specialized getstate for opcodes.
|
128 |
|
129 |
This method adds to the state dictionary the OP_ID of the class,
|
130 |
so that on unload we can identify the correct class for
|
131 |
instantiating the opcode.
|
132 |
|
133 |
@rtype: C{dict}
|
134 |
@return: the state as a dictionary
|
135 |
|
136 |
"""
|
137 |
data = BaseOpCode.__getstate__(self)
|
138 |
data["OP_ID"] = self.OP_ID |
139 |
return data
|
140 |
|
141 |
@classmethod
|
142 |
def LoadOpCode(cls, data): |
143 |
"""Generic load opcode method.
|
144 |
|
145 |
The method identifies the correct opcode class from the dict-form
|
146 |
by looking for a OP_ID key, if this is not found, or its value is
|
147 |
not available in this module as a child of this class, we fail.
|
148 |
|
149 |
@type data: C{dict}
|
150 |
@param data: the serialized opcode
|
151 |
|
152 |
"""
|
153 |
if not isinstance(data, dict): |
154 |
raise ValueError("Invalid data to LoadOpCode (%s)" % type(data)) |
155 |
if "OP_ID" not in data: |
156 |
raise ValueError("Invalid data to LoadOpcode, missing OP_ID") |
157 |
op_id = data["OP_ID"]
|
158 |
op_class = None
|
159 |
if op_id in OP_MAPPING: |
160 |
op_class = OP_MAPPING[op_id] |
161 |
else:
|
162 |
raise ValueError("Invalid data to LoadOpCode: OP_ID %s unsupported" % |
163 |
op_id) |
164 |
op = op_class() |
165 |
new_data = data.copy() |
166 |
del new_data["OP_ID"] |
167 |
op.__setstate__(new_data) |
168 |
return op
|
169 |
|
170 |
def Summary(self): |
171 |
"""Generates a summary description of this opcode.
|
172 |
|
173 |
"""
|
174 |
# all OP_ID start with OP_, we remove that
|
175 |
txt = self.OP_ID[3:] |
176 |
field_name = getattr(self, "OP_DSC_FIELD", None) |
177 |
if field_name:
|
178 |
field_value = getattr(self, field_name, None) |
179 |
if isinstance(field_value, (list, tuple)): |
180 |
field_value = ",".join(str(i) for i in field_value) |
181 |
txt = "%s(%s)" % (txt, field_value)
|
182 |
return txt
|
183 |
|
184 |
|
185 |
# cluster opcodes
|
186 |
|
187 |
class OpPostInitCluster(OpCode): |
188 |
"""Post cluster initialization.
|
189 |
|
190 |
This opcode does not touch the cluster at all. Its purpose is to run hooks
|
191 |
after the cluster has been initialized.
|
192 |
|
193 |
"""
|
194 |
OP_ID = "OP_CLUSTER_POST_INIT"
|
195 |
__slots__ = [] |
196 |
|
197 |
|
198 |
class OpDestroyCluster(OpCode): |
199 |
"""Destroy the cluster.
|
200 |
|
201 |
This opcode has no other parameters. All the state is irreversibly
|
202 |
lost after the execution of this opcode.
|
203 |
|
204 |
"""
|
205 |
OP_ID = "OP_CLUSTER_DESTROY"
|
206 |
__slots__ = [] |
207 |
|
208 |
|
209 |
class OpQueryClusterInfo(OpCode): |
210 |
"""Query cluster information."""
|
211 |
OP_ID = "OP_CLUSTER_QUERY"
|
212 |
__slots__ = [] |
213 |
|
214 |
|
215 |
class OpVerifyCluster(OpCode): |
216 |
"""Verify the cluster state.
|
217 |
|
218 |
@type skip_checks: C{list}
|
219 |
@ivar skip_checks: steps to be skipped from the verify process; this
|
220 |
needs to be a subset of
|
221 |
L{constants.VERIFY_OPTIONAL_CHECKS}; currently
|
222 |
only L{constants.VERIFY_NPLUSONE_MEM} can be passed
|
223 |
|
224 |
"""
|
225 |
OP_ID = "OP_CLUSTER_VERIFY"
|
226 |
__slots__ = ["skip_checks", "verbose", "error_codes", |
227 |
"debug_simulate_errors"]
|
228 |
|
229 |
|
230 |
class OpVerifyDisks(OpCode): |
231 |
"""Verify the cluster disks.
|
232 |
|
233 |
Parameters: none
|
234 |
|
235 |
Result: a tuple of four elements:
|
236 |
- list of node names with bad data returned (unreachable, etc.)
|
237 |
- dict of node names with broken volume groups (values: error msg)
|
238 |
- list of instances with degraded disks (that should be activated)
|
239 |
- dict of instances with missing logical volumes (values: (node, vol)
|
240 |
pairs with details about the missing volumes)
|
241 |
|
242 |
In normal operation, all lists should be empty. A non-empty instance
|
243 |
list (3rd element of the result) is still ok (errors were fixed) but
|
244 |
non-empty node list means some node is down, and probably there are
|
245 |
unfixable drbd errors.
|
246 |
|
247 |
Note that only instances that are drbd-based are taken into
|
248 |
consideration. This might need to be revisited in the future.
|
249 |
|
250 |
"""
|
251 |
OP_ID = "OP_CLUSTER_VERIFY_DISKS"
|
252 |
__slots__ = [] |
253 |
|
254 |
|
255 |
class OpRepairDiskSizes(OpCode): |
256 |
"""Verify the disk sizes of the instances and fixes configuration
|
257 |
mimatches.
|
258 |
|
259 |
Parameters: optional instances list, in case we want to restrict the
|
260 |
checks to only a subset of the instances.
|
261 |
|
262 |
Result: a list of tuples, (instance, disk, new-size) for changed
|
263 |
configurations.
|
264 |
|
265 |
In normal operation, the list should be empty.
|
266 |
|
267 |
@type instances: list
|
268 |
@ivar instances: the list of instances to check, or empty for all instances
|
269 |
|
270 |
"""
|
271 |
OP_ID = "OP_CLUSTER_REPAIR_DISK_SIZES"
|
272 |
__slots__ = ["instances"]
|
273 |
|
274 |
|
275 |
class OpQueryConfigValues(OpCode): |
276 |
"""Query cluster configuration values."""
|
277 |
OP_ID = "OP_CLUSTER_CONFIG_QUERY"
|
278 |
__slots__ = ["output_fields"]
|
279 |
|
280 |
|
281 |
class OpRenameCluster(OpCode): |
282 |
"""Rename the cluster.
|
283 |
|
284 |
@type name: C{str}
|
285 |
@ivar name: The new name of the cluster. The name and/or the master IP
|
286 |
address will be changed to match the new name and its IP
|
287 |
address.
|
288 |
|
289 |
"""
|
290 |
OP_ID = "OP_CLUSTER_RENAME"
|
291 |
OP_DSC_FIELD = "name"
|
292 |
__slots__ = ["name"]
|
293 |
|
294 |
|
295 |
class OpSetClusterParams(OpCode): |
296 |
"""Change the parameters of the cluster.
|
297 |
|
298 |
@type vg_name: C{str} or C{None}
|
299 |
@ivar vg_name: The new volume group name or None to disable LVM usage.
|
300 |
|
301 |
"""
|
302 |
OP_ID = "OP_CLUSTER_SET_PARAMS"
|
303 |
__slots__ = [ |
304 |
"vg_name",
|
305 |
"drbd_helper",
|
306 |
"enabled_hypervisors",
|
307 |
"hvparams",
|
308 |
"os_hvp",
|
309 |
"beparams",
|
310 |
"osparams",
|
311 |
"nicparams",
|
312 |
"ndparams",
|
313 |
"candidate_pool_size",
|
314 |
"maintain_node_health",
|
315 |
"uid_pool",
|
316 |
"add_uids",
|
317 |
"remove_uids",
|
318 |
"default_iallocator",
|
319 |
"reserved_lvs",
|
320 |
"hidden_os",
|
321 |
"blacklisted_os",
|
322 |
"prealloc_wipe_disks",
|
323 |
] |
324 |
|
325 |
|
326 |
class OpRedistributeConfig(OpCode): |
327 |
"""Force a full push of the cluster configuration.
|
328 |
|
329 |
"""
|
330 |
OP_ID = "OP_CLUSTER_REDIST_CONF"
|
331 |
__slots__ = [] |
332 |
|
333 |
# node opcodes
|
334 |
|
335 |
class OpRemoveNode(OpCode): |
336 |
"""Remove a node.
|
337 |
|
338 |
@type node_name: C{str}
|
339 |
@ivar node_name: The name of the node to remove. If the node still has
|
340 |
instances on it, the operation will fail.
|
341 |
|
342 |
"""
|
343 |
OP_ID = "OP_NODE_REMOVE"
|
344 |
OP_DSC_FIELD = "node_name"
|
345 |
__slots__ = ["node_name"]
|
346 |
|
347 |
|
348 |
class OpAddNode(OpCode): |
349 |
"""Add a node to the cluster.
|
350 |
|
351 |
@type node_name: C{str}
|
352 |
@ivar node_name: The name of the node to add. This can be a short name,
|
353 |
but it will be expanded to the FQDN.
|
354 |
@type primary_ip: IP address
|
355 |
@ivar primary_ip: The primary IP of the node. This will be ignored when the
|
356 |
opcode is submitted, but will be filled during the node
|
357 |
add (so it will be visible in the job query).
|
358 |
@type secondary_ip: IP address
|
359 |
@ivar secondary_ip: The secondary IP of the node. This needs to be passed
|
360 |
if the cluster has been initialized in 'dual-network'
|
361 |
mode, otherwise it must not be given.
|
362 |
@type readd: C{bool}
|
363 |
@ivar readd: Whether to re-add an existing node to the cluster. If
|
364 |
this is not passed, then the operation will abort if the node
|
365 |
name is already in the cluster; use this parameter to 'repair'
|
366 |
a node that had its configuration broken, or was reinstalled
|
367 |
without removal from the cluster.
|
368 |
@type group: C{str}
|
369 |
@ivar group: The node group to which this node will belong.
|
370 |
@type vm_capable: C{bool}
|
371 |
@ivar vm_capable: The vm_capable node attribute
|
372 |
@type master_capable: C{bool}
|
373 |
@ivar master_capable: The master_capable node attribute
|
374 |
|
375 |
"""
|
376 |
OP_ID = "OP_NODE_ADD"
|
377 |
OP_DSC_FIELD = "node_name"
|
378 |
__slots__ = ["node_name", "primary_ip", "secondary_ip", "readd", "group", |
379 |
"vm_capable", "master_capable", "ndparams"] |
380 |
|
381 |
|
382 |
class OpQueryNodes(OpCode): |
383 |
"""Compute the list of nodes."""
|
384 |
OP_ID = "OP_NODE_QUERY"
|
385 |
__slots__ = ["output_fields", "names", "use_locking"] |
386 |
|
387 |
|
388 |
class OpQueryNodeVolumes(OpCode): |
389 |
"""Get list of volumes on node."""
|
390 |
OP_ID = "OP_NODE_QUERYVOLS"
|
391 |
__slots__ = ["nodes", "output_fields"] |
392 |
|
393 |
|
394 |
class OpQueryNodeStorage(OpCode): |
395 |
"""Get information on storage for node(s)."""
|
396 |
OP_ID = "OP_NODE_QUERY_STORAGE"
|
397 |
__slots__ = [ |
398 |
"nodes",
|
399 |
"storage_type",
|
400 |
"name",
|
401 |
"output_fields",
|
402 |
] |
403 |
|
404 |
|
405 |
class OpModifyNodeStorage(OpCode): |
406 |
"""Modifies the properies of a storage unit"""
|
407 |
OP_ID = "OP_NODE_MODIFY_STORAGE"
|
408 |
__slots__ = [ |
409 |
"node_name",
|
410 |
"storage_type",
|
411 |
"name",
|
412 |
"changes",
|
413 |
] |
414 |
|
415 |
|
416 |
class OpRepairNodeStorage(OpCode): |
417 |
"""Repairs the volume group on a node."""
|
418 |
OP_ID = "OP_REPAIR_NODE_STORAGE"
|
419 |
OP_DSC_FIELD = "node_name"
|
420 |
__slots__ = [ |
421 |
"node_name",
|
422 |
"storage_type",
|
423 |
"name",
|
424 |
"ignore_consistency",
|
425 |
] |
426 |
|
427 |
|
428 |
class OpSetNodeParams(OpCode): |
429 |
"""Change the parameters of a node."""
|
430 |
OP_ID = "OP_NODE_SET_PARAMS"
|
431 |
OP_DSC_FIELD = "node_name"
|
432 |
__slots__ = [ |
433 |
"node_name",
|
434 |
"force",
|
435 |
"master_candidate",
|
436 |
"offline",
|
437 |
"drained",
|
438 |
"auto_promote",
|
439 |
"master_capable",
|
440 |
"vm_capable",
|
441 |
"secondary_ip",
|
442 |
"ndparams",
|
443 |
] |
444 |
|
445 |
|
446 |
class OpPowercycleNode(OpCode): |
447 |
"""Tries to powercycle a node."""
|
448 |
OP_ID = "OP_NODE_POWERCYCLE"
|
449 |
OP_DSC_FIELD = "node_name"
|
450 |
__slots__ = [ |
451 |
"node_name",
|
452 |
"force",
|
453 |
] |
454 |
|
455 |
|
456 |
class OpMigrateNode(OpCode): |
457 |
"""Migrate all instances from a node."""
|
458 |
OP_ID = "OP_NODE_MIGRATE"
|
459 |
OP_DSC_FIELD = "node_name"
|
460 |
__slots__ = [ |
461 |
"node_name",
|
462 |
"mode",
|
463 |
"live",
|
464 |
] |
465 |
|
466 |
|
467 |
class OpNodeEvacuationStrategy(OpCode): |
468 |
"""Compute the evacuation strategy for a list of nodes."""
|
469 |
OP_ID = "OP_NODE_EVAC_STRATEGY"
|
470 |
OP_DSC_FIELD = "nodes"
|
471 |
__slots__ = ["nodes", "iallocator", "remote_node"] |
472 |
|
473 |
|
474 |
# instance opcodes
|
475 |
|
476 |
class OpCreateInstance(OpCode): |
477 |
"""Create an instance.
|
478 |
|
479 |
@ivar instance_name: Instance name
|
480 |
@ivar mode: Instance creation mode (one of L{constants.INSTANCE_CREATE_MODES})
|
481 |
@ivar source_handshake: Signed handshake from source (remote import only)
|
482 |
@ivar source_x509_ca: Source X509 CA in PEM format (remote import only)
|
483 |
@ivar source_instance_name: Previous name of instance (remote import only)
|
484 |
|
485 |
"""
|
486 |
OP_ID = "OP_INSTANCE_CREATE"
|
487 |
OP_DSC_FIELD = "instance_name"
|
488 |
__slots__ = [ |
489 |
"instance_name",
|
490 |
"os_type", "force_variant", "no_install", |
491 |
"pnode", "disk_template", "snode", "mode", |
492 |
"disks", "nics", |
493 |
"src_node", "src_path", "start", "identify_defaults", |
494 |
"wait_for_sync", "ip_check", "name_check", |
495 |
"file_storage_dir", "file_driver", |
496 |
"iallocator",
|
497 |
"hypervisor", "hvparams", "beparams", "osparams", |
498 |
"source_handshake",
|
499 |
"source_x509_ca",
|
500 |
"source_instance_name",
|
501 |
] |
502 |
|
503 |
|
504 |
class OpReinstallInstance(OpCode): |
505 |
"""Reinstall an instance's OS."""
|
506 |
OP_ID = "OP_INSTANCE_REINSTALL"
|
507 |
OP_DSC_FIELD = "instance_name"
|
508 |
__slots__ = ["instance_name", "os_type", "force_variant", "osparams"] |
509 |
|
510 |
|
511 |
class OpRemoveInstance(OpCode): |
512 |
"""Remove an instance."""
|
513 |
OP_ID = "OP_INSTANCE_REMOVE"
|
514 |
OP_DSC_FIELD = "instance_name"
|
515 |
__slots__ = [ |
516 |
"instance_name",
|
517 |
"ignore_failures",
|
518 |
"shutdown_timeout",
|
519 |
] |
520 |
|
521 |
|
522 |
class OpRenameInstance(OpCode): |
523 |
"""Rename an instance."""
|
524 |
OP_ID = "OP_INSTANCE_RENAME"
|
525 |
__slots__ = [ |
526 |
"instance_name", "ip_check", "new_name", "name_check", |
527 |
] |
528 |
|
529 |
|
530 |
class OpStartupInstance(OpCode): |
531 |
"""Startup an instance."""
|
532 |
OP_ID = "OP_INSTANCE_STARTUP"
|
533 |
OP_DSC_FIELD = "instance_name"
|
534 |
__slots__ = [ |
535 |
"instance_name", "force", "hvparams", "beparams", "ignore_offline_nodes", |
536 |
] |
537 |
|
538 |
|
539 |
class OpShutdownInstance(OpCode): |
540 |
"""Shutdown an instance."""
|
541 |
OP_ID = "OP_INSTANCE_SHUTDOWN"
|
542 |
OP_DSC_FIELD = "instance_name"
|
543 |
__slots__ = [ |
544 |
"instance_name", "timeout", "ignore_offline_nodes", |
545 |
] |
546 |
|
547 |
|
548 |
class OpRebootInstance(OpCode): |
549 |
"""Reboot an instance."""
|
550 |
OP_ID = "OP_INSTANCE_REBOOT"
|
551 |
OP_DSC_FIELD = "instance_name"
|
552 |
__slots__ = [ |
553 |
"instance_name", "reboot_type", "ignore_secondaries", "shutdown_timeout", |
554 |
] |
555 |
|
556 |
|
557 |
class OpReplaceDisks(OpCode): |
558 |
"""Replace the disks of an instance."""
|
559 |
OP_ID = "OP_INSTANCE_REPLACE_DISKS"
|
560 |
OP_DSC_FIELD = "instance_name"
|
561 |
__slots__ = [ |
562 |
"instance_name", "remote_node", "mode", "disks", "iallocator", |
563 |
"early_release",
|
564 |
] |
565 |
|
566 |
|
567 |
class OpFailoverInstance(OpCode): |
568 |
"""Failover an instance."""
|
569 |
OP_ID = "OP_INSTANCE_FAILOVER"
|
570 |
OP_DSC_FIELD = "instance_name"
|
571 |
__slots__ = [ |
572 |
"instance_name", "ignore_consistency", "shutdown_timeout", |
573 |
] |
574 |
|
575 |
|
576 |
class OpMigrateInstance(OpCode): |
577 |
"""Migrate an instance.
|
578 |
|
579 |
This migrates (without shutting down an instance) to its secondary
|
580 |
node.
|
581 |
|
582 |
@ivar instance_name: the name of the instance
|
583 |
@ivar mode: the migration mode (live, non-live or None for auto)
|
584 |
|
585 |
"""
|
586 |
OP_ID = "OP_INSTANCE_MIGRATE"
|
587 |
OP_DSC_FIELD = "instance_name"
|
588 |
__slots__ = ["instance_name", "mode", "cleanup", "live"] |
589 |
|
590 |
|
591 |
class OpMoveInstance(OpCode): |
592 |
"""Move an instance.
|
593 |
|
594 |
This move (with shutting down an instance and data copying) to an
|
595 |
arbitrary node.
|
596 |
|
597 |
@ivar instance_name: the name of the instance
|
598 |
@ivar target_node: the destination node
|
599 |
|
600 |
"""
|
601 |
OP_ID = "OP_INSTANCE_MOVE"
|
602 |
OP_DSC_FIELD = "instance_name"
|
603 |
__slots__ = [ |
604 |
"instance_name", "target_node", "shutdown_timeout", |
605 |
] |
606 |
|
607 |
|
608 |
class OpConnectConsole(OpCode): |
609 |
"""Connect to an instance's console."""
|
610 |
OP_ID = "OP_INSTANCE_CONSOLE"
|
611 |
OP_DSC_FIELD = "instance_name"
|
612 |
__slots__ = ["instance_name"]
|
613 |
|
614 |
|
615 |
class OpActivateInstanceDisks(OpCode): |
616 |
"""Activate an instance's disks."""
|
617 |
OP_ID = "OP_INSTANCE_ACTIVATE_DISKS"
|
618 |
OP_DSC_FIELD = "instance_name"
|
619 |
__slots__ = ["instance_name", "ignore_size"] |
620 |
|
621 |
|
622 |
class OpDeactivateInstanceDisks(OpCode): |
623 |
"""Deactivate an instance's disks."""
|
624 |
OP_ID = "OP_INSTANCE_DEACTIVATE_DISKS"
|
625 |
OP_DSC_FIELD = "instance_name"
|
626 |
__slots__ = ["instance_name"]
|
627 |
|
628 |
|
629 |
class OpRecreateInstanceDisks(OpCode): |
630 |
"""Deactivate an instance's disks."""
|
631 |
OP_ID = "OP_INSTANCE_RECREATE_DISKS"
|
632 |
OP_DSC_FIELD = "instance_name"
|
633 |
__slots__ = ["instance_name", "disks"] |
634 |
|
635 |
|
636 |
class OpQueryInstances(OpCode): |
637 |
"""Compute the list of instances."""
|
638 |
OP_ID = "OP_INSTANCE_QUERY"
|
639 |
__slots__ = ["output_fields", "names", "use_locking"] |
640 |
|
641 |
|
642 |
class OpQueryInstanceData(OpCode): |
643 |
"""Compute the run-time status of instances."""
|
644 |
OP_ID = "OP_INSTANCE_QUERY_DATA"
|
645 |
__slots__ = ["instances", "static"] |
646 |
|
647 |
|
648 |
class OpSetInstanceParams(OpCode): |
649 |
"""Change the parameters of an instance."""
|
650 |
OP_ID = "OP_INSTANCE_SET_PARAMS"
|
651 |
OP_DSC_FIELD = "instance_name"
|
652 |
__slots__ = [ |
653 |
"instance_name",
|
654 |
"hvparams", "beparams", "osparams", "force", |
655 |
"nics", "disks", "disk_template", |
656 |
"remote_node", "os_name", "force_variant", |
657 |
] |
658 |
|
659 |
|
660 |
class OpGrowDisk(OpCode): |
661 |
"""Grow a disk of an instance."""
|
662 |
OP_ID = "OP_INSTANCE_GROW_DISK"
|
663 |
OP_DSC_FIELD = "instance_name"
|
664 |
__slots__ = [ |
665 |
"instance_name", "disk", "amount", "wait_for_sync", |
666 |
] |
667 |
|
668 |
|
669 |
# OS opcodes
|
670 |
class OpDiagnoseOS(OpCode): |
671 |
"""Compute the list of guest operating systems."""
|
672 |
OP_ID = "OP_OS_DIAGNOSE"
|
673 |
__slots__ = ["output_fields", "names"] |
674 |
|
675 |
|
676 |
# Exports opcodes
|
677 |
class OpQueryExports(OpCode): |
678 |
"""Compute the list of exported images."""
|
679 |
OP_ID = "OP_BACKUP_QUERY"
|
680 |
__slots__ = ["nodes", "use_locking"] |
681 |
|
682 |
|
683 |
class OpPrepareExport(OpCode): |
684 |
"""Prepares an instance export.
|
685 |
|
686 |
@ivar instance_name: Instance name
|
687 |
@ivar mode: Export mode (one of L{constants.EXPORT_MODES})
|
688 |
|
689 |
"""
|
690 |
OP_ID = "OP_BACKUP_PREPARE"
|
691 |
OP_DSC_FIELD = "instance_name"
|
692 |
__slots__ = [ |
693 |
"instance_name", "mode", |
694 |
] |
695 |
|
696 |
|
697 |
class OpExportInstance(OpCode): |
698 |
"""Export an instance.
|
699 |
|
700 |
For local exports, the export destination is the node name. For remote
|
701 |
exports, the export destination is a list of tuples, each consisting of
|
702 |
hostname/IP address, port, HMAC and HMAC salt. The HMAC is calculated using
|
703 |
the cluster domain secret over the value "${index}:${hostname}:${port}". The
|
704 |
destination X509 CA must be a signed certificate.
|
705 |
|
706 |
@ivar mode: Export mode (one of L{constants.EXPORT_MODES})
|
707 |
@ivar target_node: Export destination
|
708 |
@ivar x509_key_name: X509 key to use (remote export only)
|
709 |
@ivar destination_x509_ca: Destination X509 CA in PEM format (remote export
|
710 |
only)
|
711 |
|
712 |
"""
|
713 |
OP_ID = "OP_BACKUP_EXPORT"
|
714 |
OP_DSC_FIELD = "instance_name"
|
715 |
__slots__ = [ |
716 |
# TODO: Rename target_node as it changes meaning for different export modes
|
717 |
# (e.g. "destination")
|
718 |
"instance_name", "target_node", "shutdown", "shutdown_timeout", |
719 |
"remove_instance",
|
720 |
"ignore_remove_failures",
|
721 |
"mode",
|
722 |
"x509_key_name",
|
723 |
"destination_x509_ca",
|
724 |
] |
725 |
|
726 |
|
727 |
class OpRemoveExport(OpCode): |
728 |
"""Remove an instance's export."""
|
729 |
OP_ID = "OP_BACKUP_REMOVE"
|
730 |
OP_DSC_FIELD = "instance_name"
|
731 |
__slots__ = ["instance_name"]
|
732 |
|
733 |
|
734 |
# Tags opcodes
|
735 |
class OpGetTags(OpCode): |
736 |
"""Returns the tags of the given object."""
|
737 |
OP_ID = "OP_TAGS_GET"
|
738 |
OP_DSC_FIELD = "name"
|
739 |
__slots__ = ["kind", "name"] |
740 |
|
741 |
|
742 |
class OpSearchTags(OpCode): |
743 |
"""Searches the tags in the cluster for a given pattern."""
|
744 |
OP_ID = "OP_TAGS_SEARCH"
|
745 |
OP_DSC_FIELD = "pattern"
|
746 |
__slots__ = ["pattern"]
|
747 |
|
748 |
|
749 |
class OpAddTags(OpCode): |
750 |
"""Add a list of tags on a given object."""
|
751 |
OP_ID = "OP_TAGS_SET"
|
752 |
__slots__ = ["kind", "name", "tags"] |
753 |
|
754 |
|
755 |
class OpDelTags(OpCode): |
756 |
"""Remove a list of tags from a given object."""
|
757 |
OP_ID = "OP_TAGS_DEL"
|
758 |
__slots__ = ["kind", "name", "tags"] |
759 |
|
760 |
|
761 |
# Test opcodes
|
762 |
class OpTestDelay(OpCode): |
763 |
"""Sleeps for a configured amount of time.
|
764 |
|
765 |
This is used just for debugging and testing.
|
766 |
|
767 |
Parameters:
|
768 |
- duration: the time to sleep
|
769 |
- on_master: if true, sleep on the master
|
770 |
- on_nodes: list of nodes in which to sleep
|
771 |
|
772 |
If the on_master parameter is true, it will execute a sleep on the
|
773 |
master (before any node sleep).
|
774 |
|
775 |
If the on_nodes list is not empty, it will sleep on those nodes
|
776 |
(after the sleep on the master, if that is enabled).
|
777 |
|
778 |
As an additional feature, the case of duration < 0 will be reported
|
779 |
as an execution error, so this opcode can be used as a failure
|
780 |
generator. The case of duration == 0 will not be treated specially.
|
781 |
|
782 |
"""
|
783 |
OP_ID = "OP_TEST_DELAY"
|
784 |
OP_DSC_FIELD = "duration"
|
785 |
__slots__ = ["duration", "on_master", "on_nodes", "repeat"] |
786 |
|
787 |
|
788 |
class OpTestAllocator(OpCode): |
789 |
"""Allocator framework testing.
|
790 |
|
791 |
This opcode has two modes:
|
792 |
- gather and return allocator input for a given mode (allocate new
|
793 |
or replace secondary) and a given instance definition (direction
|
794 |
'in')
|
795 |
- run a selected allocator for a given operation (as above) and
|
796 |
return the allocator output (direction 'out')
|
797 |
|
798 |
"""
|
799 |
OP_ID = "OP_TEST_ALLOCATOR"
|
800 |
OP_DSC_FIELD = "allocator"
|
801 |
__slots__ = [ |
802 |
"direction", "mode", "allocator", "name", |
803 |
"mem_size", "disks", "disk_template", |
804 |
"os", "tags", "nics", "vcpus", "hypervisor", |
805 |
"evac_nodes",
|
806 |
] |
807 |
|
808 |
|
809 |
class OpTestJobqueue(OpCode): |
810 |
"""Utility opcode to test some aspects of the job queue.
|
811 |
|
812 |
"""
|
813 |
OP_ID = "OP_TEST_JQUEUE"
|
814 |
__slots__ = [ |
815 |
"notify_waitlock",
|
816 |
"notify_exec",
|
817 |
"log_messages",
|
818 |
"fail",
|
819 |
] |
820 |
|
821 |
|
822 |
class OpTestDummy(OpCode): |
823 |
"""Utility opcode used by unittests.
|
824 |
|
825 |
"""
|
826 |
OP_ID = "OP_TEST_DUMMY"
|
827 |
__slots__ = [ |
828 |
"result",
|
829 |
"messages",
|
830 |
"fail",
|
831 |
] |
832 |
|
833 |
|
834 |
OP_MAPPING = dict([(v.OP_ID, v) for v in globals().values() |
835 |
if (isinstance(v, type) and issubclass(v, OpCode) and |
836 |
hasattr(v, "OP_ID"))]) |