Add file_storage_dir to opcodes.OpInitCluster
[ganeti-local] / lib / opcodes.py
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
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
32
33 """
34
35 # this are practically structures, so disable the message about too
36 # few public methods:
37 # pylint: disable-msg=R0903
38
39 class OpCode(object):
40   """Abstract OpCode"""
41   OP_ID = "OP_ABSTRACT"
42   __slots__ = []
43
44   def __init__(self, **kwargs):
45     for key in 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])
50
51
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",
57                "file_storage_dir"]
58
59
60 class OpDestroyCluster(OpCode):
61   """Destroy the cluster."""
62   OP_ID = "OP_CLUSTER_DESTROY"
63   __slots__ = []
64
65
66 class OpQueryClusterInfo(OpCode):
67   """Query cluster information."""
68   OP_ID = "OP_CLUSTER_QUERY"
69   __slots__ = []
70
71
72 class OpClusterCopyFile(OpCode):
73   """Copy a file to multiple nodes."""
74   OP_ID = "OP_CLUSTER_COPYFILE"
75   __slots__ = ["nodes", "filename"]
76
77
78 class OpRunClusterCommand(OpCode):
79   """Run a command on multiple nodes."""
80   OP_ID = "OP_CLUSTER_RUNCOMMAND"
81   __slots__ = ["nodes", "command"]
82
83
84 class OpVerifyCluster(OpCode):
85   """Verify the cluster state."""
86   OP_ID = "OP_CLUSTER_VERIFY"
87   __slots__ = []
88
89
90 class OpVerifyDisks(OpCode):
91   """Verify the cluster disks.
92
93   Parameters: none
94
95   Result: two lists:
96     - list of node names with bad data returned (unreachable, etc.)
97     - dist of node names with broken volume groups (values: error msg)
98     - list of instances with degraded disks (that should be activated)
99     - dict of instances with missing logical volumes (values: (node, vol)
100       pairs with details about the missing volumes)
101
102   In normal operation, all lists should be empty. A non-empty instance
103   list (3rd element of the result) is still ok (errors were fixed) but
104   non-empty node list means some node is down, and probably there are
105   unfixable drbd errors.
106
107   Note that only instances that are drbd-based are taken into
108   consideration. This might need to be revisited in the future.
109
110   """
111   OP_ID = "OP_CLUSTER_VERIFY_DISKS"
112   __slots__ = []
113
114
115 class OpMasterFailover(OpCode):
116   """Do a master failover."""
117   OP_ID = "OP_CLUSTER_MASTERFAILOVER"
118   __slots__ = []
119
120
121 class OpDumpClusterConfig(OpCode):
122   """Dump the cluster configuration."""
123   OP_ID = "OP_CLUSTER_DUMPCONFIG"
124   __slots__ = []
125
126
127 class OpRenameCluster(OpCode):
128   """Rename the cluster."""
129   OP_ID = "OP_CLUSTER_RENAME"
130   __slots__ = ["name"]
131
132
133 # node opcodes
134
135 class OpRemoveNode(OpCode):
136   """Remove a node."""
137   OP_ID = "OP_NODE_REMOVE"
138   __slots__ = ["node_name"]
139
140
141 class OpAddNode(OpCode):
142   """Add a node."""
143   OP_ID = "OP_NODE_ADD"
144   __slots__ = ["node_name", "primary_ip", "secondary_ip"]
145
146
147 class OpQueryNodes(OpCode):
148   """Compute the list of nodes."""
149   OP_ID = "OP_NODE_QUERY"
150   __slots__ = ["output_fields", "names"]
151
152
153 class OpQueryNodeVolumes(OpCode):
154   """Get list of volumes on node."""
155   OP_ID = "OP_NODE_QUERYVOLS"
156   __slots__ = ["nodes", "output_fields"]
157
158
159 # instance opcodes
160
161 class OpCreateInstance(OpCode):
162   """Create an instance."""
163   OP_ID = "OP_INSTANCE_CREATE"
164   __slots__ = [
165     "instance_name", "mem_size", "disk_size", "os_type", "pnode",
166     "disk_template", "snode", "swap_size", "mode",
167     "vcpus", "ip", "bridge", "src_node", "src_path", "start",
168     "wait_for_sync", "ip_check", "mac",
169     "kernel_path", "initrd_path", "hvm_boot_order",
170     ]
171
172
173 class OpReinstallInstance(OpCode):
174   """Reinstall an instance's OS."""
175   OP_ID = "OP_INSTANCE_REINSTALL"
176   __slots__ = ["instance_name", "os_type"]
177
178
179 class OpRemoveInstance(OpCode):
180   """Remove an instance."""
181   OP_ID = "OP_INSTANCE_REMOVE"
182   __slots__ = ["instance_name", "ignore_failures"]
183
184
185 class OpRenameInstance(OpCode):
186   """Rename an instance."""
187   OP_ID = "OP_INSTANCE_RENAME"
188   __slots__ = ["instance_name", "ignore_ip", "new_name"]
189
190
191 class OpStartupInstance(OpCode):
192   """Startup an instance."""
193   OP_ID = "OP_INSTANCE_STARTUP"
194   __slots__ = ["instance_name", "force", "extra_args"]
195
196
197 class OpShutdownInstance(OpCode):
198   """Shutdown an instance."""
199   OP_ID = "OP_INSTANCE_SHUTDOWN"
200   __slots__ = ["instance_name"]
201
202
203 class OpRebootInstance(OpCode):
204   """Reboot an instance."""
205   OP_ID = "OP_INSTANCE_REBOOT"
206   __slots__ = ["instance_name", "reboot_type", "extra_args",
207                "ignore_secondaries" ]
208
209
210 class OpAddMDDRBDComponent(OpCode):
211   """Add a MD-DRBD component."""
212   OP_ID = "OP_INSTANCE_ADD_MDDRBD"
213   __slots__ = ["instance_name", "remote_node", "disk_name"]
214
215
216 class OpRemoveMDDRBDComponent(OpCode):
217   """Remove a MD-DRBD component."""
218   OP_ID = "OP_INSTANCE_REMOVE_MDDRBD"
219   __slots__ = ["instance_name", "disk_name", "disk_id"]
220
221
222 class OpReplaceDisks(OpCode):
223   """Replace the disks of an instance."""
224   OP_ID = "OP_INSTANCE_REPLACE_DISKS"
225   __slots__ = ["instance_name", "remote_node", "mode", "disks"]
226
227
228 class OpFailoverInstance(OpCode):
229   """Failover an instance."""
230   OP_ID = "OP_INSTANCE_FAILOVER"
231   __slots__ = ["instance_name", "ignore_consistency"]
232
233
234 class OpConnectConsole(OpCode):
235   """Connect to an instance's console."""
236   OP_ID = "OP_INSTANCE_CONSOLE"
237   __slots__ = ["instance_name"]
238
239
240 class OpActivateInstanceDisks(OpCode):
241   """Activate an instance's disks."""
242   OP_ID = "OP_INSTANCE_ACTIVATE_DISKS"
243   __slots__ = ["instance_name"]
244
245
246 class OpDeactivateInstanceDisks(OpCode):
247   """Deactivate an instance's disks."""
248   OP_ID = "OP_INSTANCE_DEACTIVATE_DISKS"
249   __slots__ = ["instance_name"]
250
251
252 class OpQueryInstances(OpCode):
253   """Compute the list of instances."""
254   OP_ID = "OP_INSTANCE_QUERY"
255   __slots__ = ["output_fields", "names"]
256
257
258 class OpQueryInstanceData(OpCode):
259   """Compute the run-time status of instances."""
260   OP_ID = "OP_INSTANCE_QUERY_DATA"
261   __slots__ = ["instances"]
262
263
264 class OpSetInstanceParms(OpCode):
265   """Change the parameters of an instance."""
266   OP_ID = "OP_INSTANCE_SET_PARMS"
267   __slots__ = [
268     "instance_name", "mem", "vcpus", "ip", "bridge", "mac",
269     "kernel_path", "initrd_path", "hvm_boot_order",
270     ]
271
272
273 # OS opcodes
274 class OpDiagnoseOS(OpCode):
275   """Compute the list of guest operating systems."""
276   OP_ID = "OP_OS_DIAGNOSE"
277   __slots__ = []
278
279
280 # Exports opcodes
281 class OpQueryExports(OpCode):
282   """Compute the list of exported images."""
283   OP_ID = "OP_BACKUP_QUERY"
284   __slots__ = ["nodes"]
285
286
287 class OpExportInstance(OpCode):
288   """Export an instance."""
289   OP_ID = "OP_BACKUP_EXPORT"
290   __slots__ = ["instance_name", "target_node", "shutdown"]
291
292
293 # Tags opcodes
294 class OpGetTags(OpCode):
295   """Returns the tags of the given object."""
296   OP_ID = "OP_TAGS_GET"
297   __slots__ = ["kind", "name"]
298
299
300 class OpSearchTags(OpCode):
301   """Searches the tags in the cluster for a given pattern."""
302   OP_ID = "OP_TAGS_SEARCH"
303   __slots__ = ["pattern"]
304
305
306 class OpAddTags(OpCode):
307   """Add a list of tags on a given object."""
308   OP_ID = "OP_TAGS_SET"
309   __slots__ = ["kind", "name", "tags"]
310
311
312 class OpDelTags(OpCode):
313   """Remove a list of tags from a given object."""
314   OP_ID = "OP_TAGS_DEL"
315   __slots__ = ["kind", "name", "tags"]
316
317
318 # Test opcodes
319 class OpTestDelay(OpCode):
320   """Sleeps for a configured amount of time.
321
322   This is used just for debugging and testing.
323
324   Parameters:
325     - duration: the time to sleep
326     - on_master: if true, sleep on the master
327     - on_nodes: list of nodes in which to sleep
328
329   If the on_master parameter is true, it will execute a sleep on the
330   master (before any node sleep).
331
332   If the on_nodes list is not empty, it will sleep on those nodes
333   (after the sleep on the master, if that is enabled).
334
335   As an additional feature, the case of duration < 0 will be reported
336   as an execution error, so this opcode can be used as a failure
337   generator. The case of duration == 0 will not be treated specially.
338
339   """
340   OP_ID = "OP_TEST_DELAY"
341   __slots__ = ["duration", "on_master", "on_nodes"]