root / lib / opcodes.py @ 25c5878d
History | View | Annotate | Download (8 kB)
1 | 2f31098c | Iustin Pop | #
|
---|---|---|---|
2 | a8083063 | Iustin Pop | #
|
3 | a8083063 | Iustin Pop | |
4 | a8083063 | Iustin Pop | # Copyright (C) 2006, 2007 Google Inc.
|
5 | a8083063 | Iustin Pop | #
|
6 | a8083063 | Iustin Pop | # This program is free software; you can redistribute it and/or modify
|
7 | a8083063 | Iustin Pop | # it under the terms of the GNU General Public License as published by
|
8 | a8083063 | Iustin Pop | # the Free Software Foundation; either version 2 of the License, or
|
9 | a8083063 | Iustin Pop | # (at your option) any later version.
|
10 | a8083063 | Iustin Pop | #
|
11 | a8083063 | Iustin Pop | # This program is distributed in the hope that it will be useful, but
|
12 | a8083063 | Iustin Pop | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | a8083063 | Iustin Pop | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 | a8083063 | Iustin Pop | # General Public License for more details.
|
15 | a8083063 | Iustin Pop | #
|
16 | a8083063 | Iustin Pop | # You should have received a copy of the GNU General Public License
|
17 | a8083063 | Iustin Pop | # along with this program; if not, write to the Free Software
|
18 | a8083063 | Iustin Pop | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
19 | a8083063 | Iustin Pop | # 02110-1301, USA.
|
20 | a8083063 | Iustin Pop | |
21 | a8083063 | Iustin Pop | |
22 | a8083063 | Iustin Pop | """OpCodes module
|
23 | a8083063 | Iustin Pop |
|
24 | a8083063 | Iustin Pop | This module implements the data structures which define the cluster
|
25 | a8083063 | Iustin Pop | operations - the so-called opcodes.
|
26 | a8083063 | Iustin Pop |
|
27 | a8083063 | Iustin Pop |
|
28 | a8083063 | Iustin Pop | This module implements the logic for doing operations in the cluster. There
|
29 | a8083063 | Iustin Pop | are two kinds of classes defined:
|
30 | a8083063 | Iustin Pop | - opcodes, which are small classes only holding data for the task at hand
|
31 | a8083063 | Iustin Pop | - logical units, which know how to deal with their specific opcode only
|
32 | a8083063 | Iustin Pop |
|
33 | a8083063 | Iustin Pop | """
|
34 | a8083063 | Iustin Pop | |
35 | a8083063 | Iustin Pop | # this are practically structures, so disable the message about too
|
36 | a8083063 | Iustin Pop | # few public methods:
|
37 | a8083063 | Iustin Pop | # pylint: disable-msg=R0903
|
38 | a8083063 | Iustin Pop | |
39 | a8083063 | Iustin Pop | class OpCode(object): |
40 | a8083063 | Iustin Pop | """Abstract OpCode"""
|
41 | a8083063 | Iustin Pop | OP_ID = "OP_ABSTRACT"
|
42 | a8083063 | Iustin Pop | __slots__ = [] |
43 | a8083063 | Iustin Pop | |
44 | a8083063 | Iustin Pop | def __init__(self, **kwargs): |
45 | a8083063 | Iustin Pop | for key in kwargs: |
46 | a8083063 | Iustin Pop | if key not in self.__slots__: |
47 | 3ecf6786 | Iustin Pop | raise TypeError("OpCode %s doesn't support the parameter '%s'" % |
48 | 3ecf6786 | Iustin Pop | (self.__class__.__name__, key))
|
49 | a8083063 | Iustin Pop | setattr(self, key, kwargs[key]) |
50 | a8083063 | Iustin Pop | |
51 | a8083063 | Iustin Pop | |
52 | a8083063 | Iustin Pop | class OpInitCluster(OpCode): |
53 | a8083063 | Iustin Pop | """Initialise the cluster."""
|
54 | a8083063 | Iustin Pop | OP_ID = "OP_CLUSTER_INIT"
|
55 | a8083063 | Iustin Pop | __slots__ = ["cluster_name", "secondary_ip", "hypervisor_type", |
56 | 880478f8 | Iustin Pop | "vg_name", "mac_prefix", "def_bridge", "master_netdev"] |
57 | a8083063 | Iustin Pop | |
58 | a8083063 | Iustin Pop | |
59 | a8083063 | Iustin Pop | class OpDestroyCluster(OpCode): |
60 | a8083063 | Iustin Pop | """Destroy the cluster."""
|
61 | a8083063 | Iustin Pop | OP_ID = "OP_CLUSTER_DESTROY"
|
62 | a8083063 | Iustin Pop | __slots__ = [] |
63 | a8083063 | Iustin Pop | |
64 | a8083063 | Iustin Pop | |
65 | a8083063 | Iustin Pop | class OpQueryClusterInfo(OpCode): |
66 | fdc267f4 | Iustin Pop | """Query cluster information."""
|
67 | a8083063 | Iustin Pop | OP_ID = "OP_CLUSTER_QUERY"
|
68 | a8083063 | Iustin Pop | __slots__ = [] |
69 | a8083063 | Iustin Pop | |
70 | a8083063 | Iustin Pop | |
71 | a8083063 | Iustin Pop | class OpClusterCopyFile(OpCode): |
72 | fdc267f4 | Iustin Pop | """Copy a file to multiple nodes."""
|
73 | a8083063 | Iustin Pop | OP_ID = "OP_CLUSTER_COPYFILE"
|
74 | a8083063 | Iustin Pop | __slots__ = ["nodes", "filename"] |
75 | a8083063 | Iustin Pop | |
76 | a8083063 | Iustin Pop | |
77 | a8083063 | Iustin Pop | class OpRunClusterCommand(OpCode): |
78 | fdc267f4 | Iustin Pop | """Run a command on multiple nodes."""
|
79 | a8083063 | Iustin Pop | OP_ID = "OP_CLUSTER_RUNCOMMAND"
|
80 | a8083063 | Iustin Pop | __slots__ = ["nodes", "command"] |
81 | a8083063 | Iustin Pop | |
82 | a8083063 | Iustin Pop | |
83 | a8083063 | Iustin Pop | class OpVerifyCluster(OpCode): |
84 | fdc267f4 | Iustin Pop | """Verify the cluster state."""
|
85 | a8083063 | Iustin Pop | OP_ID = "OP_CLUSTER_VERIFY"
|
86 | a8083063 | Iustin Pop | __slots__ = [] |
87 | a8083063 | Iustin Pop | |
88 | a8083063 | Iustin Pop | |
89 | 150e978f | Iustin Pop | class OpVerifyDisks(OpCode): |
90 | 150e978f | Iustin Pop | """Verify the cluster disks.
|
91 | 150e978f | Iustin Pop |
|
92 | 150e978f | Iustin Pop | Parameters: none
|
93 | 150e978f | Iustin Pop |
|
94 | 150e978f | Iustin Pop | Result: two lists:
|
95 | 150e978f | Iustin Pop | - list of node names with bad data returned (unreachable, etc.)
|
96 | b63ed789 | Iustin Pop | - dist of node names with broken volume groups (values: error msg)
|
97 | 150e978f | Iustin Pop | - list of instances with degraded disks (that should be activated)
|
98 | b63ed789 | Iustin Pop | - dict of instances with missing logical volumes (values: (node, vol)
|
99 | b63ed789 | Iustin Pop | pairs with details about the missing volumes)
|
100 | 150e978f | Iustin Pop |
|
101 | b63ed789 | Iustin Pop | In normal operation, all lists should be empty. A non-empty instance
|
102 | b63ed789 | Iustin Pop | list (3rd element of the result) is still ok (errors were fixed) but
|
103 | b63ed789 | Iustin Pop | non-empty node list means some node is down, and probably there are
|
104 | b63ed789 | Iustin Pop | unfixable drbd errors.
|
105 | 150e978f | Iustin Pop |
|
106 | 150e978f | Iustin Pop | Note that only instances that are drbd-based are taken into
|
107 | 150e978f | Iustin Pop | consideration. This might need to be revisited in the future.
|
108 | 150e978f | Iustin Pop |
|
109 | 150e978f | Iustin Pop | """
|
110 | 150e978f | Iustin Pop | OP_ID = "OP_CLUSTER_VERIFY_DISKS"
|
111 | 150e978f | Iustin Pop | __slots__ = [] |
112 | 150e978f | Iustin Pop | |
113 | 150e978f | Iustin Pop | |
114 | a8083063 | Iustin Pop | class OpMasterFailover(OpCode): |
115 | fdc267f4 | Iustin Pop | """Do a master failover."""
|
116 | a8083063 | Iustin Pop | OP_ID = "OP_CLUSTER_MASTERFAILOVER"
|
117 | a8083063 | Iustin Pop | __slots__ = [] |
118 | a8083063 | Iustin Pop | |
119 | a8083063 | Iustin Pop | |
120 | a8083063 | Iustin Pop | class OpDumpClusterConfig(OpCode): |
121 | fdc267f4 | Iustin Pop | """Dump the cluster configuration."""
|
122 | a8083063 | Iustin Pop | OP_ID = "OP_CLUSTER_DUMPCONFIG"
|
123 | a8083063 | Iustin Pop | __slots__ = [] |
124 | a8083063 | Iustin Pop | |
125 | a8083063 | Iustin Pop | |
126 | 07bd8a51 | Iustin Pop | class OpRenameCluster(OpCode): |
127 | 07bd8a51 | Iustin Pop | """Rename the cluster."""
|
128 | 07bd8a51 | Iustin Pop | OP_ID = "OP_CLUSTER_RENAME"
|
129 | 07bd8a51 | Iustin Pop | __slots__ = ["name"]
|
130 | 07bd8a51 | Iustin Pop | |
131 | 07bd8a51 | Iustin Pop | |
132 | 07bd8a51 | Iustin Pop | # node opcodes
|
133 | 07bd8a51 | Iustin Pop | |
134 | a8083063 | Iustin Pop | class OpRemoveNode(OpCode): |
135 | a8083063 | Iustin Pop | """Remove a node."""
|
136 | a8083063 | Iustin Pop | OP_ID = "OP_NODE_REMOVE"
|
137 | a8083063 | Iustin Pop | __slots__ = ["node_name"]
|
138 | a8083063 | Iustin Pop | |
139 | a8083063 | Iustin Pop | |
140 | a8083063 | Iustin Pop | class OpAddNode(OpCode): |
141 | a8083063 | Iustin Pop | """Add a node."""
|
142 | a8083063 | Iustin Pop | OP_ID = "OP_NODE_ADD"
|
143 | a8083063 | Iustin Pop | __slots__ = ["node_name", "primary_ip", "secondary_ip"] |
144 | a8083063 | Iustin Pop | |
145 | a8083063 | Iustin Pop | |
146 | a8083063 | Iustin Pop | class OpQueryNodes(OpCode): |
147 | a8083063 | Iustin Pop | """Compute the list of nodes."""
|
148 | a8083063 | Iustin Pop | OP_ID = "OP_NODE_QUERY"
|
149 | 246e180a | Iustin Pop | __slots__ = ["output_fields", "names"] |
150 | a8083063 | Iustin Pop | |
151 | a8083063 | Iustin Pop | |
152 | dcb93971 | Michael Hanselmann | class OpQueryNodeVolumes(OpCode): |
153 | dcb93971 | Michael Hanselmann | """Get list of volumes on node."""
|
154 | dcb93971 | Michael Hanselmann | OP_ID = "OP_NODE_QUERYVOLS"
|
155 | dcb93971 | Michael Hanselmann | __slots__ = ["nodes", "output_fields"] |
156 | dcb93971 | Michael Hanselmann | |
157 | dcb93971 | Michael Hanselmann | |
158 | a8083063 | Iustin Pop | # instance opcodes
|
159 | a8083063 | Iustin Pop | |
160 | a8083063 | Iustin Pop | class OpCreateInstance(OpCode): |
161 | fdc267f4 | Iustin Pop | """Create an instance."""
|
162 | a8083063 | Iustin Pop | OP_ID = "OP_INSTANCE_CREATE"
|
163 | 3b6d8c9b | Iustin Pop | __slots__ = [ |
164 | 3b6d8c9b | Iustin Pop | "instance_name", "mem_size", "disk_size", "os_type", "pnode", |
165 | 3b6d8c9b | Iustin Pop | "disk_template", "snode", "swap_size", "mode", |
166 | 3b6d8c9b | Iustin Pop | "vcpus", "ip", "bridge", "src_node", "src_path", "start", |
167 | 3b6d8c9b | Iustin Pop | "wait_for_sync", "ip_check", "mac", |
168 | 25c5878d | Alexander Schreiber | "kernel_path", "initrd_path", "hvm_boot_order", |
169 | 3b6d8c9b | Iustin Pop | ] |
170 | a8083063 | Iustin Pop | |
171 | a8083063 | Iustin Pop | |
172 | fe7b0351 | Michael Hanselmann | class OpReinstallInstance(OpCode): |
173 | fdc267f4 | Iustin Pop | """Reinstall an instance's OS."""
|
174 | fe7b0351 | Michael Hanselmann | OP_ID = "OP_INSTANCE_REINSTALL"
|
175 | d0834de3 | Michael Hanselmann | __slots__ = ["instance_name", "os_type"] |
176 | fe7b0351 | Michael Hanselmann | |
177 | fe7b0351 | Michael Hanselmann | |
178 | a8083063 | Iustin Pop | class OpRemoveInstance(OpCode): |
179 | a8083063 | Iustin Pop | """Remove an instance."""
|
180 | a8083063 | Iustin Pop | OP_ID = "OP_INSTANCE_REMOVE"
|
181 | 1d67656e | Iustin Pop | __slots__ = ["instance_name", "ignore_failures"] |
182 | a8083063 | Iustin Pop | |
183 | a8083063 | Iustin Pop | |
184 | decd5f45 | Iustin Pop | class OpRenameInstance(OpCode): |
185 | decd5f45 | Iustin Pop | """Rename an instance."""
|
186 | decd5f45 | Iustin Pop | OP_ID = "OP_INSTANCE_RENAME"
|
187 | decd5f45 | Iustin Pop | __slots__ = ["instance_name", "ignore_ip", "new_name"] |
188 | decd5f45 | Iustin Pop | |
189 | decd5f45 | Iustin Pop | |
190 | a8083063 | Iustin Pop | class OpStartupInstance(OpCode): |
191 | fdc267f4 | Iustin Pop | """Startup an instance."""
|
192 | a8083063 | Iustin Pop | OP_ID = "OP_INSTANCE_STARTUP"
|
193 | a8083063 | Iustin Pop | __slots__ = ["instance_name", "force", "extra_args"] |
194 | a8083063 | Iustin Pop | |
195 | a8083063 | Iustin Pop | |
196 | a8083063 | Iustin Pop | class OpShutdownInstance(OpCode): |
197 | fdc267f4 | Iustin Pop | """Shutdown an instance."""
|
198 | a8083063 | Iustin Pop | OP_ID = "OP_INSTANCE_SHUTDOWN"
|
199 | a8083063 | Iustin Pop | __slots__ = ["instance_name"]
|
200 | a8083063 | Iustin Pop | |
201 | a8083063 | Iustin Pop | |
202 | bf6929a2 | Alexander Schreiber | class OpRebootInstance(OpCode): |
203 | bf6929a2 | Alexander Schreiber | """Reboot an instance."""
|
204 | bf6929a2 | Alexander Schreiber | OP_ID = "OP_INSTANCE_STARTUP"
|
205 | bf6929a2 | Alexander Schreiber | __slots__ = ["instance_name", "reboot_type", "extra_args", |
206 | bf6929a2 | Alexander Schreiber | "ignore_secondaries" ]
|
207 | bf6929a2 | Alexander Schreiber | |
208 | bf6929a2 | Alexander Schreiber | |
209 | a8083063 | Iustin Pop | class OpAddMDDRBDComponent(OpCode): |
210 | a8083063 | Iustin Pop | """Add a MD-DRBD component."""
|
211 | a8083063 | Iustin Pop | OP_ID = "OP_INSTANCE_ADD_MDDRBD"
|
212 | a8083063 | Iustin Pop | __slots__ = ["instance_name", "remote_node", "disk_name"] |
213 | a8083063 | Iustin Pop | |
214 | a8083063 | Iustin Pop | |
215 | a8083063 | Iustin Pop | class OpRemoveMDDRBDComponent(OpCode): |
216 | a8083063 | Iustin Pop | """Remove a MD-DRBD component."""
|
217 | a8083063 | Iustin Pop | OP_ID = "OP_INSTANCE_REMOVE_MDDRBD"
|
218 | a8083063 | Iustin Pop | __slots__ = ["instance_name", "disk_name", "disk_id"] |
219 | a8083063 | Iustin Pop | |
220 | a8083063 | Iustin Pop | |
221 | a8083063 | Iustin Pop | class OpReplaceDisks(OpCode): |
222 | fdc267f4 | Iustin Pop | """Replace the disks of an instance."""
|
223 | a8083063 | Iustin Pop | OP_ID = "OP_INSTANCE_REPLACE_DISKS"
|
224 | a9e0c397 | Iustin Pop | __slots__ = ["instance_name", "remote_node", "mode", "disks"] |
225 | a8083063 | Iustin Pop | |
226 | a8083063 | Iustin Pop | |
227 | a8083063 | Iustin Pop | class OpFailoverInstance(OpCode): |
228 | a8083063 | Iustin Pop | """Failover an instance."""
|
229 | a8083063 | Iustin Pop | OP_ID = "OP_INSTANCE_FAILOVER"
|
230 | a8083063 | Iustin Pop | __slots__ = ["instance_name", "ignore_consistency"] |
231 | a8083063 | Iustin Pop | |
232 | a8083063 | Iustin Pop | |
233 | a8083063 | Iustin Pop | class OpConnectConsole(OpCode): |
234 | fdc267f4 | Iustin Pop | """Connect to an instance's console."""
|
235 | a8083063 | Iustin Pop | OP_ID = "OP_INSTANCE_CONSOLE"
|
236 | a8083063 | Iustin Pop | __slots__ = ["instance_name"]
|
237 | a8083063 | Iustin Pop | |
238 | a8083063 | Iustin Pop | |
239 | a8083063 | Iustin Pop | class OpActivateInstanceDisks(OpCode): |
240 | fdc267f4 | Iustin Pop | """Activate an instance's disks."""
|
241 | a8083063 | Iustin Pop | OP_ID = "OP_INSTANCE_ACTIVATE_DISKS"
|
242 | a8083063 | Iustin Pop | __slots__ = ["instance_name"]
|
243 | a8083063 | Iustin Pop | |
244 | a8083063 | Iustin Pop | |
245 | a8083063 | Iustin Pop | class OpDeactivateInstanceDisks(OpCode): |
246 | fdc267f4 | Iustin Pop | """Deactivate an instance's disks."""
|
247 | a8083063 | Iustin Pop | OP_ID = "OP_INSTANCE_DEACTIVATE_DISKS"
|
248 | a8083063 | Iustin Pop | __slots__ = ["instance_name"]
|
249 | a8083063 | Iustin Pop | |
250 | a8083063 | Iustin Pop | |
251 | a8083063 | Iustin Pop | class OpQueryInstances(OpCode): |
252 | a8083063 | Iustin Pop | """Compute the list of instances."""
|
253 | a8083063 | Iustin Pop | OP_ID = "OP_INSTANCE_QUERY"
|
254 | 069dcc86 | Iustin Pop | __slots__ = ["output_fields", "names"] |
255 | a8083063 | Iustin Pop | |
256 | a8083063 | Iustin Pop | |
257 | a8083063 | Iustin Pop | class OpQueryInstanceData(OpCode): |
258 | a8083063 | Iustin Pop | """Compute the run-time status of instances."""
|
259 | a8083063 | Iustin Pop | OP_ID = "OP_INSTANCE_QUERY_DATA"
|
260 | a8083063 | Iustin Pop | __slots__ = ["instances"]
|
261 | a8083063 | Iustin Pop | |
262 | a8083063 | Iustin Pop | |
263 | a8083063 | Iustin Pop | class OpSetInstanceParms(OpCode): |
264 | a8083063 | Iustin Pop | """Change the parameters of an instance."""
|
265 | a8083063 | Iustin Pop | OP_ID = "OP_INSTANCE_SET_PARMS"
|
266 | 973d7867 | Iustin Pop | __slots__ = [ |
267 | 973d7867 | Iustin Pop | "instance_name", "mem", "vcpus", "ip", "bridge", "mac", |
268 | 25c5878d | Alexander Schreiber | "kernel_path", "initrd_path", "hvm_boot_order", |
269 | 973d7867 | Iustin Pop | ] |
270 | a8083063 | Iustin Pop | |
271 | a8083063 | Iustin Pop | |
272 | a8083063 | Iustin Pop | # OS opcodes
|
273 | a8083063 | Iustin Pop | class OpDiagnoseOS(OpCode): |
274 | a8083063 | Iustin Pop | """Compute the list of guest operating systems."""
|
275 | a8083063 | Iustin Pop | OP_ID = "OP_OS_DIAGNOSE"
|
276 | a8083063 | Iustin Pop | __slots__ = [] |
277 | a8083063 | Iustin Pop | |
278 | a8083063 | Iustin Pop | # Exports opcodes
|
279 | a8083063 | Iustin Pop | class OpQueryExports(OpCode): |
280 | a8083063 | Iustin Pop | """Compute the list of exported images."""
|
281 | a8083063 | Iustin Pop | OP_ID = "OP_BACKUP_QUERY"
|
282 | a8083063 | Iustin Pop | __slots__ = ["nodes"]
|
283 | a8083063 | Iustin Pop | |
284 | a8083063 | Iustin Pop | class OpExportInstance(OpCode): |
285 | a8083063 | Iustin Pop | """Export an instance."""
|
286 | a8083063 | Iustin Pop | OP_ID = "OP_BACKUP_EXPORT"
|
287 | a8083063 | Iustin Pop | __slots__ = ["instance_name", "target_node", "shutdown"] |
288 | 5c947f38 | Iustin Pop | |
289 | 5c947f38 | Iustin Pop | |
290 | 5c947f38 | Iustin Pop | # Tags opcodes
|
291 | 5c947f38 | Iustin Pop | class OpGetTags(OpCode): |
292 | 5c947f38 | Iustin Pop | """Returns the tags of the given object."""
|
293 | 5c947f38 | Iustin Pop | OP_ID = "OP_TAGS_GET"
|
294 | 5c947f38 | Iustin Pop | __slots__ = ["kind", "name"] |
295 | 5c947f38 | Iustin Pop | |
296 | 5c947f38 | Iustin Pop | |
297 | 73415719 | Iustin Pop | class OpSearchTags(OpCode): |
298 | 73415719 | Iustin Pop | """Searches the tags in the cluster for a given pattern."""
|
299 | 73415719 | Iustin Pop | OP_ID = "OP_TAGS_SEARCH"
|
300 | 73415719 | Iustin Pop | __slots__ = ["pattern"]
|
301 | 73415719 | Iustin Pop | |
302 | 73415719 | Iustin Pop | |
303 | f27302fa | Iustin Pop | class OpAddTags(OpCode): |
304 | f27302fa | Iustin Pop | """Add a list of tags on a given object."""
|
305 | 5c947f38 | Iustin Pop | OP_ID = "OP_TAGS_SET"
|
306 | f27302fa | Iustin Pop | __slots__ = ["kind", "name", "tags"] |
307 | 5c947f38 | Iustin Pop | |
308 | 5c947f38 | Iustin Pop | |
309 | f27302fa | Iustin Pop | class OpDelTags(OpCode): |
310 | f27302fa | Iustin Pop | """Remove a list of tags from a given object."""
|
311 | 5c947f38 | Iustin Pop | OP_ID = "OP_TAGS_DEL"
|
312 | f27302fa | Iustin Pop | __slots__ = ["kind", "name", "tags"] |