root / lib / rpc_defs.py @ a09f9847
History | View | Annotate | Download (17.1 kB)
1 |
#
|
---|---|
2 |
#
|
3 |
|
4 |
# Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 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 |
"""RPC definitions for communication between master and node daemons.
|
22 |
|
23 |
RPC definition fields:
|
24 |
|
25 |
- Name as string
|
26 |
- L{SINGLE} for single-node calls, L{MULTI} for multi-node
|
27 |
- Timeout (e.g. L{TMO_NORMAL})
|
28 |
- List of arguments as tuples
|
29 |
|
30 |
- Name as string
|
31 |
- Argument kind used for encoding/decoding
|
32 |
- Description for docstring (can be C{None})
|
33 |
|
34 |
- Return value wrapper (e.g. for deserializing into L{objects}-based objects)
|
35 |
- Short call description for docstring
|
36 |
|
37 |
"""
|
38 |
|
39 |
from ganeti import utils |
40 |
|
41 |
|
42 |
# Guidelines for choosing timeouts:
|
43 |
# - call used during watcher: timeout of 1min, _TMO_URGENT
|
44 |
# - trivial (but be sure it is trivial) (e.g. reading a file): 5min, _TMO_FAST
|
45 |
# - other calls: 15 min, _TMO_NORMAL
|
46 |
# - special calls (instance add, etc.): either _TMO_SLOW (1h) or huge timeouts
|
47 |
TMO_URGENT = 60 # one minute |
48 |
TMO_FAST = 5 * 60 # five minutes |
49 |
TMO_NORMAL = 15 * 60 # 15 minutes |
50 |
TMO_SLOW = 3600 # one hour |
51 |
TMO_4HRS = 4 * 3600 |
52 |
TMO_1DAY = 86400
|
53 |
|
54 |
SINGLE = "single-node"
|
55 |
MULTI = "multi-node"
|
56 |
|
57 |
# Constants for encoding/decoding
|
58 |
(ED_OBJECT_DICT, |
59 |
ED_OBJECT_DICT_LIST, |
60 |
ED_INST_DICT, |
61 |
ED_INST_DICT_HVP_BEP, |
62 |
ED_NODE_TO_DISK_DICT, |
63 |
ED_INST_DICT_OSP, |
64 |
ED_IMPEXP_IO, |
65 |
ED_FILE_DETAILS, |
66 |
ED_FINALIZE_EXPORT_DISKS, |
67 |
ED_COMPRESS, |
68 |
ED_BLOCKDEV_RENAME) = range(1, 12) |
69 |
|
70 |
|
71 |
def _Prepare(calls): |
72 |
"""Converts list of calls to dictionary.
|
73 |
|
74 |
"""
|
75 |
return utils.SequenceToDict(calls)
|
76 |
|
77 |
|
78 |
_FILE_STORAGE_CALLS = [ |
79 |
("file_storage_dir_create", SINGLE, TMO_FAST, [
|
80 |
("file_storage_dir", None, "File storage directory"), |
81 |
], None, "Create the given file storage directory"), |
82 |
("file_storage_dir_remove", SINGLE, TMO_FAST, [
|
83 |
("file_storage_dir", None, "File storage directory"), |
84 |
], None, "Remove the given file storage directory"), |
85 |
("file_storage_dir_rename", SINGLE, TMO_FAST, [
|
86 |
("old_file_storage_dir", None, "Old name"), |
87 |
("new_file_storage_dir", None, "New name"), |
88 |
], None, "Rename file storage directory"), |
89 |
] |
90 |
|
91 |
_STORAGE_CALLS = [ |
92 |
("storage_list", MULTI, TMO_NORMAL, [
|
93 |
("su_name", None, None), |
94 |
("su_args", None, None), |
95 |
("name", None, None), |
96 |
("fields", None, None), |
97 |
], None, "Get list of storage units"), |
98 |
("storage_modify", SINGLE, TMO_NORMAL, [
|
99 |
("su_name", None, None), |
100 |
("su_args", None, None), |
101 |
("name", None, None), |
102 |
("changes", None, None), |
103 |
], None, "Modify a storage unit"), |
104 |
("storage_execute", SINGLE, TMO_NORMAL, [
|
105 |
("su_name", None, None), |
106 |
("su_args", None, None), |
107 |
("name", None, None), |
108 |
("op", None, None), |
109 |
], None, "Executes an operation on a storage unit"), |
110 |
] |
111 |
|
112 |
_INSTANCE_CALLS = [ |
113 |
("instance_info", SINGLE, TMO_URGENT, [
|
114 |
("instance", None, "Instance name"), |
115 |
("hname", None, "Hypervisor type"), |
116 |
], None, "Returns information about a single instance"), |
117 |
("all_instances_info", MULTI, TMO_URGENT, [
|
118 |
("hypervisor_list", None, "Hypervisors to query for instances"), |
119 |
], None, "Returns information about all instances on the given nodes"), |
120 |
("instance_list", MULTI, TMO_URGENT, [
|
121 |
("hypervisor_list", None, "Hypervisors to query for instances"), |
122 |
], None, "Returns the list of running instances on the given nodes"), |
123 |
("instance_reboot", SINGLE, TMO_NORMAL, [
|
124 |
("inst", ED_INST_DICT, "Instance object"), |
125 |
("reboot_type", None, None), |
126 |
("shutdown_timeout", None, None), |
127 |
], None, "Returns the list of running instances on the given nodes"), |
128 |
("instance_shutdown", SINGLE, TMO_NORMAL, [
|
129 |
("instance", ED_INST_DICT, "Instance object"), |
130 |
("timeout", None, None), |
131 |
], None, "Stops an instance"), |
132 |
("instance_run_rename", SINGLE, TMO_SLOW, [
|
133 |
("instance", ED_INST_DICT, "Instance object"), |
134 |
("old_name", None, None), |
135 |
("debug", None, None), |
136 |
], None, "Run the OS rename script for an instance"), |
137 |
("instance_migratable", SINGLE, TMO_NORMAL, [
|
138 |
("instance", ED_INST_DICT, "Instance object"), |
139 |
], None, "Checks whether the given instance can be migrated"), |
140 |
("migration_info", SINGLE, TMO_NORMAL, [
|
141 |
("instance", ED_INST_DICT, "Instance object"), |
142 |
], None,
|
143 |
"Gather the information necessary to prepare an instance migration"),
|
144 |
("accept_instance", SINGLE, TMO_NORMAL, [
|
145 |
("instance", ED_INST_DICT, "Instance object"), |
146 |
("info", None, "Result for the call_migration_info call"), |
147 |
("target", None, "Target hostname (usually an IP address)"), |
148 |
], None, "Prepare a node to accept an instance"), |
149 |
("instance_finalize_migration_dst", SINGLE, TMO_NORMAL, [
|
150 |
("instance", ED_INST_DICT, "Instance object"), |
151 |
("info", None, "Result for the call_migration_info call"), |
152 |
("success", None, "Whether the migration was a success or failure"), |
153 |
], None, "Finalize any target-node migration specific operation"), |
154 |
("instance_migrate", SINGLE, TMO_SLOW, [
|
155 |
("instance", ED_INST_DICT, "Instance object"), |
156 |
("target", None, "Target node name"), |
157 |
("live", None, "Whether the migration should be done live or not"), |
158 |
], None, "Migrate an instance"), |
159 |
("instance_finalize_migration_src", SINGLE, TMO_SLOW, [
|
160 |
("instance", ED_INST_DICT, "Instance object"), |
161 |
("success", None, "Whether the migration succeeded or not"), |
162 |
("live", None, "Whether the user requested a live migration or not"), |
163 |
], None, "Finalize the instance migration on the source node"), |
164 |
("instance_get_migration_status", SINGLE, TMO_SLOW, [
|
165 |
("instance", ED_INST_DICT, "Instance object"), |
166 |
], "self._MigrationStatusPostProc", "Report migration status"), |
167 |
("instance_start", SINGLE, TMO_NORMAL, [
|
168 |
("instance_hvp_bep", ED_INST_DICT_HVP_BEP, None), |
169 |
("startup_paused", None, None), |
170 |
], None, "Starts an instance"), |
171 |
("instance_os_add", SINGLE, TMO_1DAY, [
|
172 |
("instance_osp", ED_INST_DICT_OSP, None), |
173 |
("reinstall", None, None), |
174 |
("debug", None, None), |
175 |
], None, "Starts an instance"), |
176 |
] |
177 |
|
178 |
_IMPEXP_CALLS = [ |
179 |
("import_start", SINGLE, TMO_NORMAL, [
|
180 |
("opts", ED_OBJECT_DICT, None), |
181 |
("instance", ED_INST_DICT, None), |
182 |
("component", None, None), |
183 |
("dest", ED_IMPEXP_IO, "Import destination"), |
184 |
], None, "Starts an import daemon"), |
185 |
("export_start", SINGLE, TMO_NORMAL, [
|
186 |
("opts", ED_OBJECT_DICT, None), |
187 |
("host", None, None), |
188 |
("port", None, None), |
189 |
("instance", ED_INST_DICT, None), |
190 |
("component", None, None), |
191 |
("source", ED_IMPEXP_IO, "Export source"), |
192 |
], None, "Starts an export daemon"), |
193 |
("impexp_status", SINGLE, TMO_FAST, [
|
194 |
("names", None, "Import/export names"), |
195 |
], "self._ImpExpStatusPostProc", "Gets the status of an import or export"), |
196 |
("impexp_abort", SINGLE, TMO_NORMAL, [
|
197 |
("name", None, "Import/export name"), |
198 |
], None, "Aborts an import or export"), |
199 |
("impexp_cleanup", SINGLE, TMO_NORMAL, [
|
200 |
("name", None, "Import/export name"), |
201 |
], None, "Cleans up after an import or export"), |
202 |
("export_info", SINGLE, TMO_FAST, [
|
203 |
("path", None, None), |
204 |
], None, "Queries the export information in a given path"), |
205 |
("finalize_export", SINGLE, TMO_NORMAL, [
|
206 |
("instance", ED_INST_DICT, None), |
207 |
("snap_disks", ED_FINALIZE_EXPORT_DISKS, None), |
208 |
], None, "Request the completion of an export operation"), |
209 |
("export_list", MULTI, TMO_FAST, [], None, "Gets the stored exports list"), |
210 |
("export_remove", SINGLE, TMO_FAST, [
|
211 |
("export", None, None), |
212 |
], None, "Requests removal of a given export"), |
213 |
] |
214 |
|
215 |
_X509_CALLS = [ |
216 |
("x509_cert_create", SINGLE, TMO_NORMAL, [
|
217 |
("validity", None, "Validity in seconds"), |
218 |
], None, "Creates a new X509 certificate for SSL/TLS"), |
219 |
("x509_cert_remove", SINGLE, TMO_NORMAL, [
|
220 |
("name", None, "Certificate name"), |
221 |
], None, "Removes a X509 certificate"), |
222 |
] |
223 |
|
224 |
_BLOCKDEV_CALLS = [ |
225 |
("bdev_sizes", MULTI, TMO_URGENT, [
|
226 |
("devices", None, None), |
227 |
], None, "Gets the sizes of requested block devices present on a node"), |
228 |
("blockdev_create", SINGLE, TMO_NORMAL, [
|
229 |
("bdev", ED_OBJECT_DICT, None), |
230 |
("size", None, None), |
231 |
("owner", None, None), |
232 |
("on_primary", None, None), |
233 |
("info", None, None), |
234 |
], None, "Request creation of a given block device"), |
235 |
("blockdev_wipe", SINGLE, TMO_SLOW, [
|
236 |
("bdev", ED_OBJECT_DICT, None), |
237 |
("offset", None, None), |
238 |
("size", None, None), |
239 |
], None,
|
240 |
"Request wipe at given offset with given size of a block device"),
|
241 |
("blockdev_remove", SINGLE, TMO_NORMAL, [
|
242 |
("bdev", ED_OBJECT_DICT, None), |
243 |
], None, "Request removal of a given block device"), |
244 |
("blockdev_pause_resume_sync", SINGLE, TMO_NORMAL, [
|
245 |
("disks", ED_OBJECT_DICT_LIST, None), |
246 |
("pause", None, None), |
247 |
], None, "Request a pause/resume of given block device"), |
248 |
("blockdev_assemble", SINGLE, TMO_NORMAL, [
|
249 |
("disk", ED_OBJECT_DICT, None), |
250 |
("owner", None, None), |
251 |
("on_primary", None, None), |
252 |
("idx", None, None), |
253 |
], None, "Request assembling of a given block device"), |
254 |
("blockdev_shutdown", SINGLE, TMO_NORMAL, [
|
255 |
("disk", ED_OBJECT_DICT, None), |
256 |
], None, "Request shutdown of a given block device"), |
257 |
("blockdev_addchildren", SINGLE, TMO_NORMAL, [
|
258 |
("bdev", ED_OBJECT_DICT, None), |
259 |
("ndevs", ED_OBJECT_DICT_LIST, None), |
260 |
], None, "Request adding a list of children to a (mirroring) device"), |
261 |
("blockdev_removechildren", SINGLE, TMO_NORMAL, [
|
262 |
("bdev", ED_OBJECT_DICT, None), |
263 |
("ndevs", ED_OBJECT_DICT_LIST, None), |
264 |
], None, "Request removing a list of children from a (mirroring) device"), |
265 |
("blockdev_close", SINGLE, TMO_NORMAL, [
|
266 |
("instance_name", None, None), |
267 |
("disks", ED_OBJECT_DICT_LIST, None), |
268 |
], None, "Closes the given block devices"), |
269 |
("blockdev_getsize", SINGLE, TMO_NORMAL, [
|
270 |
("disks", ED_OBJECT_DICT_LIST, None), |
271 |
], None, "Returns the size of the given disks"), |
272 |
("drbd_disconnect_net", MULTI, TMO_NORMAL, [
|
273 |
("nodes_ip", None, None), |
274 |
("disks", ED_OBJECT_DICT_LIST, None), |
275 |
], None, "Disconnects the network of the given drbd devices"), |
276 |
("drbd_attach_net", MULTI, TMO_NORMAL, [
|
277 |
("nodes_ip", None, None), |
278 |
("disks", ED_OBJECT_DICT_LIST, None), |
279 |
("instance_name", None, None), |
280 |
("multimaster", None, None), |
281 |
], None, "Connects the given DRBD devices"), |
282 |
("drbd_wait_sync", MULTI, TMO_SLOW, [
|
283 |
("nodes_ip", None, None), |
284 |
("disks", ED_OBJECT_DICT_LIST, None), |
285 |
], None, "Waits for the synchronization of drbd devices is complete"), |
286 |
("blockdev_grow", SINGLE, TMO_NORMAL, [
|
287 |
("cf_bdev", ED_OBJECT_DICT, None), |
288 |
("amount", None, None), |
289 |
("dryrun", None, None), |
290 |
], None, "Request a snapshot of the given block device"), |
291 |
("blockdev_export", SINGLE, TMO_1DAY, [
|
292 |
("cf_bdev", ED_OBJECT_DICT, None), |
293 |
("dest_node", None, None), |
294 |
("dest_path", None, None), |
295 |
("cluster_name", None, None), |
296 |
], None, "Export a given disk to another node"), |
297 |
("blockdev_snapshot", SINGLE, TMO_NORMAL, [
|
298 |
("cf_bdev", ED_OBJECT_DICT, None), |
299 |
], None, "Export a given disk to another node"), |
300 |
("blockdev_rename", SINGLE, TMO_NORMAL, [
|
301 |
("devlist", ED_BLOCKDEV_RENAME, None), |
302 |
], None, "Request rename of the given block devices"), |
303 |
("blockdev_find", SINGLE, TMO_NORMAL, [
|
304 |
("disk", ED_OBJECT_DICT, None), |
305 |
], "self._BlockdevFindPostProc",
|
306 |
"Request identification of a given block device"),
|
307 |
("blockdev_getmirrorstatus", SINGLE, TMO_NORMAL, [
|
308 |
("disks", ED_OBJECT_DICT_LIST, None), |
309 |
], "self._BlockdevGetMirrorStatusPostProc",
|
310 |
"Request status of a (mirroring) device"),
|
311 |
("blockdev_getmirrorstatus_multi", MULTI, TMO_NORMAL, [
|
312 |
("node_disks", ED_NODE_TO_DISK_DICT, None), |
313 |
], "self._BlockdevGetMirrorStatusMultiPostProc",
|
314 |
"Request status of (mirroring) devices from multiple nodes"),
|
315 |
] |
316 |
|
317 |
_OS_CALLS = [ |
318 |
("os_diagnose", MULTI, TMO_FAST, [], None, |
319 |
"Request a diagnose of OS definitions"),
|
320 |
("os_validate", MULTI, TMO_FAST, [
|
321 |
("required", None, None), |
322 |
("name", None, None), |
323 |
("checks", None, None), |
324 |
("params", None, None), |
325 |
], None, "Run a validation routine for a given OS"), |
326 |
("os_get", SINGLE, TMO_FAST, [
|
327 |
("name", None, None), |
328 |
], "self._OsGetPostProc", "Returns an OS definition"), |
329 |
] |
330 |
|
331 |
_NODE_CALLS = [ |
332 |
("node_has_ip_address", SINGLE, TMO_FAST, [
|
333 |
("address", None, "IP address"), |
334 |
], None, "Checks if a node has the given IP address"), |
335 |
("node_info", MULTI, TMO_URGENT, [
|
336 |
("vg_name", None, |
337 |
"Name of the volume group to ask for disk space information"),
|
338 |
("hypervisor_type", None, |
339 |
"Name of the hypervisor to ask for memory information"),
|
340 |
], None, "Return node information"), |
341 |
("node_verify", MULTI, TMO_NORMAL, [
|
342 |
("checkdict", None, None), |
343 |
("cluster_name", None, None), |
344 |
], None, "Request verification of given parameters"), |
345 |
("node_volumes", MULTI, TMO_FAST, [], None, "Gets all volumes on node(s)"), |
346 |
("node_demote_from_mc", SINGLE, TMO_FAST, [], None, |
347 |
"Demote a node from the master candidate role"),
|
348 |
("node_powercycle", SINGLE, TMO_NORMAL, [
|
349 |
("hypervisor", None, "Hypervisor type"), |
350 |
], None, "Tries to powercycle a node"), |
351 |
] |
352 |
|
353 |
_MISC_CALLS = [ |
354 |
("lv_list", MULTI, TMO_URGENT, [
|
355 |
("vg_name", None, None), |
356 |
], None, "Gets the logical volumes present in a given volume group"), |
357 |
("vg_list", MULTI, TMO_URGENT, [], None, "Gets the volume group list"), |
358 |
("bridges_exist", SINGLE, TMO_URGENT, [
|
359 |
("bridges_list", None, "Bridges which must be present on remote node"), |
360 |
], None, "Checks if a node has all the bridges given"), |
361 |
("etc_hosts_modify", SINGLE, TMO_NORMAL, [
|
362 |
("mode", None, |
363 |
"Mode to operate; currently L{constants.ETC_HOSTS_ADD} or"
|
364 |
" L{constants.ETC_HOSTS_REMOVE}"),
|
365 |
("name", None, "Hostname to be modified"), |
366 |
("ip", None, "IP address (L{constants.ETC_HOSTS_ADD} only)"), |
367 |
], None, "Modify hosts file with name"), |
368 |
("drbd_helper", MULTI, TMO_URGENT, [], None, "Gets DRBD helper"), |
369 |
("run_oob", SINGLE, TMO_NORMAL, [
|
370 |
("oob_program", None, None), |
371 |
("command", None, None), |
372 |
("remote_node", None, None), |
373 |
("timeout", None, None), |
374 |
], None, "Runs out-of-band command"), |
375 |
("hooks_runner", MULTI, TMO_NORMAL, [
|
376 |
("hpath", None, None), |
377 |
("phase", None, None), |
378 |
("env", None, None), |
379 |
], None, "Call the hooks runner"), |
380 |
("iallocator_runner", SINGLE, TMO_NORMAL, [
|
381 |
("name", None, "Iallocator name"), |
382 |
("idata", None, "JSON-encoded input string"), |
383 |
], None, "Call an iallocator on a remote node"), |
384 |
("test_delay", MULTI, None, [ |
385 |
("duration", None, None), |
386 |
], None, "Sleep for a fixed time on given node(s)"), |
387 |
("hypervisor_validate_params", MULTI, TMO_NORMAL, [
|
388 |
("hvname", None, "Hypervisor name"), |
389 |
("hvfull", None, "Parameters to be validated"), |
390 |
], None, "Validate hypervisor params"), |
391 |
] |
392 |
|
393 |
CALLS = { |
394 |
"RpcClientDefault": \
|
395 |
_Prepare(_IMPEXP_CALLS + _X509_CALLS + _OS_CALLS + _NODE_CALLS + |
396 |
_FILE_STORAGE_CALLS + _MISC_CALLS + _INSTANCE_CALLS + |
397 |
_BLOCKDEV_CALLS + _STORAGE_CALLS), |
398 |
"RpcClientJobQueue": _Prepare([
|
399 |
("jobqueue_update", MULTI, TMO_URGENT, [
|
400 |
("file_name", None, None), |
401 |
("content", ED_COMPRESS, None), |
402 |
], None, "Update job queue file"), |
403 |
("jobqueue_purge", SINGLE, TMO_NORMAL, [], None, "Purge job queue"), |
404 |
("jobqueue_rename", MULTI, TMO_URGENT, [
|
405 |
("rename", None, None), |
406 |
], None, "Rename job queue file"), |
407 |
]), |
408 |
"RpcClientBootstrap": _Prepare([
|
409 |
("node_start_master_daemons", SINGLE, TMO_FAST, [
|
410 |
("no_voting", None, None), |
411 |
], None, "Starts master daemons on a node"), |
412 |
("node_activate_master_ip", SINGLE, TMO_FAST, [
|
413 |
("master_params", ED_OBJECT_DICT, "Network parameters of the master"), |
414 |
], None,
|
415 |
"Activates master IP on a node"),
|
416 |
("node_stop_master", SINGLE, TMO_FAST, [], None, |
417 |
"Deactivates master IP and stops master daemons on a node"),
|
418 |
("node_deactivate_master_ip", SINGLE, TMO_FAST, [
|
419 |
("master_params", ED_OBJECT_DICT, "Network parameters of the master"), |
420 |
], None,
|
421 |
"Deactivates master IP on a node"),
|
422 |
("node_change_master_netmask", SINGLE, TMO_FAST, [
|
423 |
("old_netmask", None, "The old value of the netmask"), |
424 |
("netmask", None, "The new value of the netmask"), |
425 |
("master_ip", None, "The master IP"), |
426 |
("master_netdev", None, "The master network device"), |
427 |
], None, "Change master IP netmask"), |
428 |
("node_leave_cluster", SINGLE, TMO_NORMAL, [
|
429 |
("modify_ssh_setup", None, None), |
430 |
], None, "Requests a node to clean the cluster information it has"), |
431 |
("master_info", MULTI, TMO_URGENT, [], None, "Query master info"), |
432 |
("version", MULTI, TMO_URGENT, [], None, "Query node version"), |
433 |
]), |
434 |
"RpcClientConfig": _Prepare([
|
435 |
("upload_file", MULTI, TMO_NORMAL, [
|
436 |
("file_name", ED_FILE_DETAILS, None), |
437 |
], None, "Upload a file"), |
438 |
("write_ssconf_files", MULTI, TMO_NORMAL, [
|
439 |
("values", None, None), |
440 |
], None, "Write ssconf files"), |
441 |
]), |
442 |
} |