rpc_defs.py 17.1 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#
#

# Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Google Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.

"""RPC definitions for communication between master and node daemons.

Michael Hanselmann's avatar
Michael Hanselmann committed
23
24
25
26
27
28
29
30
RPC definition fields:

  - Name as string
  - L{SINGLE} for single-node calls, L{MULTI} for multi-node
  - Timeout (e.g. L{TMO_NORMAL})
  - List of arguments as tuples

    - Name as string
31
    - Argument kind used for encoding/decoding
Michael Hanselmann's avatar
Michael Hanselmann committed
32
33
34
35
36
    - Description for docstring (can be C{None})

  - Return value wrapper (e.g. for deserializing into L{objects}-based objects)
  - Short call description for docstring

37
38
"""

39
40
from ganeti import utils

41

42
43
44
45
46
# Guidelines for choosing timeouts:
# - call used during watcher: timeout of 1min, _TMO_URGENT
# - trivial (but be sure it is trivial) (e.g. reading a file): 5min, _TMO_FAST
# - other calls: 15 min, _TMO_NORMAL
# - special calls (instance add, etc.): either _TMO_SLOW (1h) or huge timeouts
47
48
49
50
51
52
53
54
55
56
TMO_URGENT = 60 # one minute
TMO_FAST = 5 * 60 # five minutes
TMO_NORMAL = 15 * 60 # 15 minutes
TMO_SLOW = 3600 # one hour
TMO_4HRS = 4 * 3600
TMO_1DAY = 86400

SINGLE = "single-node"
MULTI = "multi-node"

57
58
59
60
61
62
63
64
65
66
67
68
# Constants for encoding/decoding
(ED_OBJECT_DICT,
 ED_OBJECT_DICT_LIST,
 ED_INST_DICT,
 ED_INST_DICT_HVP_BEP,
 ED_NODE_TO_DISK_DICT,
 ED_INST_DICT_OSP,
 ED_IMPEXP_IO,
 ED_FILE_DETAILS,
 ED_FINALIZE_EXPORT_DISKS,
 ED_COMPRESS,
 ED_BLOCKDEV_RENAME) = range(1, 12)
69

70
71
72
73
74
75
76
77

def _Prepare(calls):
  """Converts list of calls to dictionary.

  """
  return utils.SequenceToDict(calls)


Michael Hanselmann's avatar
Michael Hanselmann committed
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
_FILE_STORAGE_CALLS = [
  ("file_storage_dir_create", SINGLE, TMO_FAST, [
    ("file_storage_dir", None, "File storage directory"),
    ], None, "Create the given file storage directory"),
  ("file_storage_dir_remove", SINGLE, TMO_FAST, [
    ("file_storage_dir", None, "File storage directory"),
    ], None, "Remove the given file storage directory"),
  ("file_storage_dir_rename", SINGLE, TMO_FAST, [
    ("old_file_storage_dir", None, "Old name"),
    ("new_file_storage_dir", None, "New name"),
    ], None, "Rename file storage directory"),
  ]

_STORAGE_CALLS = [
  ("storage_list", MULTI, TMO_NORMAL, [
    ("su_name", None, None),
    ("su_args", None, None),
    ("name", None, None),
    ("fields", None, None),
    ], None, "Get list of storage units"),
  ("storage_modify", SINGLE, TMO_NORMAL, [
    ("su_name", None, None),
    ("su_args", None, None),
    ("name", None, None),
    ("changes", None, None),
    ], None, "Modify a storage unit"),
  ("storage_execute", SINGLE, TMO_NORMAL, [
    ("su_name", None, None),
    ("su_args", None, None),
    ("name", None, None),
    ("op", None, None),
    ], None, "Executes an operation on a storage unit"),
  ]

