4 # Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012 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
21 """RPC definitions for communication between master and node daemons.
23 RPC definition fields:
26 - L{SINGLE} for single-node calls, L{MULTI} for multi-node
27 - Name resolver option(s), can be callable receiving all arguments in a tuple
28 - Timeout (e.g. L{TMO_NORMAL}), or callback receiving all arguments in a
29 tuple to calculate timeout
30 - List of arguments as tuples
33 - Argument kind used for encoding/decoding
34 - Description for docstring (can be C{None})
36 - Custom body encoder (e.g. for preparing per-node bodies)
37 - Return value wrapper (e.g. for deserializing into L{objects}-based objects)
38 - Short call description for docstring
42 from ganeti import utils
43 from ganeti import objects
46 # Guidelines for choosing timeouts:
47 # - call used during watcher: timeout of 1min, _TMO_URGENT
48 # - trivial (but be sure it is trivial) (e.g. reading a file): 5min, _TMO_FAST
49 # - other calls: 15 min, _TMO_NORMAL
50 # - special calls (instance add, etc.): either _TMO_SLOW (1h) or huge timeouts
51 TMO_URGENT = 60 # one minute
52 TMO_FAST = 5 * 60 # five minutes
53 TMO_NORMAL = 15 * 60 # 15 minutes
54 TMO_SLOW = 3600 # one hour
58 SINGLE = "single-node"
61 ACCEPT_OFFLINE_NODE = object()
63 # Constants for encoding/decoding
72 ED_FINALIZE_EXPORT_DISKS,
76 ED_SINGLE_DISK_DICT_DP) = range(1, 14)
80 """Converts list of calls to dictionary.
83 return utils.SequenceToDict(calls)
86 def _MigrationStatusPostProc(result):
87 """Post-processor for L{rpc.RpcRunner.call_instance_get_migration_status}.
90 if not result.fail_msg and result.payload is not None:
91 result.payload = objects.MigrationStatus.FromDict(result.payload)
95 def _BlockdevFindPostProc(result):
96 """Post-processor for L{rpc.RpcRunner.call_blockdev_find}.
99 if not result.fail_msg and result.payload is not None:
100 result.payload = objects.BlockDevStatus.FromDict(result.payload)
104 def _BlockdevGetMirrorStatusPostProc(result):
105 """Post-processor for L{rpc.RpcRunner.call_blockdev_getmirrorstatus}.
108 if not result.fail_msg:
109 result.payload = map(objects.BlockDevStatus.FromDict, result.payload)
113 def _BlockdevGetMirrorStatusMultiPreProc(node, args):
114 """Prepares the appropriate node values for blockdev_getmirrorstatus_multi.
117 # there should be only one argument to this RPC, already holding a
118 # node->disks dictionary, we just need to extract the value for the
120 assert len(args) == 1
121 return [args[0][node]]
124 def _BlockdevGetMirrorStatusMultiPostProc(result):
125 """Post-processor for L{rpc.RpcRunner.call_blockdev_getmirrorstatus_multi}.
128 if not result.fail_msg:
129 for idx, (success, status) in enumerate(result.payload):
131 result.payload[idx] = (success, objects.BlockDevStatus.FromDict(status))
136 def _OsGetPostProc(result):
137 """Post-processor for L{rpc.RpcRunner.call_os_get}.
140 if not result.fail_msg and isinstance(result.payload, dict):
141 result.payload = objects.OS.FromDict(result.payload)
145 def _ImpExpStatusPostProc(result):
146 """Post-processor for import/export status.
148 @rtype: Payload containing list of L{objects.ImportExportStatus} instances
149 @return: Returns a list of the state of each named import/export or None if
150 a status couldn't be retrieved
153 if not result.fail_msg:
156 for i in result.payload:
160 decoded.append(objects.ImportExportStatus.FromDict(i))
162 result.payload = decoded
167 def _TestDelayTimeout((duration, )):
168 """Calculate timeout for "test_delay" RPC.
171 return int(duration + 5)
174 _FILE_STORAGE_CALLS = [
175 ("file_storage_dir_create", SINGLE, None, TMO_FAST, [
176 ("file_storage_dir", None, "File storage directory"),
177 ], None, None, "Create the given file storage directory"),
178 ("file_storage_dir_remove", SINGLE, None, TMO_FAST, [
179 ("file_storage_dir", None, "File storage directory"),
180 ], None, None, "Remove the given file storage directory"),
181 ("file_storage_dir_rename", SINGLE, None, TMO_FAST, [
182 ("old_file_storage_dir", None, "Old name"),
183 ("new_file_storage_dir", None, "New name"),
184 ], None, None, "Rename file storage directory"),
188 ("storage_list", MULTI, None, TMO_NORMAL, [
189 ("su_name", None, None),
190 ("su_args", None, None),
191 ("name", None, None),
192 ("fields", None, None),
193 ], None, None, "Get list of storage units"),
194 ("storage_modify", SINGLE, None, TMO_NORMAL, [
195 ("su_name", None, None),
196 ("su_args", None, None),
197 ("name", None, None),
198 ("changes", None, None),
199 ], None, None, "Modify a storage unit"),
200 ("storage_execute", SINGLE, None, TMO_NORMAL, [
201 ("su_name", None, None),
202 ("su_args", None, None),
203 ("name", None, None),
205 ], None, None, "Executes an operation on a storage unit"),
209 ("instance_info", SINGLE, None, TMO_URGENT, [
210 ("instance", None, "Instance name"),
211 ("hname", None, "Hypervisor type"),
212 ], None, None, "Returns information about a single instance"),
213 ("all_instances_info", MULTI, None, TMO_URGENT, [
214 ("hypervisor_list", None, "Hypervisors to query for instances"),
216 "Returns information about all instances on the given nodes"),
217 ("instance_list", MULTI, None, TMO_URGENT, [
218 ("hypervisor_list", None, "Hypervisors to query for instances"),
219 ], None, None, "Returns the list of running instances on the given nodes"),
220 ("instance_reboot", SINGLE, None, TMO_NORMAL, [
221 ("inst", ED_INST_DICT, "Instance object"),
222 ("reboot_type", None, None),
223 ("shutdown_timeout", None, None),
224 ], None, None, "Returns the list of running instances on the given nodes"),
225 ("instance_shutdown", SINGLE, None, TMO_NORMAL, [
226 ("instance", ED_INST_DICT, "Instance object"),
227 ("timeout", None, None),
228 ], None, None, "Stops an instance"),
229 ("instance_balloon_memory", SINGLE, None, TMO_NORMAL, [
230 ("instance", ED_INST_DICT, "Instance object"),
231 ("memory", None, None),
232 ], None, None, "Modify the amount of an instance's runtime memory"),
233 ("instance_run_rename", SINGLE, None, TMO_SLOW, [
234 ("instance", ED_INST_DICT, "Instance object"),
235 ("old_name", None, None),
236 ("debug", None, None),
237 ], None, None, "Run the OS rename script for an instance"),
238 ("instance_migratable", SINGLE, None, TMO_NORMAL, [
239 ("instance", ED_INST_DICT, "Instance object"),
240 ], None, None, "Checks whether the given instance can be migrated"),
241 ("migration_info", SINGLE, None, TMO_NORMAL, [
242 ("instance", ED_INST_DICT, "Instance object"),
244 "Gather the information necessary to prepare an instance migration"),
245 ("accept_instance", SINGLE, None, TMO_NORMAL, [
246 ("instance", ED_INST_DICT, "Instance object"),
247 ("info", None, "Result for the call_migration_info call"),
248 ("target", None, "Target hostname (usually an IP address)"),
249 ], None, None, "Prepare a node to accept an instance"),
250 ("instance_finalize_migration_dst", SINGLE, None, TMO_NORMAL, [
251 ("instance", ED_INST_DICT, "Instance object"),
252 ("info", None, "Result for the call_migration_info call"),
253 ("success", None, "Whether the migration was a success or failure"),
254 ], None, None, "Finalize any target-node migration specific operation"),
255 ("instance_migrate", SINGLE, None, TMO_SLOW, [
256 ("instance", ED_INST_DICT, "Instance object"),
257 ("target", None, "Target node name"),
258 ("live", None, "Whether the migration should be done live or not"),
259 ], None, None, "Migrate an instance"),
260 ("instance_finalize_migration_src", SINGLE, None, TMO_SLOW, [
261 ("instance", ED_INST_DICT, "Instance object"),
262 ("success", None, "Whether the migration succeeded or not"),
263 ("live", None, "Whether the user requested a live migration or not"),
264 ], None, None, "Finalize the instance migration on the source node"),
265 ("instance_get_migration_status", SINGLE, None, TMO_SLOW, [
266 ("instance", ED_INST_DICT, "Instance object"),
267 ], None, _MigrationStatusPostProc, "Report migration status"),
268 ("instance_start", SINGLE, None, TMO_NORMAL, [
269 ("instance_hvp_bep", ED_INST_DICT_HVP_BEP, None),
270 ("startup_paused", None, None),
271 ], None, None, "Starts an instance"),
272 ("instance_os_add", SINGLE, None, TMO_1DAY, [
273 ("instance_osp", ED_INST_DICT_OSP_DP, None),
274 ("reinstall", None, None),
275 ("debug", None, None),
276 ], None, None, "Starts an instance"),
280 ("import_start", SINGLE, None, TMO_NORMAL, [
281 ("opts", ED_OBJECT_DICT, None),
282 ("instance", ED_INST_DICT, None),
283 ("component", None, None),
284 ("dest", ED_IMPEXP_IO, "Import destination"),
285 ], None, None, "Starts an import daemon"),
286 ("export_start", SINGLE, None, TMO_NORMAL, [
287 ("opts", ED_OBJECT_DICT, None),
288 ("host", None, None),
289 ("port", None, None),
290 ("instance", ED_INST_DICT, None),
291 ("component", None, None),
292 ("source", ED_IMPEXP_IO, "Export source"),
293 ], None, None, "Starts an export daemon"),
294 ("impexp_status", SINGLE, None, TMO_FAST, [
295 ("names", None, "Import/export names"),
296 ], None, _ImpExpStatusPostProc, "Gets the status of an import or export"),
297 ("impexp_abort", SINGLE, None, TMO_NORMAL, [
298 ("name", None, "Import/export name"),
299 ], None, None, "Aborts an import or export"),
300 ("impexp_cleanup", SINGLE, None, TMO_NORMAL, [
301 ("name", None, "Import/export name"),
302 ], None, None, "Cleans up after an import or export"),
303 ("export_info", SINGLE, None, TMO_FAST, [
304 ("path", None, None),
305 ], None, None, "Queries the export information in a given path"),
306 ("finalize_export", SINGLE, None, TMO_NORMAL, [
307 ("instance", ED_INST_DICT, None),
308 ("snap_disks", ED_FINALIZE_EXPORT_DISKS, None),
309 ], None, None, "Request the completion of an export operation"),
310 ("export_list", MULTI, None, TMO_FAST, [], None, None,
311 "Gets the stored exports list"),
312 ("export_remove", SINGLE, None, TMO_FAST, [
313 ("export", None, None),
314 ], None, None, "Requests removal of a given export"),
318 ("x509_cert_create", SINGLE, None, TMO_NORMAL, [
319 ("validity", None, "Validity in seconds"),
320 ], None, None, "Creates a new X509 certificate for SSL/TLS"),
321 ("x509_cert_remove", SINGLE, None, TMO_NORMAL, [
322 ("name", None, "Certificate name"),
323 ], None, None, "Removes a X509 certificate"),
327 ("bdev_sizes", MULTI, None, TMO_URGENT, [
328 ("devices", None, None),
330 "Gets the sizes of requested block devices present on a node"),
331 ("blockdev_create", SINGLE, None, TMO_NORMAL, [
332 ("bdev", ED_OBJECT_DICT, None),
333 ("size", None, None),
334 ("owner", None, None),
335 ("on_primary", None, None),
336 ("info", None, None),
337 ], None, None, "Request creation of a given block device"),
338 ("blockdev_wipe", SINGLE, None, TMO_SLOW, [
339 ("bdev", ED_SINGLE_DISK_DICT_DP, None),
340 ("offset", None, None),
341 ("size", None, None),
343 "Request wipe at given offset with given size of a block device"),
344 ("blockdev_remove", SINGLE, None, TMO_NORMAL, [
345 ("bdev", ED_OBJECT_DICT, None),
346 ], None, None, "Request removal of a given block device"),
347 ("blockdev_pause_resume_sync", SINGLE, None, TMO_NORMAL, [
348 ("disks", ED_DISKS_DICT_DP, None),
349 ("pause", None, None),
350 ], None, None, "Request a pause/resume of given block device"),
351 ("blockdev_assemble", SINGLE, None, TMO_NORMAL, [
352 ("disk", ED_SINGLE_DISK_DICT_DP, None),
353 ("owner", None, None),
354 ("on_primary", None, None),
356 ], None, None, "Request assembling of a given block device"),
357 ("blockdev_shutdown", SINGLE, None, TMO_NORMAL, [
358 ("disk", ED_SINGLE_DISK_DICT_DP, None),
359 ], None, None, "Request shutdown of a given block device"),
360 ("blockdev_addchildren", SINGLE, None, TMO_NORMAL, [
361 ("bdev", ED_SINGLE_DISK_DICT_DP, None),
362 ("ndevs", ED_OBJECT_DICT_LIST, None),
364 "Request adding a list of children to a (mirroring) device"),
365 ("blockdev_removechildren", SINGLE, None, TMO_NORMAL, [
366 ("bdev", ED_OBJECT_DICT, None),
367 ("ndevs", ED_OBJECT_DICT_LIST, None),
369 "Request removing a list of children from a (mirroring) device"),
370 ("blockdev_close", SINGLE, None, TMO_NORMAL, [
371 ("instance_name", None, None),
372 ("disks", ED_OBJECT_DICT_LIST, None),
373 ], None, None, "Closes the given block devices"),
374 ("blockdev_getsize", SINGLE, None, TMO_NORMAL, [
375 ("disks", ED_OBJECT_DICT_LIST, None),
376 ], None, None, "Returns the size of the given disks"),
377 ("drbd_disconnect_net", MULTI, None, TMO_NORMAL, [
378 ("nodes_ip", None, None),
379 ("disks", ED_OBJECT_DICT_LIST, None),
380 ], None, None, "Disconnects the network of the given drbd devices"),
381 ("drbd_attach_net", MULTI, None, TMO_NORMAL, [
382 ("nodes_ip", None, None),
383 ("disks", ED_DISKS_DICT_DP, None),
384 ("instance_name", None, None),
385 ("multimaster", None, None),
386 ], None, None, "Connects the given DRBD devices"),
387 ("drbd_wait_sync", MULTI, None, TMO_SLOW, [
388 ("nodes_ip", None, None),
389 ("disks", ED_DISKS_DICT_DP, None),
391 "Waits for the synchronization of drbd devices is complete"),
392 ("blockdev_grow", SINGLE, None, TMO_NORMAL, [
393 ("cf_bdev", ED_SINGLE_DISK_DICT_DP, None),
394 ("amount", None, None),
395 ("dryrun", None, None),
396 ("backingstore", None, None),
397 ], None, None, "Request growing of the given block device by a"
399 ("blockdev_export", SINGLE, None, TMO_1DAY, [
400 ("cf_bdev", ED_SINGLE_DISK_DICT_DP, None),
401 ("dest_node", None, None),
402 ("dest_path", None, None),
403 ("cluster_name", None, None),
404 ], None, None, "Export a given disk to another node"),
405 ("blockdev_snapshot", SINGLE, None, TMO_NORMAL, [
406 ("cf_bdev", ED_SINGLE_DISK_DICT_DP, None),
407 ], None, None, "Export a given disk to another node"),
408 ("blockdev_rename", SINGLE, None, TMO_NORMAL, [
409 ("devlist", ED_BLOCKDEV_RENAME, None),
410 ], None, None, "Request rename of the given block devices"),
411 ("blockdev_find", SINGLE, None, TMO_NORMAL, [
412 ("disk", ED_OBJECT_DICT, None),
413 ], None, _BlockdevFindPostProc,
414 "Request identification of a given block device"),
415 ("blockdev_getmirrorstatus", SINGLE, None, TMO_NORMAL, [
416 ("disks", ED_DISKS_DICT_DP, None),
417 ], None, _BlockdevGetMirrorStatusPostProc,
418 "Request status of a (mirroring) device"),
419 ("blockdev_getmirrorstatus_multi", MULTI, None, TMO_NORMAL, [
420 ("node_disks", ED_NODE_TO_DISK_DICT, None),
421 ], _BlockdevGetMirrorStatusMultiPreProc,
422 _BlockdevGetMirrorStatusMultiPostProc,
423 "Request status of (mirroring) devices from multiple nodes"),
427 ("os_diagnose", MULTI, None, TMO_FAST, [], None, None,
428 "Request a diagnose of OS definitions"),
429 ("os_validate", MULTI, None, TMO_FAST, [
430 ("required", None, None),
431 ("name", None, None),
432 ("checks", None, None),
433 ("params", None, None),
434 ], None, None, "Run a validation routine for a given OS"),
435 ("os_get", SINGLE, None, TMO_FAST, [
436 ("name", None, None),
437 ], None, _OsGetPostProc, "Returns an OS definition"),
441 ("node_has_ip_address", SINGLE, None, TMO_FAST, [
442 ("address", None, "IP address"),
443 ], None, None, "Checks if a node has the given IP address"),
444 ("node_info", MULTI, None, TMO_URGENT, [
446 "Names of the volume groups to ask for disk space information"),
448 "Names of the hypervisors to ask for node information"),
449 ], None, None, "Return node information"),
450 ("node_verify", MULTI, None, TMO_NORMAL, [
451 ("checkdict", None, None),
452 ("cluster_name", None, None),
453 ], None, None, "Request verification of given parameters"),
454 ("node_volumes", MULTI, None, TMO_FAST, [], None, None,
455 "Gets all volumes on node(s)"),
456 ("node_demote_from_mc", SINGLE, None, TMO_FAST, [], None, None,
457 "Demote a node from the master candidate role"),
458 ("node_powercycle", SINGLE, ACCEPT_OFFLINE_NODE, TMO_NORMAL, [
459 ("hypervisor", None, "Hypervisor type"),
460 ], None, None, "Tries to powercycle a node"),
464 ("lv_list", MULTI, None, TMO_URGENT, [
465 ("vg_name", None, None),
466 ], None, None, "Gets the logical volumes present in a given volume group"),
467 ("vg_list", MULTI, None, TMO_URGENT, [], None, None,
468 "Gets the volume group list"),
469 ("bridges_exist", SINGLE, None, TMO_URGENT, [
470 ("bridges_list", None, "Bridges which must be present on remote node"),
471 ], None, None, "Checks if a node has all the bridges given"),
472 ("etc_hosts_modify", SINGLE, None, TMO_NORMAL, [
474 "Mode to operate; currently L{constants.ETC_HOSTS_ADD} or"
475 " L{constants.ETC_HOSTS_REMOVE}"),
476 ("name", None, "Hostname to be modified"),
477 ("ip", None, "IP address (L{constants.ETC_HOSTS_ADD} only)"),
478 ], None, None, "Modify hosts file with name"),
479 ("drbd_helper", MULTI, None, TMO_URGENT, [], None, None, "Gets DRBD helper"),
480 ("run_oob", SINGLE, None, TMO_NORMAL, [
481 ("oob_program", None, None),
482 ("command", None, None),
483 ("remote_node", None, None),
484 ("timeout", None, None),
485 ], None, None, "Runs out-of-band command"),
486 ("hooks_runner", MULTI, None, TMO_NORMAL, [
487 ("hpath", None, None),
488 ("phase", None, None),
490 ], None, None, "Call the hooks runner"),
491 ("iallocator_runner", SINGLE, None, TMO_NORMAL, [
492 ("name", None, "Iallocator name"),
493 ("idata", None, "JSON-encoded input string"),
494 ], None, None, "Call an iallocator on a remote node"),
495 ("test_delay", MULTI, None, _TestDelayTimeout, [
496 ("duration", None, None),
497 ], None, None, "Sleep for a fixed time on given node(s)"),
498 ("hypervisor_validate_params", MULTI, None, TMO_NORMAL, [
499 ("hvname", None, "Hypervisor name"),
500 ("hvfull", None, "Parameters to be validated"),
501 ], None, None, "Validate hypervisor params"),
505 "RpcClientDefault": \
506 _Prepare(_IMPEXP_CALLS + _X509_CALLS + _OS_CALLS + _NODE_CALLS +
507 _FILE_STORAGE_CALLS + _MISC_CALLS + _INSTANCE_CALLS +
508 _BLOCKDEV_CALLS + _STORAGE_CALLS),
509 "RpcClientJobQueue": _Prepare([
510 ("jobqueue_update", MULTI, None, TMO_URGENT, [
511 ("file_name", None, None),
512 ("content", ED_COMPRESS, None),
513 ], None, None, "Update job queue file"),
514 ("jobqueue_purge", SINGLE, None, TMO_NORMAL, [], None, None,
516 ("jobqueue_rename", MULTI, None, TMO_URGENT, [
517 ("rename", None, None),
518 ], None, None, "Rename job queue file"),
520 "RpcClientBootstrap": _Prepare([
521 ("node_start_master_daemons", SINGLE, None, TMO_FAST, [
522 ("no_voting", None, None),
523 ], None, None, "Starts master daemons on a node"),
524 ("node_activate_master_ip", SINGLE, None, TMO_FAST, [
525 ("master_params", ED_OBJECT_DICT, "Network parameters of the master"),
526 ("use_external_mip_script", None,
527 "Whether to use the user-provided master IP address setup script"),
529 "Activates master IP on a node"),
530 ("node_stop_master", SINGLE, None, TMO_FAST, [], None, None,
531 "Deactivates master IP and stops master daemons on a node"),
532 ("node_deactivate_master_ip", SINGLE, None, TMO_FAST, [
533 ("master_params", ED_OBJECT_DICT, "Network parameters of the master"),
534 ("use_external_mip_script", None,
535 "Whether to use the user-provided master IP address setup script"),
537 "Deactivates master IP on a node"),
538 ("node_change_master_netmask", SINGLE, None, TMO_FAST, [
539 ("old_netmask", None, "The old value of the netmask"),
540 ("netmask", None, "The new value of the netmask"),
541 ("master_ip", None, "The master IP"),
542 ("master_netdev", None, "The master network device"),
543 ], None, None, "Change master IP netmask"),
544 ("node_leave_cluster", SINGLE, None, TMO_NORMAL, [
545 ("modify_ssh_setup", None, None),
547 "Requests a node to clean the cluster information it has"),
548 ("master_info", MULTI, None, TMO_URGENT, [], None, None,
549 "Query master info"),
551 "RpcClientDnsOnly": _Prepare([
552 ("version", MULTI, ACCEPT_OFFLINE_NODE, TMO_URGENT, [], None, None,
553 "Query node version"),
555 "RpcClientConfig": _Prepare([
556 ("upload_file", MULTI, None, TMO_NORMAL, [
557 ("file_name", ED_FILE_DETAILS, None),
558 ], None, None, "Upload a file"),
559 ("write_ssconf_files", MULTI, None, TMO_NORMAL, [
560 ("values", None, None),
561 ], None, None, "Write ssconf files"),