4 # Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 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 - Timeout (e.g. L{TMO_NORMAL}), or callback receiving all arguments in a
28 tuple to calculate timeout
29 - List of arguments as tuples
32 - Argument kind used for encoding/decoding
33 - Description for docstring (can be C{None})
35 - Return value wrapper (e.g. for deserializing into L{objects}-based objects)
36 - Short call description for docstring
40 from ganeti import utils
41 from ganeti import objects
44 # Guidelines for choosing timeouts:
45 # - call used during watcher: timeout of 1min, _TMO_URGENT
46 # - trivial (but be sure it is trivial) (e.g. reading a file): 5min, _TMO_FAST
47 # - other calls: 15 min, _TMO_NORMAL
48 # - special calls (instance add, etc.): either _TMO_SLOW (1h) or huge timeouts
49 TMO_URGENT = 60 # one minute
50 TMO_FAST = 5 * 60 # five minutes
51 TMO_NORMAL = 15 * 60 # 15 minutes
52 TMO_SLOW = 3600 # one hour
56 SINGLE = "single-node"
59 # Constants for encoding/decoding
68 ED_FINALIZE_EXPORT_DISKS,
70 ED_BLOCKDEV_RENAME) = range(1, 12)
74 """Converts list of calls to dictionary.
77 return utils.SequenceToDict(calls)
80 def _MigrationStatusPostProc(result):
81 """Post-processor for L{rpc.RpcRunner.call_instance_get_migration_status}.
84 if not result.fail_msg and result.payload is not None:
85 result.payload = objects.MigrationStatus.FromDict(result.payload)
89 def _BlockdevFindPostProc(result):
90 """Post-processor for L{rpc.RpcRunner.call_blockdev_find}.
93 if not result.fail_msg and result.payload is not None:
94 result.payload = objects.BlockDevStatus.FromDict(result.payload)
98 def _BlockdevGetMirrorStatusPostProc(result):
99 """Post-processor for L{rpc.RpcRunner.call_blockdev_getmirrorstatus}.
102 if not result.fail_msg:
103 result.payload = map(objects.BlockDevStatus.FromDict, result.payload)
107 def _BlockdevGetMirrorStatusMultiPostProc(result):
108 """Post-processor for L{rpc.RpcRunner.call_blockdev_getmirrorstatus_multi}.
111 for nres in result.values():
115 for idx, (success, status) in enumerate(nres.payload):
117 nres.payload[idx] = (success, objects.BlockDevStatus.FromDict(status))
122 def _OsGetPostProc(result):
123 """Post-processor for L{rpc.RpcRunner.call_os_get}.
126 if not result.fail_msg and isinstance(result.payload, dict):
127 result.payload = objects.OS.FromDict(result.payload)
131 def _ImpExpStatusPostProc(result):
132 """Post-processor for import/export status.
134 @rtype: Payload containing list of L{objects.ImportExportStatus} instances
135 @return: Returns a list of the state of each named import/export or None if
136 a status couldn't be retrieved
139 if not result.fail_msg:
142 for i in result.payload:
146 decoded.append(objects.ImportExportStatus.FromDict(i))
148 result.payload = decoded
153 def _TestDelayTimeout((duration, )):
154 """Calculate timeout for "test_delay" RPC.
157 return int(duration + 5)
160 _FILE_STORAGE_CALLS = [
161 ("file_storage_dir_create", SINGLE, TMO_FAST, [
162 ("file_storage_dir", None, "File storage directory"),
163 ], None, "Create the given file storage directory"),
164 ("file_storage_dir_remove", SINGLE, TMO_FAST, [
165 ("file_storage_dir", None, "File storage directory"),
166 ], None, "Remove the given file storage directory"),
167 ("file_storage_dir_rename", SINGLE, TMO_FAST, [
168 ("old_file_storage_dir", None, "Old name"),
169 ("new_file_storage_dir", None, "New name"),
170 ], None, "Rename file storage directory"),
174 ("storage_list", MULTI, TMO_NORMAL, [
175 ("su_name", None, None),
176 ("su_args", None, None),
177 ("name", None, None),
178 ("fields", None, None),
179 ], None, "Get list of storage units"),
180 ("storage_modify", SINGLE, TMO_NORMAL, [
181 ("su_name", None, None),
182 ("su_args", None, None),
183 ("name", None, None),
184 ("changes", None, None),
185 ], None, "Modify a storage unit"),
186 ("storage_execute", SINGLE, TMO_NORMAL, [
187 ("su_name", None, None),
188 ("su_args", None, None),
189 ("name", None, None),
191 ], None, "Executes an operation on a storage unit"),
195 ("instance_info", SINGLE, TMO_URGENT, [
196 ("instance", None, "Instance name"),
197 ("hname", None, "Hypervisor type"),
198 ], None, "Returns information about a single instance"),
199 ("all_instances_info", MULTI, TMO_URGENT, [
200 ("hypervisor_list", None, "Hypervisors to query for instances"),
201 ], None, "Returns information about all instances on the given nodes"),
202 ("instance_list", MULTI, TMO_URGENT, [
203 ("hypervisor_list", None, "Hypervisors to query for instances"),
204 ], None, "Returns the list of running instances on the given nodes"),
205 ("instance_reboot", SINGLE, TMO_NORMAL, [
206 ("inst", ED_INST_DICT, "Instance object"),
207 ("reboot_type", None, None),
208 ("shutdown_timeout", None, None),
209 ], None, "Returns the list of running instances on the given nodes"),
210 ("instance_shutdown", SINGLE, TMO_NORMAL, [
211 ("instance", ED_INST_DICT, "Instance object"),
212 ("timeout", None, None),
213 ], None, "Stops an instance"),
214 ("instance_run_rename", SINGLE, TMO_SLOW, [
215 ("instance", ED_INST_DICT, "Instance object"),
216 ("old_name", None, None),
217 ("debug", None, None),
218 ], None, "Run the OS rename script for an instance"),
219 ("instance_migratable", SINGLE, TMO_NORMAL, [
220 ("instance", ED_INST_DICT, "Instance object"),
221 ], None, "Checks whether the given instance can be migrated"),
222 ("migration_info", SINGLE, TMO_NORMAL, [
223 ("instance", ED_INST_DICT, "Instance object"),
225 "Gather the information necessary to prepare an instance migration"),
226 ("accept_instance", SINGLE, TMO_NORMAL, [
227 ("instance", ED_INST_DICT, "Instance object"),
228 ("info", None, "Result for the call_migration_info call"),
229 ("target", None, "Target hostname (usually an IP address)"),
230 ], None, "Prepare a node to accept an instance"),
231 ("instance_finalize_migration_dst", SINGLE, TMO_NORMAL, [
232 ("instance", ED_INST_DICT, "Instance object"),
233 ("info", None, "Result for the call_migration_info call"),
234 ("success", None, "Whether the migration was a success or failure"),
235 ], None, "Finalize any target-node migration specific operation"),
236 ("instance_migrate", SINGLE, TMO_SLOW, [
237 ("instance", ED_INST_DICT, "Instance object"),
238 ("target", None, "Target node name"),
239 ("live", None, "Whether the migration should be done live or not"),
240 ], None, "Migrate an instance"),
241 ("instance_finalize_migration_src", SINGLE, TMO_SLOW, [
242 ("instance", ED_INST_DICT, "Instance object"),
243 ("success", None, "Whether the migration succeeded or not"),
244 ("live", None, "Whether the user requested a live migration or not"),
245 ], None, "Finalize the instance migration on the source node"),
246 ("instance_get_migration_status", SINGLE, TMO_SLOW, [
247 ("instance", ED_INST_DICT, "Instance object"),
248 ], _MigrationStatusPostProc, "Report migration status"),
249 ("instance_start", SINGLE, TMO_NORMAL, [
250 ("instance_hvp_bep", ED_INST_DICT_HVP_BEP, None),
251 ("startup_paused", None, None),
252 ], None, "Starts an instance"),
253 ("instance_os_add", SINGLE, TMO_1DAY, [
254 ("instance_osp", ED_INST_DICT_OSP, None),
255 ("reinstall", None, None),
256 ("debug", None, None),
257 ], None, "Starts an instance"),
261 ("import_start", SINGLE, TMO_NORMAL, [
262 ("opts", ED_OBJECT_DICT, None),
263 ("instance", ED_INST_DICT, None),
264 ("component", None, None),
265 ("dest", ED_IMPEXP_IO, "Import destination"),
266 ], None, "Starts an import daemon"),
267 ("export_start", SINGLE, TMO_NORMAL, [
268 ("opts", ED_OBJECT_DICT, None),
269 ("host", None, None),
270 ("port", None, None),
271 ("instance", ED_INST_DICT, None),
272 ("component", None, None),
273 ("source", ED_IMPEXP_IO, "Export source"),
274 ], None, "Starts an export daemon"),
275 ("impexp_status", SINGLE, TMO_FAST, [
276 ("names", None, "Import/export names"),
277 ], _ImpExpStatusPostProc, "Gets the status of an import or export"),
278 ("impexp_abort", SINGLE, TMO_NORMAL, [
279 ("name", None, "Import/export name"),
280 ], None, "Aborts an import or export"),
281 ("impexp_cleanup", SINGLE, TMO_NORMAL, [
282 ("name", None, "Import/export name"),
283 ], None, "Cleans up after an import or export"),
284 ("export_info", SINGLE, TMO_FAST, [
285 ("path", None, None),
286 ], None, "Queries the export information in a given path"),
287 ("finalize_export", SINGLE, TMO_NORMAL, [
288 ("instance", ED_INST_DICT, None),
289 ("snap_disks", ED_FINALIZE_EXPORT_DISKS, None),
290 ], None, "Request the completion of an export operation"),
291 ("export_list", MULTI, TMO_FAST, [], None, "Gets the stored exports list"),
292 ("export_remove", SINGLE, TMO_FAST, [
293 ("export", None, None),
294 ], None, "Requests removal of a given export"),
298 ("x509_cert_create", SINGLE, TMO_NORMAL, [
299 ("validity", None, "Validity in seconds"),
300 ], None, "Creates a new X509 certificate for SSL/TLS"),
301 ("x509_cert_remove", SINGLE, TMO_NORMAL, [
302 ("name", None, "Certificate name"),
303 ], None, "Removes a X509 certificate"),
307 ("bdev_sizes", MULTI, TMO_URGENT, [
308 ("devices", None, None),
309 ], None, "Gets the sizes of requested block devices present on a node"),
310 ("blockdev_create", SINGLE, TMO_NORMAL, [
311 ("bdev", ED_OBJECT_DICT, None),
312 ("size", None, None),
313 ("owner", None, None),
314 ("on_primary", None, None),
315 ("info", None, None),
316 ], None, "Request creation of a given block device"),
317 ("blockdev_wipe", SINGLE, TMO_SLOW, [
318 ("bdev", ED_OBJECT_DICT, None),
319 ("offset", None, None),
320 ("size", None, None),
322 "Request wipe at given offset with given size of a block device"),
323 ("blockdev_remove", SINGLE, TMO_NORMAL, [
324 ("bdev", ED_OBJECT_DICT, None),
325 ], None, "Request removal of a given block device"),
326 ("blockdev_pause_resume_sync", SINGLE, TMO_NORMAL, [
327 ("disks", ED_OBJECT_DICT_LIST, None),
328 ("pause", None, None),
329 ], None, "Request a pause/resume of given block device"),
330 ("blockdev_assemble", SINGLE, TMO_NORMAL, [
331 ("disk", ED_OBJECT_DICT, None),
332 ("owner", None, None),
333 ("on_primary", None, None),
335 ], None, "Request assembling of a given block device"),
336 ("blockdev_shutdown", SINGLE, TMO_NORMAL, [
337 ("disk", ED_OBJECT_DICT, None),
338 ], None, "Request shutdown of a given block device"),
339 ("blockdev_addchildren", SINGLE, TMO_NORMAL, [
340 ("bdev", ED_OBJECT_DICT, None),
341 ("ndevs", ED_OBJECT_DICT_LIST, None),
342 ], None, "Request adding a list of children to a (mirroring) device"),
343 ("blockdev_removechildren", SINGLE, TMO_NORMAL, [
344 ("bdev", ED_OBJECT_DICT, None),
345 ("ndevs", ED_OBJECT_DICT_LIST, None),
346 ], None, "Request removing a list of children from a (mirroring) device"),
347 ("blockdev_close", SINGLE, TMO_NORMAL, [
348 ("instance_name", None, None),
349 ("disks", ED_OBJECT_DICT_LIST, None),
350 ], None, "Closes the given block devices"),
351 ("blockdev_getsize", SINGLE, TMO_NORMAL, [
352 ("disks", ED_OBJECT_DICT_LIST, None),
353 ], None, "Returns the size of the given disks"),
354 ("drbd_disconnect_net", MULTI, TMO_NORMAL, [
355 ("nodes_ip", None, None),
356 ("disks", ED_OBJECT_DICT_LIST, None),
357 ], None, "Disconnects the network of the given drbd devices"),
358 ("drbd_attach_net", MULTI, TMO_NORMAL, [
359 ("nodes_ip", None, None),
360 ("disks", ED_OBJECT_DICT_LIST, None),
361 ("instance_name", None, None),
362 ("multimaster", None, None),
363 ], None, "Connects the given DRBD devices"),
364 ("drbd_wait_sync", MULTI, TMO_SLOW, [
365 ("nodes_ip", None, None),
366 ("disks", ED_OBJECT_DICT_LIST, None),
367 ], None, "Waits for the synchronization of drbd devices is complete"),
368 ("blockdev_grow", SINGLE, TMO_NORMAL, [
369 ("cf_bdev", ED_OBJECT_DICT, None),
370 ("amount", None, None),
371 ("dryrun", None, None),
372 ], None, "Request a snapshot of the given block device"),
373 ("blockdev_export", SINGLE, TMO_1DAY, [
374 ("cf_bdev", ED_OBJECT_DICT, None),
375 ("dest_node", None, None),
376 ("dest_path", None, None),
377 ("cluster_name", None, None),
378 ], None, "Export a given disk to another node"),
379 ("blockdev_snapshot", SINGLE, TMO_NORMAL, [
380 ("cf_bdev", ED_OBJECT_DICT, None),
381 ], None, "Export a given disk to another node"),
382 ("blockdev_rename", SINGLE, TMO_NORMAL, [
383 ("devlist", ED_BLOCKDEV_RENAME, None),
384 ], None, "Request rename of the given block devices"),
385 ("blockdev_find", SINGLE, TMO_NORMAL, [
386 ("disk", ED_OBJECT_DICT, None),
387 ], _BlockdevFindPostProc,
388 "Request identification of a given block device"),
389 ("blockdev_getmirrorstatus", SINGLE, TMO_NORMAL, [
390 ("disks", ED_OBJECT_DICT_LIST, None),
391 ], _BlockdevGetMirrorStatusPostProc,
392 "Request status of a (mirroring) device"),
393 ("blockdev_getmirrorstatus_multi", MULTI, TMO_NORMAL, [
394 ("node_disks", ED_NODE_TO_DISK_DICT, None),
395 ], _BlockdevGetMirrorStatusMultiPostProc,
396 "Request status of (mirroring) devices from multiple nodes"),
400 ("os_diagnose", MULTI, TMO_FAST, [], None,
401 "Request a diagnose of OS definitions"),
402 ("os_validate", MULTI, TMO_FAST, [
403 ("required", None, None),
404 ("name", None, None),
405 ("checks", None, None),
406 ("params", None, None),
407 ], None, "Run a validation routine for a given OS"),
408 ("os_get", SINGLE, TMO_FAST, [
409 ("name", None, None),
410 ], _OsGetPostProc, "Returns an OS definition"),
414 ("node_has_ip_address", SINGLE, TMO_FAST, [
415 ("address", None, "IP address"),
416 ], None, "Checks if a node has the given IP address"),
417 ("node_info", MULTI, TMO_URGENT, [
419 "Name of the volume group to ask for disk space information"),
420 ("hypervisor_type", None,
421 "Name of the hypervisor to ask for memory information"),
422 ], None, "Return node information"),
423 ("node_verify", MULTI, TMO_NORMAL, [
424 ("checkdict", None, None),
425 ("cluster_name", None, None),
426 ], None, "Request verification of given parameters"),
427 ("node_volumes", MULTI, TMO_FAST, [], None, "Gets all volumes on node(s)"),
428 ("node_demote_from_mc", SINGLE, TMO_FAST, [], None,
429 "Demote a node from the master candidate role"),
430 ("node_powercycle", SINGLE, TMO_NORMAL, [
431 ("hypervisor", None, "Hypervisor type"),
432 ], None, "Tries to powercycle a node"),
436 ("lv_list", MULTI, TMO_URGENT, [
437 ("vg_name", None, None),
438 ], None, "Gets the logical volumes present in a given volume group"),
439 ("vg_list", MULTI, TMO_URGENT, [], None, "Gets the volume group list"),
440 ("bridges_exist", SINGLE, TMO_URGENT, [
441 ("bridges_list", None, "Bridges which must be present on remote node"),
442 ], None, "Checks if a node has all the bridges given"),
443 ("etc_hosts_modify", SINGLE, TMO_NORMAL, [
445 "Mode to operate; currently L{constants.ETC_HOSTS_ADD} or"
446 " L{constants.ETC_HOSTS_REMOVE}"),
447 ("name", None, "Hostname to be modified"),
448 ("ip", None, "IP address (L{constants.ETC_HOSTS_ADD} only)"),
449 ], None, "Modify hosts file with name"),
450 ("drbd_helper", MULTI, TMO_URGENT, [], None, "Gets DRBD helper"),
451 ("run_oob", SINGLE, TMO_NORMAL, [
452 ("oob_program", None, None),
453 ("command", None, None),
454 ("remote_node", None, None),
455 ("timeout", None, None),
456 ], None, "Runs out-of-band command"),
457 ("hooks_runner", MULTI, TMO_NORMAL, [
458 ("hpath", None, None),
459 ("phase", None, None),
461 ], None, "Call the hooks runner"),
462 ("iallocator_runner", SINGLE, TMO_NORMAL, [
463 ("name", None, "Iallocator name"),
464 ("idata", None, "JSON-encoded input string"),
465 ], None, "Call an iallocator on a remote node"),
466 ("test_delay", MULTI, None, [
467 ("duration", None, None),
468 ], _TestDelayTimeout, "Sleep for a fixed time on given node(s)"),
469 ("hypervisor_validate_params", MULTI, TMO_NORMAL, [
470 ("hvname", None, "Hypervisor name"),
471 ("hvfull", None, "Parameters to be validated"),
472 ], None, "Validate hypervisor params"),
476 "RpcClientDefault": \
477 _Prepare(_IMPEXP_CALLS + _X509_CALLS + _OS_CALLS + _NODE_CALLS +
478 _FILE_STORAGE_CALLS + _MISC_CALLS + _INSTANCE_CALLS +
479 _BLOCKDEV_CALLS + _STORAGE_CALLS),
480 "RpcClientJobQueue": _Prepare([
481 ("jobqueue_update", MULTI, TMO_URGENT, [
482 ("file_name", None, None),
483 ("content", ED_COMPRESS, None),
484 ], None, "Update job queue file"),
485 ("jobqueue_purge", SINGLE, TMO_NORMAL, [], None, "Purge job queue"),
486 ("jobqueue_rename", MULTI, TMO_URGENT, [
487 ("rename", None, None),
488 ], None, "Rename job queue file"),
490 "RpcClientBootstrap": _Prepare([
491 ("node_start_master_daemons", SINGLE, TMO_FAST, [
492 ("no_voting", None, None),
493 ], None, "Starts master daemons on a node"),
494 ("node_activate_master_ip", SINGLE, TMO_FAST, [
495 ("master_params", ED_OBJECT_DICT, "Network parameters of the master"),
497 "Activates master IP on a node"),
498 ("node_stop_master", SINGLE, TMO_FAST, [], None,
499 "Deactivates master IP and stops master daemons on a node"),
500 ("node_deactivate_master_ip", SINGLE, TMO_FAST, [
501 ("master_params", ED_OBJECT_DICT, "Network parameters of the master"),
503 "Deactivates master IP on a node"),
504 ("node_change_master_netmask", SINGLE, TMO_FAST, [
505 ("old_netmask", None, "The old value of the netmask"),
506 ("netmask", None, "The new value of the netmask"),
507 ("master_ip", None, "The master IP"),
508 ("master_netdev", None, "The master network device"),
509 ], None, "Change master IP netmask"),
510 ("node_leave_cluster", SINGLE, TMO_NORMAL, [
511 ("modify_ssh_setup", None, None),
512 ], None, "Requests a node to clean the cluster information it has"),
513 ("master_info", MULTI, TMO_URGENT, [], None, "Query master info"),
514 ("version", MULTI, TMO_URGENT, [], None, "Query node version"),
516 "RpcClientConfig": _Prepare([
517 ("upload_file", MULTI, TMO_NORMAL, [
518 ("file_name", ED_FILE_DETAILS, None),
519 ], None, "Upload a file"),
520 ("write_ssconf_files", MULTI, TMO_NORMAL, [
521 ("values", None, None),
522 ], None, "Write ssconf files"),