_INSTANCE_CALLS = [
  ("instance_info", SINGLE, TMO_URGENT, [
    ("instance", None, "Instance name"),
    ("hname", None, "Hypervisor type"),
    ], None, "Returns information about a single instance"),
  ("all_instances_info", MULTI, TMO_URGENT, [
    ("hypervisor_list", None, "Hypervisors to query for instances"),
    ], None, "Returns information about all instances on the given nodes"),
  ("instance_list", MULTI, TMO_URGENT, [
    ("hypervisor_list", None, "Hypervisors to query for instances"),
    ], None, "Returns the list of running instances on the given nodes"),
  ("instance_reboot", SINGLE, TMO_NORMAL, [
124
    ("inst", ED_INST_DICT, "Instance object"),
Michael Hanselmann's avatar
Michael Hanselmann committed
125
126
127
128
    ("reboot_type", None, None),
    ("shutdown_timeout", None, None),
    ], None, "Returns the list of running instances on the given nodes"),
  ("instance_shutdown", SINGLE, TMO_NORMAL, [
129
    ("instance", ED_INST_DICT, "Instance object"),
Michael Hanselmann's avatar
Michael Hanselmann committed
130
131
132
    ("timeout", None, None),
    ], None, "Stops an instance"),
  ("instance_run_rename", SINGLE, TMO_SLOW, [
133
    ("instance", ED_INST_DICT, "Instance object"),
Michael Hanselmann's avatar
Michael Hanselmann committed
134
135
136
137
    ("old_name", None, None),
    ("debug", None, None),
    ], None, "Run the OS rename script for an instance"),
  ("instance_migratable", SINGLE, TMO_NORMAL, [
138
    ("instance", ED_INST_DICT, "Instance object"),
Michael Hanselmann's avatar
Michael Hanselmann committed
139
140
    ], None, "Checks whether the given instance can be migrated"),
  ("migration_info", SINGLE, TMO_NORMAL, [
141
    ("instance", ED_INST_DICT, "Instance object"),
Michael Hanselmann's avatar
Michael Hanselmann committed
142
143
144
    ], None,
    "Gather the information necessary to prepare an instance migration"),
  ("accept_instance", SINGLE, TMO_NORMAL, [
145
    ("instance", ED_INST_DICT, "Instance object"),
Michael Hanselmann's avatar
Michael Hanselmann committed
146
147
148
149
    ("info", None, "Result for the call_migration_info call"),
    ("target", None, "Target hostname (usually an IP address)"),
    ], None, "Prepare a node to accept an instance"),
  ("instance_finalize_migration_dst", SINGLE, TMO_NORMAL, [
150
    ("instance", ED_INST_DICT, "Instance object"),
Michael Hanselmann's avatar
Michael Hanselmann committed
151
152
153
154
    ("info", None, "Result for the call_migration_info call"),
    ("success", None, "Whether the migration was a success or failure"),
    ], None, "Finalize any target-node migration specific operation"),
  ("instance_migrate", SINGLE, TMO_SLOW, [
155
    ("instance", ED_INST_DICT, "Instance object"),
Michael Hanselmann's avatar
Michael Hanselmann committed
156
157
158
159
    ("target", None, "Target node name"),
    ("live", None, "Whether the migration should be done live or not"),
    ], None, "Migrate an instance"),
  ("instance_finalize_migration_src", SINGLE, TMO_SLOW, [
160
    ("instance", ED_INST_DICT, "Instance object"),
Michael Hanselmann's avatar
Michael Hanselmann committed
161
162
163
    ("success", None, "Whether the migration succeeded or not"),
    ("live", None, "Whether the user requested a live migration or not"),
    ], 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
170
171
    ("startup_paused", None, None),
    ], None, "Starts an instance"),
  ("instance_os_add", SINGLE, TMO_1DAY, [
172
    ("instance_osp", ED_INST_DICT_OSP, None),
173
174
175
    ("reinstall", None, None),
    ("debug", None, None),
    ], None, "Starts an instance"),
Michael Hanselmann's avatar
Michael Hanselmann committed
176
177
178
  ]

