4 # Copyright (C) 2006, 2007 Google Inc.
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.
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.
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
24 This module implements the data structures which define the cluster
25 operations - the so-called opcodes.
28 This module implements the logic for doing operations in the cluster. There
29 are two kinds of classes defined:
30 - opcodes, which are small classes only holding data for the task at hand
31 - logical units, which know how to deal with their specific opcode only
35 # this are practically structures, so disable the message about too
37 # pylint: disable-msg=R0903
44 def __init__(self, **kwargs):
46 if key not in self.__slots__:
47 raise TypeError("OpCode %s doesn't support the parameter '%s'" %
48 (self.__class__.__name__, key))
49 setattr(self, key, kwargs[key])
52 class OpInitCluster(OpCode):
53 """Initialise the cluster."""
54 OP_ID = "OP_CLUSTER_INIT"
55 __slots__ = ["cluster_name", "secondary_ip", "hypervisor_type",
56 "vg_name", "mac_prefix", "def_bridge", "master_netdev"]
59 class OpDestroyCluster(OpCode):
60 """Destroy the cluster."""
61 OP_ID = "OP_CLUSTER_DESTROY"
65 class OpQueryClusterInfo(OpCode):
66 """Query cluster information."""
67 OP_ID = "OP_CLUSTER_QUERY"
71 class OpClusterCopyFile(OpCode):
72 """Copy a file to multiple nodes."""
73 OP_ID = "OP_CLUSTER_COPYFILE"
74 __slots__ = ["nodes", "filename"]
77 class OpRunClusterCommand(OpCode):
78 """Run a command on multiple nodes."""
79 OP_ID = "OP_CLUSTER_RUNCOMMAND"
80 __slots__ = ["nodes", "command"]
83 class OpVerifyCluster(OpCode):
84 """Verify the cluster state."""
85 OP_ID = "OP_CLUSTER_VERIFY"
86 __slots__ = ["skip_checks"]
89 class OpVerifyDisks(OpCode):
90 """Verify the cluster disks.
95 - list of node names with bad data returned (unreachable, etc.)
96 - dist of node names with broken volume groups (values: error msg)
97 - list of instances with degraded disks (that should be activated)
98 - dict of instances with missing logical volumes (values: (node, vol)
99 pairs with details about the missing volumes)
101 In normal operation, all lists should be empty. A non-empty instance
102 list (3rd element of the result) is still ok (errors were fixed) but
103 non-empty node list means some node is down, and probably there are
104 unfixable drbd errors.
106 Note that only instances that are drbd-based are taken into
107 consideration. This might need to be revisited in the future.
110 OP_ID = "OP_CLUSTER_VERIFY_DISKS"
114 class OpMasterFailover(OpCode):
115 """Do a master failover."""
116 OP_ID = "OP_CLUSTER_MASTERFAILOVER"
120 class OpDumpClusterConfig(OpCode):
121 """Dump the cluster configuration."""
122 OP_ID = "OP_CLUSTER_DUMPCONFIG"
126 class OpRenameCluster(OpCode):
127 """Rename the cluster."""
128 OP_ID = "OP_CLUSTER_RENAME"
134 class OpRemoveNode(OpCode):
136 OP_ID = "OP_NODE_REMOVE"
137 __slots__ = ["node_name"]
140 class OpAddNode(OpCode):
142 OP_ID = "OP_NODE_ADD"
143 __slots__ = ["node_name", "primary_ip", "secondary_ip"]
146 class OpQueryNodes(OpCode):
147 """Compute the list of nodes."""
148 OP_ID = "OP_NODE_QUERY"
149 __slots__ = ["output_fields", "names"]
152 class OpQueryNodeVolumes(OpCode):
153 """Get list of volumes on node."""
154 OP_ID = "OP_NODE_QUERYVOLS"
155 __slots__ = ["nodes", "output_fields"]
160 class OpCreateInstance(OpCode):
161 """Create an instance."""
162 OP_ID = "OP_INSTANCE_CREATE"
164 "instance_name", "mem_size", "disk_size", "os_type", "pnode",
165 "disk_template", "snode", "swap_size", "mode",
166 "vcpus", "ip", "bridge", "src_node", "src_path", "start",
167 "wait_for_sync", "ip_check", "mac",
168 "kernel_path", "initrd_path", "hvm_boot_order", "hvm_acpi",
169 "hvm_pae", "hvm_cdrom_image_path", "vnc_bind_address",
174 class OpReinstallInstance(OpCode):
175 """Reinstall an instance's OS."""
176 OP_ID = "OP_INSTANCE_REINSTALL"
177 __slots__ = ["instance_name", "os_type"]
180 class OpRemoveInstance(OpCode):
181 """Remove an instance."""
182 OP_ID = "OP_INSTANCE_REMOVE"
183 __slots__ = ["instance_name", "ignore_failures"]
186 class OpRenameInstance(OpCode):
187 """Rename an instance."""
188 OP_ID = "OP_INSTANCE_RENAME"
189 __slots__ = ["instance_name", "ignore_ip", "new_name"]
192 class OpStartupInstance(OpCode):
193 """Startup an instance."""
194 OP_ID = "OP_INSTANCE_STARTUP"
195 __slots__ = ["instance_name", "force", "extra_args"]
198 class OpShutdownInstance(OpCode):
199 """Shutdown an instance."""
200 OP_ID = "OP_INSTANCE_SHUTDOWN"
201 __slots__ = ["instance_name"]
204 class OpRebootInstance(OpCode):
205 """Reboot an instance."""
206 OP_ID = "OP_INSTANCE_REBOOT"
207 __slots__ = ["instance_name", "reboot_type", "extra_args",
208 "ignore_secondaries" ]
211 class OpAddMDDRBDComponent(OpCode):
212 """Add a MD-DRBD component."""
213 OP_ID = "OP_INSTANCE_ADD_MDDRBD"
214 __slots__ = ["instance_name", "remote_node", "disk_name"]
217 class OpRemoveMDDRBDComponent(OpCode):
218 """Remove a MD-DRBD component."""
219 OP_ID = "OP_INSTANCE_REMOVE_MDDRBD"
220 __slots__ = ["instance_name", "disk_name", "disk_id"]
223 class OpReplaceDisks(OpCode):
224 """Replace the disks of an instance."""
225 OP_ID = "OP_INSTANCE_REPLACE_DISKS"
226 __slots__ = ["instance_name", "remote_node", "mode", "disks", "iallocator"]
229 class OpFailoverInstance(OpCode):
230 """Failover an instance."""
231 OP_ID = "OP_INSTANCE_FAILOVER"
232 __slots__ = ["instance_name", "ignore_consistency"]
235 class OpConnectConsole(OpCode):
236 """Connect to an instance's console."""
237 OP_ID = "OP_INSTANCE_CONSOLE"
238 __slots__ = ["instance_name"]
241 class OpActivateInstanceDisks(OpCode):
242 """Activate an instance's disks."""
243 OP_ID = "OP_INSTANCE_ACTIVATE_DISKS"
244 __slots__ = ["instance_name"]
247 class OpDeactivateInstanceDisks(OpCode):
248 """Deactivate an instance's disks."""
249 OP_ID = "OP_INSTANCE_DEACTIVATE_DISKS"
250 __slots__ = ["instance_name"]
253 class OpQueryInstances(OpCode):
254 """Compute the list of instances."""
255 OP_ID = "OP_INSTANCE_QUERY"
256 __slots__ = ["output_fields", "names"]
259 class OpQueryInstanceData(OpCode):
260 """Compute the run-time status of instances."""
261 OP_ID = "OP_INSTANCE_QUERY_DATA"
262 __slots__ = ["instances"]
265 class OpSetInstanceParms(OpCode):
266 """Change the parameters of an instance."""
267 OP_ID = "OP_INSTANCE_SET_PARMS"
269 "instance_name", "mem", "vcpus", "ip", "bridge", "mac",
270 "kernel_path", "initrd_path", "hvm_boot_order", "hvm_acpi",
271 "hvm_pae", "hvm_cdrom_image_path", "vnc_bind_address"
276 class OpDiagnoseOS(OpCode):
277 """Compute the list of guest operating systems."""
278 OP_ID = "OP_OS_DIAGNOSE"
279 __slots__ = ["output_fields", "names"]
282 class OpQueryExports(OpCode):
283 """Compute the list of exported images."""
284 OP_ID = "OP_BACKUP_QUERY"
285 __slots__ = ["nodes"]
287 class OpExportInstance(OpCode):
288 """Export an instance."""
289 OP_ID = "OP_BACKUP_EXPORT"
290 __slots__ = ["instance_name", "target_node", "shutdown"]
292 class OpRemoveExport(OpCode):
293 """Remove an instance's export."""
294 OP_ID = "OP_BACKUP_REMOVE"
295 __slots__ = ["instance_name"]
298 class OpGetTags(OpCode):
299 """Returns the tags of the given object."""
300 OP_ID = "OP_TAGS_GET"
301 __slots__ = ["kind", "name"]
304 class OpSearchTags(OpCode):
305 """Searches the tags in the cluster for a given pattern."""
306 OP_ID = "OP_TAGS_SEARCH"
307 __slots__ = ["pattern"]
310 class OpAddTags(OpCode):
311 """Add a list of tags on a given object."""
312 OP_ID = "OP_TAGS_SET"
313 __slots__ = ["kind", "name", "tags"]
316 class OpDelTags(OpCode):
317 """Remove a list of tags from a given object."""
318 OP_ID = "OP_TAGS_DEL"
319 __slots__ = ["kind", "name", "tags"]
323 class OpTestDelay(OpCode):
324 """Sleeps for a configured amount of time.
326 This is used just for debugging and testing.
329 - duration: the time to sleep
330 - on_master: if true, sleep on the master
331 - on_nodes: list of nodes in which to sleep
333 If the on_master parameter is true, it will execute a sleep on the
334 master (before any node sleep).
336 If the on_nodes list is not empty, it will sleep on those nodes
337 (after the sleep on the master, if that is enabled).
339 As an additional feature, the case of duration < 0 will be reported
340 as an execution error, so this opcode can be used as a failure
341 generator. The case of duration == 0 will not be treated specially.
344 OP_ID = "OP_TEST_DELAY"
345 __slots__ = ["duration", "on_master", "on_nodes"]
348 class OpTestAllocator(OpCode):
349 """Allocator framework testing.
351 This opcode has two modes:
352 - gather and return allocator input for a given mode (allocate new
353 or replace secondary) and a given instance definition (direction
355 - run a selected allocator for a given operation (as above) and
356 return the allocator output (direction 'out')
359 OP_ID = "OP_TEST_ALLOCATOR"
361 "direction", "mode", "allocator", "name",
362 "mem_size", "disks", "disk_template",
363 "os", "tags", "nics", "vcpus",