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