_IMPEXP_CALLS = [
179
  ("import_start", SINGLE, TMO_NORMAL, [
180
181
    ("opts", ED_OBJECT_DICT, None),
    ("instance", ED_INST_DICT, None),
182
    ("component", None, None),
183
    ("dest", ED_IMPEXP_IO, "Import destination"),
184
185
    ], None, "Starts an import daemon"),
  ("export_start", SINGLE, TMO_NORMAL, [
186
    ("opts", ED_OBJECT_DICT, None),
187
188
    ("host", None, None),
    ("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"),
Michael Hanselmann's avatar
Michael Hanselmann committed
193
194
195
196
197
198
199
200
201
202
203
204
205
  ("impexp_status", SINGLE, TMO_FAST, [
    ("names", None, "Import/export names"),
    ], "self._ImpExpStatusPostProc", "Gets the status of an import or export"),
  ("impexp_abort", SINGLE, TMO_NORMAL, [
    ("name", None, "Import/export name"),
    ], None, "Aborts an import or export"),
  ("impexp_cleanup", SINGLE, TMO_NORMAL, [
    ("name", None, "Import/export name"),
    ], None, "Cleans up after an import or export"),
  ("export_info", SINGLE, TMO_FAST, [
    ("path", None, None),
    ], None, "Queries the export information in a given path"),
  ("finalize_export", SINGLE, TMO_NORMAL, [
206
207
    ("instance", ED_INST_DICT, None),
    ("snap_disks", ED_FINALIZE_EXPORT_DISKS, None),
Michael Hanselmann's avatar
Michael Hanselmann committed
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
    ], None, "Request the completion of an export operation"),
  ("export_list", MULTI, TMO_FAST, [], None, "Gets the stored exports list"),
  ("export_remove", SINGLE, TMO_FAST, [
    ("export", None, None),
    ], None, "Requests removal of a given export"),
  ]

_X509_CALLS = [
  ("x509_cert_create", SINGLE, TMO_NORMAL, [
    ("validity", None, "Validity in seconds"),
    ], None, "Creates a new X509 certificate for SSL/TLS"),
  ("x509_cert_remove", SINGLE, TMO_NORMAL, [
    ("name", None, "Certificate name"),
    ], None, "Removes a X509 certificate"),
  ]

_BLOCKDEV_CALLS = [
  ("bdev_sizes", MULTI, TMO_URGENT, [
    ("devices", None, None),
    ], None, "Gets the sizes of requested block devices present on a node"),
  ("blockdev_create", SINGLE, TMO_NORMAL, [
229
    ("bdev", ED_OBJECT_DICT, None),
Michael Hanselmann's avatar
Michael Hanselmann committed
230
231
232
233
234
235
    ("size", None, None),
    ("owner", None, None),
    ("on_primary", None, None),
    ("info", None, None),
    ], None, "Request creation of a given block device"),
  ("blockdev_wipe", SINGLE, TMO_SLOW, [
236
    ("bdev", ED_OBJECT_DICT, None),
Michael Hanselmann's avatar
Michael Hanselmann committed
237
238
239
240
241
    ("offset", None, None),
    ("size", None, None),
    ], None,
    "Request wipe at given offset with given size of a block device"),
  ("blockdev_remove", SINGLE, TMO_NORMAL, [
242
    ("bdev", ED_OBJECT_DICT, None),
Michael Hanselmann's avatar
Michael Hanselmann committed
243
244
    ], None, "Request removal of a given block device"),
  ("blockdev_pause_resume_sync", SINGLE, TMO_NORMAL, [
245
    ("disks", ED_OBJECT_DICT_LIST, None),
Michael Hanselmann's avatar
Michael Hanselmann committed
246
247
248
    ("pause", None, None),
    ], None, "Request a pause/resume of given block device"),
  ("blockdev_assemble", SINGLE, TMO_NORMAL, [
249
    ("disk", ED_OBJECT_DICT, None),
Michael Hanselmann's avatar
Michael Hanselmann committed
250
251
252
253
254
    ("owner", None, None),
    ("on_primary", None, None),
    ("idx", None, None),
    ], None, "Request assembling of a given block device"),
  ("blockdev_shutdown", SINGLE, TMO_NORMAL, [
255
    ("disk", ED_OBJECT_DICT, None),
Michael Hanselmann's avatar
Michael Hanselmann committed
256
257
    ], None, "Request shutdown of a given block device"),
  ("blockdev_addchildren", SINGLE, TMO_NORMAL, [
258
259
    ("bdev", ED_OBJECT_DICT, None),
    ("ndevs", ED_OBJECT_DICT_LIST, None),
Michael Hanselmann's avatar
Michael Hanselmann committed
260
261
    ], None, "Request adding a list of children to a (mirroring) device"),
  ("blockdev_removechildren", SINGLE, TMO_NORMAL, [
262
263
    ("bdev", ED_OBJECT_DICT, None),
    ("ndevs", ED_OBJECT_DICT_LIST, None),
Michael Hanselmann's avatar
Michael Hanselmann committed
264
265
266
    ], None, "Request removing a list of children from a (mirroring) device"),
  ("blockdev_close", SINGLE, TMO_NORMAL, [
    ("instance_name", None, None),
267
    ("disks", ED_OBJECT_DICT_LIST, None),
Michael Hanselmann's avatar
Michael Hanselmann committed
268
269
    ], None, "Closes the given block devices"),
  ("blockdev_getsize", SINGLE, TMO_NORMAL, [
270
    ("disks", ED_OBJECT_DICT_LIST, None),
Michael Hanselmann's avatar
Michael Hanselmann committed
271
272
273
    ], None, "Returns the size of the given disks"),
  ("drbd_disconnect_net", MULTI, TMO_NORMAL, [
    ("nodes_ip", None, None),
274
    ("disks", ED_OBJECT_DICT_LIST, None),
Michael Hanselmann's avatar
Michael Hanselmann committed
275
276
277
    ], None, "Disconnects the network of the given drbd devices"),
  ("drbd_attach_net", MULTI, TMO_NORMAL, [
    ("nodes_ip", None, None),
278
    ("disks", ED_OBJECT_DICT_LIST, None),
Michael Hanselmann's avatar
Michael Hanselmann committed
279
280
281
282
283
    ("instance_name", None, None),
    ("multimaster", None, None),
    ], None, "Connects the given DRBD devices"),
  ("drbd_wait_sync", MULTI, TMO_SLOW, [
    ("nodes_ip", None, None),
284
    ("disks", ED_OBJECT_DICT_LIST, None),
Michael Hanselmann's avatar
Michael Hanselmann committed
285
286
    ], None, "Waits for the synchronization of drbd devices is complete"),
  ("blockdev_grow", SINGLE, TMO_NORMAL, [
287
    ("cf_bdev", ED_OBJECT_DICT, None),
Michael Hanselmann's avatar
Michael Hanselmann committed
288
289
290
291
    ("amount", None, None),
    ("dryrun", None, None),
    ], None, "Request a snapshot of the given block device"),
  ("blockdev_export", SINGLE, TMO_1DAY, [
292
    ("cf_bdev", ED_OBJECT_DICT, None),
Michael Hanselmann's avatar
Michael Hanselmann committed
293
294
295
296
297
    ("dest_node", None, None),
    ("dest_path", None, None),
    ("cluster_name", None, None),
    ], None, "Export a given disk to another node"),
  ("blockdev_snapshot", SINGLE, TMO_NORMAL, [
298
    ("cf_bdev", ED_OBJECT_DICT, None),
Michael Hanselmann's avatar
Michael Hanselmann committed
299
300
    ], None, "Export a given disk to another node"),
  ("blockdev_rename", SINGLE, TMO_NORMAL, [
301
    ("devlist", ED_BLOCKDEV_RENAME, None),
Michael Hanselmann's avatar
Michael Hanselmann committed
302
303
    ], None, "Request rename of the given block devices"),
  ("blockdev_find", SINGLE, TMO_NORMAL, [
304
    ("disk", ED_OBJECT_DICT, None),
Michael Hanselmann's avatar
Michael Hanselmann committed
305
306
307
    ], "self._BlockdevFindPostProc",
    "Request identification of a given block device"),
  ("blockdev_getmirrorstatus", SINGLE, TMO_NORMAL, [
308
    ("disks", ED_OBJECT_DICT_LIST, None),
Michael Hanselmann's avatar
Michael Hanselmann committed
309
310
311
    ], "self._BlockdevGetMirrorStatusPostProc",
    "Request status of a (mirroring) device"),
  ("blockdev_getmirrorstatus_multi", MULTI, TMO_NORMAL, [
312
    ("node_disks", ED_NODE_TO_DISK_DICT, None),
Michael Hanselmann's avatar
Michael Hanselmann committed
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
    ], "self._BlockdevGetMirrorStatusMultiPostProc",
    "Request status of (mirroring) devices from multiple nodes"),
  ]

_OS_CALLS = [
  ("os_diagnose", MULTI, TMO_FAST, [], None,
   "Request a diagnose of OS definitions"),
  ("os_validate", MULTI, TMO_FAST, [
    ("required", None, None),
    ("name", None, None),
    ("checks", None, None),
    ("params", None, None),
    ], None, "Run a validation routine for a given OS"),
  ("os_get", SINGLE, TMO_FAST, [
    ("name", None, None),
    ], "self._OsGetPostProc", "Returns an OS definition"),
  ]

_NODE_CALLS = [
  ("node_has_ip_address", SINGLE, TMO_FAST, [
    ("address", None, "IP address"),
    ], None, "Checks if a node has the given IP address"),
  ("node_info", MULTI, TMO_URGENT, [
    ("vg_name", None,
     "Name of the volume group to ask for disk space information"),
    ("hypervisor_type", None,
     "Name of the hypervisor to ask for memory information"),
    ], None, "Return node information"),
  ("node_verify", MULTI, TMO_NORMAL, [
    ("checkdict", None, None),
    ("cluster_name", None, None),
    ], None, "Request verification of given parameters"),
  ("node_volumes", MULTI, TMO_FAST, [], None, "Gets all volumes on node(s)"),
  ("node_demote_from_mc", SINGLE, TMO_FAST, [], None,
   "Demote a node from the master candidate role"),
  ("node_powercycle", SINGLE, TMO_NORMAL, [
    ("hypervisor", None, "Hypervisor type"),
    ], None, "Tries to powercycle a node"),
  ]

_MISC_CALLS = [
  ("lv_list", MULTI, TMO_URGENT, [
    ("vg_name", None, None),
    ], None, "Gets the logical volumes present in a given volume group"),
  ("vg_list", MULTI, TMO_URGENT, [], None, "Gets the volume group list"),
  ("bridges_exist", SINGLE, TMO_URGENT, [
    ("bridges_list", None, "Bridges which must be present on remote node"),
    ], None, "Checks if a node has all the bridges given"),
  ("etc_hosts_modify", SINGLE, TMO_NORMAL, [
    ("mode", None,
     "Mode to operate; currently L{constants.ETC_HOSTS_ADD} or"
     " L{constants.ETC_HOSTS_REMOVE}"),
    ("name", None, "Hostname to be modified"),
    ("ip", None, "IP address (L{constants.ETC_HOSTS_ADD} only)"),
    ], None, "Modify hosts file with name"),
  ("drbd_helper", MULTI, TMO_URGENT, [], None, "Gets DRBD helper"),
  ("run_oob", SINGLE, TMO_NORMAL, [
    ("oob_program", None, None),
    ("command", None, None),
    ("remote_node", None, None),
    ("timeout", None, None),
    ], None, "Runs out-of-band command"),
  ("hooks_runner", MULTI, TMO_NORMAL, [
    ("hpath", None, None),
    ("phase", None, None),
    ("env", None, None),
    ], None, "Call the hooks runner"),
  ("iallocator_runner", SINGLE, TMO_NORMAL, [
    ("name", None, "Iallocator name"),
    ("idata", None, "JSON-encoded input string"),
    ], None, "Call an iallocator on a remote node"),
  ("test_delay", MULTI, None, [
    ("duration", None, None),
    ], None, "Sleep for a fixed time on given node(s)"),
387
388
389
390
  ("hypervisor_validate_params", MULTI, TMO_NORMAL, [
    ("hvname", None, "Hypervisor name"),
    ("hvfull", None, "Parameters to be validated"),
    ], None, "Validate hypervisor params"),
Michael Hanselmann's avatar
Michael Hanselmann committed
391
392
  ]

393
CALLS = {
394
395
396
397
398
  "RpcClientDefault": \
    _Prepare(_IMPEXP_CALLS + _X509_CALLS + _OS_CALLS + _NODE_CALLS +
             _FILE_STORAGE_CALLS + _MISC_CALLS + _INSTANCE_CALLS +
             _BLOCKDEV_CALLS + _STORAGE_CALLS),
  "RpcClientJobQueue": _Prepare([
399
400
    ("jobqueue_update", MULTI, TMO_URGENT, [
      ("file_name", None, None),
401
      ("content", ED_COMPRESS, None),
402
403
404
405
406
      ], None, "Update job queue file"),
    ("jobqueue_purge", SINGLE, TMO_NORMAL, [], None, "Purge job queue"),
    ("jobqueue_rename", MULTI, TMO_URGENT, [
      ("rename", None, None),
      ], None, "Rename job queue file"),
407
408
    ]),
  "RpcClientBootstrap": _Prepare([
409
410
411
    ("node_start_master_daemons", SINGLE, TMO_FAST, [
      ("no_voting", None, None),
      ], 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
415
      ], None,
      "Activates master IP on a node"),
416
417
    ("node_stop_master", SINGLE, TMO_FAST, [], None,
     "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
422
     "Deactivates master IP on a node"),
    ("node_change_master_netmask", SINGLE, TMO_FAST, [
423
424
425
426
      ("old_netmask", None, "The old value of the netmask"),
      ("netmask", None, "The new value of the netmask"),
      ("master_ip", None, "The master IP"),
      ("master_netdev", None, "The master network device"),
427
428
429
430
431
432
      ], None, "Change master IP netmask"),
    ("node_leave_cluster", SINGLE, TMO_NORMAL, [
      ("modify_ssh_setup", None, None),
      ], None, "Requests a node to clean the cluster information it has"),
    ("master_info", MULTI, TMO_URGENT, [], None, "Query master info"),
    ("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
438
439
440
      ], None, "Upload a file"),
    ("write_ssconf_files", MULTI, TMO_NORMAL, [
      ("values", None, None),
      ], None, "Write ssconf files"),
441
    ]),
442
  }