1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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 - 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
31
32 - Name as string
33 - Argument kind used for encoding/decoding
34 - Description for docstring (can be C{None})
35
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
39
40 """
41
42 from ganeti import utils
43 from ganeti import objects
44
45
46
47
48
49
50
51 TMO_URGENT = 60
52 TMO_FAST = 5 * 60
53 TMO_NORMAL = 15 * 60
54 TMO_SLOW = 3600
55 TMO_4HRS = 4 * 3600
56 TMO_1DAY = 86400
57
58 SINGLE = "single-node"
59 MULTI = "multi-node"
60
61 ACCEPT_OFFLINE_NODE = object()
62
63
64 (ED_OBJECT_DICT,
65 ED_OBJECT_DICT_LIST,
66 ED_INST_DICT,
67 ED_INST_DICT_HVP_BEP_DP,
68 ED_NODE_TO_DISK_DICT,
69 ED_INST_DICT_OSP_DP,
70 ED_IMPEXP_IO,
71 ED_FILE_DETAILS,
72 ED_FINALIZE_EXPORT_DISKS,
73 ED_COMPRESS,
74 ED_BLOCKDEV_RENAME,
75 ED_DISKS_DICT_DP,
76 ED_SINGLE_DISK_DICT_DP) = range(1, 14)
77
78
84
85
87 """Post-processor for L{rpc.RpcRunner.call_instance_get_migration_status}.
88
89 """
90 if not result.fail_msg and result.payload is not None:
91 result.payload = objects.MigrationStatus.FromDict(result.payload)
92 return result
93
94
96 """Post-processor for L{rpc.RpcRunner.call_blockdev_find}.
97
98 """
99 if not result.fail_msg and result.payload is not None:
100 result.payload = objects.BlockDevStatus.FromDict(result.payload)
101 return result
102
103
105 """Post-processor for L{rpc.RpcRunner.call_blockdev_getmirrorstatus}.
106
107 """
108 if not result.fail_msg:
109 result.payload = map(objects.BlockDevStatus.FromDict, result.payload)
110 return result
111
112
114 """Prepares the appropriate node values for blockdev_getmirrorstatus_multi.
115
116 """
117
118
119
120 assert len(args) == 1
121 return [args[0][node]]
122
123
125 """Post-processor for L{rpc.RpcRunner.call_blockdev_getmirrorstatus_multi}.
126
127 """
128 if not result.fail_msg:
129 for idx, (success, status) in enumerate(result.payload):
130 if success:
131 result.payload[idx] = (success, objects.BlockDevStatus.FromDict(status))
132
133 return result
134
135
136 -def _OsGetPostProc(result):
137 """Post-processor for L{rpc.RpcRunner.call_os_get}.
138
139 """
140 if not result.fail_msg and isinstance(result.payload, dict):
141 result.payload = objects.OS.FromDict(result.payload)
142 return result
143
144
146 """Post-processor for import/export status.
147
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
151
152 """
153 if not result.fail_msg:
154 decoded = []
155
156 for i in result.payload:
157 if i is None:
158 decoded.append(None)
159 continue
160 decoded.append(objects.ImportExportStatus.FromDict(i))
161
162 result.payload = decoded
163
164 return result
165
166
168 """Calculate timeout for "test_delay" RPC.
169
170 """
171 return int(duration + 5)
172
173
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"),
185 ]
186
187 _STORAGE_CALLS = [
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),
204 ("op", None, None),
205 ], None, None, "Executes an operation on a storage unit"),
206 ]
207
208 _INSTANCE_CALLS = [
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"),
215 ], None, None,
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"),
243 ], None, None,
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_DP, 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"),
277 ]
278
279 _IMPEXP_CALLS = [
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"),
315 ]
316
317 _X509_CALLS = [
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"),
324 ]
325
326 _BLOCKDEV_CALLS = [
327 ("bdev_sizes", MULTI, None, TMO_URGENT, [
328 ("devices", None, None),
329 ], 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),
342 ], 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),
355 ("idx", 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),
363 ], None, 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),
368 ], None, 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),
390 ], None, 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 ], None, None, "Request a snapshot of the given block device"),
397 ("blockdev_export", SINGLE, None, TMO_1DAY, [
398 ("cf_bdev", ED_SINGLE_DISK_DICT_DP, None),
399 ("dest_node", None, None),
400 ("dest_path", None, None),
401 ("cluster_name", None, None),
402 ], None, None, "Export a given disk to another node"),
403 ("blockdev_snapshot", SINGLE, None, TMO_NORMAL, [
404 ("cf_bdev", ED_SINGLE_DISK_DICT_DP, None),
405 ], None, None, "Export a given disk to another node"),
406 ("blockdev_rename", SINGLE, None, TMO_NORMAL, [
407 ("devlist", ED_BLOCKDEV_RENAME, None),
408 ], None, None, "Request rename of the given block devices"),
409 ("blockdev_find", SINGLE, None, TMO_NORMAL, [
410 ("disk", ED_OBJECT_DICT, None),
411 ], None, _BlockdevFindPostProc,
412 "Request identification of a given block device"),
413 ("blockdev_getmirrorstatus", SINGLE, None, TMO_NORMAL, [
414 ("disks", ED_DISKS_DICT_DP, None),
415 ], None, _BlockdevGetMirrorStatusPostProc,
416 "Request status of a (mirroring) device"),
417 ("blockdev_getmirrorstatus_multi", MULTI, None, TMO_NORMAL, [
418 ("node_disks", ED_NODE_TO_DISK_DICT, None),
419 ], _BlockdevGetMirrorStatusMultiPreProc,
420 _BlockdevGetMirrorStatusMultiPostProc,
421 "Request status of (mirroring) devices from multiple nodes"),
422 ]
423
424 _OS_CALLS = [
425 ("os_diagnose", MULTI, None, TMO_FAST, [], None, None,
426 "Request a diagnose of OS definitions"),
427 ("os_validate", MULTI, None, TMO_FAST, [
428 ("required", None, None),
429 ("name", None, None),
430 ("checks", None, None),
431 ("params", None, None),
432 ], None, None, "Run a validation routine for a given OS"),
433 ("os_get", SINGLE, None, TMO_FAST, [
434 ("name", None, None),
435 ], None, _OsGetPostProc, "Returns an OS definition"),
436 ]
437
438 _NODE_CALLS = [
439 ("node_has_ip_address", SINGLE, None, TMO_FAST, [
440 ("address", None, "IP address"),
441 ], None, None, "Checks if a node has the given IP address"),
442 ("node_info", MULTI, None, TMO_URGENT, [
443 ("vg_names", None,
444 "Names of the volume groups to ask for disk space information"),
445 ("hv_names", None,
446 "Names of the hypervisors to ask for node information"),
447 ], None, None, "Return node information"),
448 ("node_verify", MULTI, None, TMO_NORMAL, [
449 ("checkdict", None, None),
450 ("cluster_name", None, None),
451 ], None, None, "Request verification of given parameters"),
452 ("node_volumes", MULTI, None, TMO_FAST, [], None, None,
453 "Gets all volumes on node(s)"),
454 ("node_demote_from_mc", SINGLE, None, TMO_FAST, [], None, None,
455 "Demote a node from the master candidate role"),
456 ("node_powercycle", SINGLE, ACCEPT_OFFLINE_NODE, TMO_NORMAL, [
457 ("hypervisor", None, "Hypervisor type"),
458 ], None, None, "Tries to powercycle a node"),
459 ]
460
461 _MISC_CALLS = [
462 ("lv_list", MULTI, None, TMO_URGENT, [
463 ("vg_name", None, None),
464 ], None, None, "Gets the logical volumes present in a given volume group"),
465 ("vg_list", MULTI, None, TMO_URGENT, [], None, None,
466 "Gets the volume group list"),
467 ("bridges_exist", SINGLE, None, TMO_URGENT, [
468 ("bridges_list", None, "Bridges which must be present on remote node"),
469 ], None, None, "Checks if a node has all the bridges given"),
470 ("etc_hosts_modify", SINGLE, None, TMO_NORMAL, [
471 ("mode", None,
472 "Mode to operate; currently L{constants.ETC_HOSTS_ADD} or"
473 " L{constants.ETC_HOSTS_REMOVE}"),
474 ("name", None, "Hostname to be modified"),
475 ("ip", None, "IP address (L{constants.ETC_HOSTS_ADD} only)"),
476 ], None, None, "Modify hosts file with name"),
477 ("drbd_helper", MULTI, None, TMO_URGENT, [], None, None, "Gets DRBD helper"),
478 ("run_oob", SINGLE, None, TMO_NORMAL, [
479 ("oob_program", None, None),
480 ("command", None, None),
481 ("remote_node", None, None),
482 ("timeout", None, None),
483 ], None, None, "Runs out-of-band command"),
484 ("hooks_runner", MULTI, None, TMO_NORMAL, [
485 ("hpath", None, None),
486 ("phase", None, None),
487 ("env", None, None),
488 ], None, None, "Call the hooks runner"),
489 ("iallocator_runner", SINGLE, None, TMO_NORMAL, [
490 ("name", None, "Iallocator name"),
491 ("idata", None, "JSON-encoded input string"),
492 ], None, None, "Call an iallocator on a remote node"),
493 ("test_delay", MULTI, None, _TestDelayTimeout, [
494 ("duration", None, None),
495 ], None, None, "Sleep for a fixed time on given node(s)"),
496 ("hypervisor_validate_params", MULTI, None, TMO_NORMAL, [
497 ("hvname", None, "Hypervisor name"),
498 ("hvfull", None, "Parameters to be validated"),
499 ], None, None, "Validate hypervisor params"),
500 ]
501
502 CALLS = {
503 "RpcClientDefault": \
504 _Prepare(_IMPEXP_CALLS + _X509_CALLS + _OS_CALLS + _NODE_CALLS +
505 _FILE_STORAGE_CALLS + _MISC_CALLS + _INSTANCE_CALLS +
506 _BLOCKDEV_CALLS + _STORAGE_CALLS),
507 "RpcClientJobQueue": _Prepare([
508 ("jobqueue_update", MULTI, None, TMO_URGENT, [
509 ("file_name", None, None),
510 ("content", ED_COMPRESS, None),
511 ], None, None, "Update job queue file"),
512 ("jobqueue_purge", SINGLE, None, TMO_NORMAL, [], None, None,
513 "Purge job queue"),
514 ("jobqueue_rename", MULTI, None, TMO_URGENT, [
515 ("rename", None, None),
516 ], None, None, "Rename job queue file"),
517 ]),
518 "RpcClientBootstrap": _Prepare([
519 ("node_start_master_daemons", SINGLE, None, TMO_FAST, [
520 ("no_voting", None, None),
521 ], None, None, "Starts master daemons on a node"),
522 ("node_activate_master_ip", SINGLE, None, TMO_FAST, [
523 ("master_params", ED_OBJECT_DICT, "Network parameters of the master"),
524 ("use_external_mip_script", None,
525 "Whether to use the user-provided master IP address setup script"),
526 ], None, None,
527 "Activates master IP on a node"),
528 ("node_stop_master", SINGLE, None, TMO_FAST, [], None, None,
529 "Deactivates master IP and stops master daemons on a node"),
530 ("node_deactivate_master_ip", SINGLE, None, TMO_FAST, [
531 ("master_params", ED_OBJECT_DICT, "Network parameters of the master"),
532 ("use_external_mip_script", None,
533 "Whether to use the user-provided master IP address setup script"),
534 ], None, None,
535 "Deactivates master IP on a node"),
536 ("node_change_master_netmask", SINGLE, None, TMO_FAST, [
537 ("old_netmask", None, "The old value of the netmask"),
538 ("netmask", None, "The new value of the netmask"),
539 ("master_ip", None, "The master IP"),
540 ("master_netdev", None, "The master network device"),
541 ], None, None, "Change master IP netmask"),
542 ("node_leave_cluster", SINGLE, None, TMO_NORMAL, [
543 ("modify_ssh_setup", None, None),
544 ], None, None,
545 "Requests a node to clean the cluster information it has"),
546 ("master_info", MULTI, None, TMO_URGENT, [], None, None,
547 "Query master info"),
548 ]),
549 "RpcClientDnsOnly": _Prepare([
550 ("version", MULTI, ACCEPT_OFFLINE_NODE, TMO_URGENT, [], None, None,
551 "Query node version"),
552 ]),
553 "RpcClientConfig": _Prepare([
554 ("upload_file", MULTI, None, TMO_NORMAL, [
555 ("file_name", ED_FILE_DETAILS, None),
556 ], None, None, "Upload a file"),
557 ("write_ssconf_files", MULTI, None, TMO_NORMAL, [
558 ("values", None, None),
559 ], None, None, "Write ssconf files"),
560 ]),
561 }
562