Statistics
| Branch: | Tag: | Revision:

root / lib / rpc_defs.py @ b8c160c1

History | View | Annotate | Download (16.6 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
    - Wrapper code ("%s" is replaced with argument name, see L{OBJECT_TO_DICT})
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

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

    
52
SINGLE = "single-node"
53
MULTI = "multi-node"
54

    
55
OBJECT_TO_DICT = "%s.ToDict()"
56
OBJECT_LIST_TO_DICT = "map(lambda d: d.ToDict(), %s)"
57
INST_TO_DICT = "self._InstDict(%s)"
58

    
59
NODE_TO_DISK_DICT = \
60
  ("dict((name, %s) for name, disks in %%s.items())" %
61
   (OBJECT_LIST_TO_DICT % "disks"))
62

    
63
_FILE_STORAGE_CALLS = [
64
  ("file_storage_dir_create", SINGLE, TMO_FAST, [
65
    ("file_storage_dir", None, "File storage directory"),
66
    ], None, "Create the given file storage directory"),
67
  ("file_storage_dir_remove", SINGLE, TMO_FAST, [
68
    ("file_storage_dir", None, "File storage directory"),
69
    ], None, "Remove the given file storage directory"),
70
  ("file_storage_dir_rename", SINGLE, TMO_FAST, [
71
    ("old_file_storage_dir", None, "Old name"),
72
    ("new_file_storage_dir", None, "New name"),
73
    ], None, "Rename file storage directory"),
74
  ]
75

    
76
_STORAGE_CALLS = [
77
  ("storage_list", MULTI, TMO_NORMAL, [
78
    ("su_name", None, None),
79
    ("su_args", None, None),
80
    ("name", None, None),
81
    ("fields", None, None),
82
    ], None, "Get list of storage units"),
83
  ("storage_modify", SINGLE, TMO_NORMAL, [
84
    ("su_name", None, None),
85
    ("su_args", None, None),
86
    ("name", None, None),
87
    ("changes", None, None),
88
    ], None, "Modify a storage unit"),
89
  ("storage_execute", SINGLE, TMO_NORMAL, [
90
    ("su_name", None, None),
91
    ("su_args", None, None),
92
    ("name", None, None),
93
    ("op", None, None),
94
    ], None, "Executes an operation on a storage unit"),
95
  ]
96

    
97
_INSTANCE_CALLS = [
98
  ("instance_info", SINGLE, TMO_URGENT, [
99
    ("instance", None, "Instance name"),
100
    ("hname", None, "Hypervisor type"),
101
    ], None, "Returns information about a single instance"),
102
  ("all_instances_info", MULTI, TMO_URGENT, [
103
    ("hypervisor_list", None, "Hypervisors to query for instances"),
104
    ], None, "Returns information about all instances on the given nodes"),
105
  ("instance_list", MULTI, TMO_URGENT, [
106
    ("hypervisor_list", None, "Hypervisors to query for instances"),
107
    ], None, "Returns the list of running instances on the given nodes"),
108
  ("instance_reboot", SINGLE, TMO_NORMAL, [
109
    ("inst", INST_TO_DICT, "Instance object"),
110
    ("reboot_type", None, None),
111
    ("shutdown_timeout", None, None),
112
    ], None, "Returns the list of running instances on the given nodes"),
113
  ("instance_shutdown", SINGLE, TMO_NORMAL, [
114
    ("instance", INST_TO_DICT, "Instance object"),
115
    ("timeout", None, None),
116
    ], None, "Stops an instance"),
117
  ("instance_run_rename", SINGLE, TMO_SLOW, [
118
    ("instance", INST_TO_DICT, "Instance object"),
119
    ("old_name", None, None),
120
    ("debug", None, None),
121
    ], None, "Run the OS rename script for an instance"),
122
  ("instance_migratable", SINGLE, TMO_NORMAL, [
123
    ("instance", INST_TO_DICT, "Instance object"),
124
    ], None, "Checks whether the given instance can be migrated"),
125
  ("migration_info", SINGLE, TMO_NORMAL, [
126
    ("instance", INST_TO_DICT, "Instance object"),
127
    ], None,
128
    "Gather the information necessary to prepare an instance migration"),
129
  ("accept_instance", SINGLE, TMO_NORMAL, [
130
    ("instance", INST_TO_DICT, "Instance object"),
131
    ("info", None, "Result for the call_migration_info call"),
132
    ("target", None, "Target hostname (usually an IP address)"),
133
    ], None, "Prepare a node to accept an instance"),
134
  ("instance_finalize_migration_dst", SINGLE, TMO_NORMAL, [
135
    ("instance", INST_TO_DICT, "Instance object"),
136
    ("info", None, "Result for the call_migration_info call"),
137
    ("success", None, "Whether the migration was a success or failure"),
138
    ], None, "Finalize any target-node migration specific operation"),
139
  ("instance_migrate", SINGLE, TMO_SLOW, [
140
    ("instance", INST_TO_DICT, "Instance object"),
141
    ("target", None, "Target node name"),
142
    ("live", None, "Whether the migration should be done live or not"),
143
    ], None, "Migrate an instance"),
144
  ("instance_finalize_migration_src", SINGLE, TMO_SLOW, [
145
    ("instance", INST_TO_DICT, "Instance object"),
146
    ("success", None, "Whether the migration succeeded or not"),
147
    ("live", None, "Whether the user requested a live migration or not"),
148
    ], None, "Finalize the instance migration on the source node"),
149
  ("instance_get_migration_status", SINGLE, TMO_SLOW, [
150
    ("instance", INST_TO_DICT, "Instance object"),
151
    ], "self._MigrationStatusPostProc", "Report migration status"),
152
  ("instance_start", SINGLE, TMO_NORMAL, [
153
    ("instance_hvp_bep", "self._InstDictHvpBep(%s)", None),
154
    ("startup_paused", None, None),
155
    ], None, "Starts an instance"),
156
  ("instance_os_add", SINGLE, TMO_1DAY, [
157
    ("instance_osp", "self._InstDictOsp(%s)", None),
158
    ("reinstall", None, None),
159
    ("debug", None, None),
160
    ], None, "Starts an instance"),
161
  ]
162

    
163
_IMPEXP_CALLS = [
164
  ("import_start", SINGLE, TMO_NORMAL, [
165
    ("opts", OBJECT_TO_DICT, None),
166
    ("instance", INST_TO_DICT, None),
167
    ("component", None, None),
168
    ("dest", "self._EncodeImportExportIO(%s)", "Import destination"),
169
    ], None, "Starts an import daemon"),
170
  ("export_start", SINGLE, TMO_NORMAL, [
171
    ("opts", OBJECT_TO_DICT, None),
172
    ("host", None, None),
173
    ("port", None, None),
174
    ("instance", INST_TO_DICT, None),
175
    ("component", None, None),
176
    ("source", "self._EncodeImportExportIO(%s)", "Export source"),
177
    ], None, "Starts an export daemon"),
178
  ("impexp_status", SINGLE, TMO_FAST, [
179
    ("names", None, "Import/export names"),
180
    ], "self._ImpExpStatusPostProc", "Gets the status of an import or export"),
181
  ("impexp_abort", SINGLE, TMO_NORMAL, [
182
    ("name", None, "Import/export name"),
183
    ], None, "Aborts an import or export"),
184
  ("impexp_cleanup", SINGLE, TMO_NORMAL, [
185
    ("name", None, "Import/export name"),
186
    ], None, "Cleans up after an import or export"),
187
  ("export_info", SINGLE, TMO_FAST, [
188
    ("path", None, None),
189
    ], None, "Queries the export information in a given path"),
190
  ("finalize_export", SINGLE, TMO_NORMAL, [
191
    ("instance", INST_TO_DICT, None),
192
    ("snap_disks", "self._PrepareFinalizeExportDisks(%s)", None),
193
    ], None, "Request the completion of an export operation"),
194
  ("export_list", MULTI, TMO_FAST, [], None, "Gets the stored exports list"),
195
  ("export_remove", SINGLE, TMO_FAST, [
196
    ("export", None, None),
197
    ], None, "Requests removal of a given export"),
198
  ]
199

    
200
_X509_CALLS = [
201
  ("x509_cert_create", SINGLE, TMO_NORMAL, [
202
    ("validity", None, "Validity in seconds"),
203
    ], None, "Creates a new X509 certificate for SSL/TLS"),
204
  ("x509_cert_remove", SINGLE, TMO_NORMAL, [
205
    ("name", None, "Certificate name"),
206
    ], None, "Removes a X509 certificate"),
207
  ]
208

    
209
_BLOCKDEV_CALLS = [
210
  ("bdev_sizes", MULTI, TMO_URGENT, [
211
    ("devices", None, None),
212
    ], None, "Gets the sizes of requested block devices present on a node"),
213
  ("blockdev_create", SINGLE, TMO_NORMAL, [
214
    ("bdev", OBJECT_TO_DICT, None),
215
    ("size", None, None),
216
    ("owner", None, None),
217
    ("on_primary", None, None),
218
    ("info", None, None),
219
    ], None, "Request creation of a given block device"),
220
  ("blockdev_wipe", SINGLE, TMO_SLOW, [
221
    ("bdev", OBJECT_TO_DICT, None),
222
    ("offset", None, None),
223
    ("size", None, None),
224
    ], None,
225
    "Request wipe at given offset with given size of a block device"),
226
  ("blockdev_remove", SINGLE, TMO_NORMAL, [
227
    ("bdev", OBJECT_TO_DICT, None),
228
    ], None, "Request removal of a given block device"),
229
  ("blockdev_pause_resume_sync", SINGLE, TMO_NORMAL, [
230
    ("disks", OBJECT_LIST_TO_DICT, None),
231
    ("pause", None, None),
232
    ], None, "Request a pause/resume of given block device"),
233
  ("blockdev_assemble", SINGLE, TMO_NORMAL, [
234
    ("disk", OBJECT_TO_DICT, None),
235
    ("owner", None, None),
236
    ("on_primary", None, None),
237
    ("idx", None, None),
238
    ], None, "Request assembling of a given block device"),
239
  ("blockdev_shutdown", SINGLE, TMO_NORMAL, [
240
    ("disk", OBJECT_TO_DICT, None),
241
    ], None, "Request shutdown of a given block device"),
242
  ("blockdev_addchildren", SINGLE, TMO_NORMAL, [
243
    ("bdev", OBJECT_TO_DICT, None),
244
    ("ndevs", OBJECT_LIST_TO_DICT, None),
245
    ], None, "Request adding a list of children to a (mirroring) device"),
246
  ("blockdev_removechildren", SINGLE, TMO_NORMAL, [
247
    ("bdev", OBJECT_TO_DICT, None),
248
    ("ndevs", OBJECT_LIST_TO_DICT, None),
249
    ], None, "Request removing a list of children from a (mirroring) device"),
250
  ("blockdev_close", SINGLE, TMO_NORMAL, [
251
    ("instance_name", None, None),
252
    ("disks", OBJECT_LIST_TO_DICT, None),
253
    ], None, "Closes the given block devices"),
254
  ("blockdev_getsize", SINGLE, TMO_NORMAL, [
255
    ("disks", OBJECT_LIST_TO_DICT, None),
256
    ], None, "Returns the size of the given disks"),
257
  ("drbd_disconnect_net", MULTI, TMO_NORMAL, [
258
    ("nodes_ip", None, None),
259
    ("disks", OBJECT_LIST_TO_DICT, None),
260
    ], None, "Disconnects the network of the given drbd devices"),
261
  ("drbd_attach_net", MULTI, TMO_NORMAL, [
262
    ("nodes_ip", None, None),
263
    ("disks", OBJECT_LIST_TO_DICT, None),
264
    ("instance_name", None, None),
265
    ("multimaster", None, None),
266
    ], None, "Connects the given DRBD devices"),
267
  ("drbd_wait_sync", MULTI, TMO_SLOW, [
268
    ("nodes_ip", None, None),
269
    ("disks", OBJECT_LIST_TO_DICT, None),
270
    ], None, "Waits for the synchronization of drbd devices is complete"),
271
  ("blockdev_grow", SINGLE, TMO_NORMAL, [
272
    ("cf_bdev", OBJECT_TO_DICT, None),
273
    ("amount", None, None),
274
    ("dryrun", None, None),
275
    ], None, "Request a snapshot of the given block device"),
276
  ("blockdev_export", SINGLE, TMO_1DAY, [
277
    ("cf_bdev", OBJECT_TO_DICT, None),
278
    ("dest_node", None, None),
279
    ("dest_path", None, None),
280
    ("cluster_name", None, None),
281
    ], None, "Export a given disk to another node"),
282
  ("blockdev_snapshot", SINGLE, TMO_NORMAL, [
283
    ("cf_bdev", OBJECT_TO_DICT, None),
284
    ], None, "Export a given disk to another node"),
285
  ("blockdev_rename", SINGLE, TMO_NORMAL, [
286
    ("devlist", "[(d.ToDict(), uid) for d, uid in %s]", None),
287
    ], None, "Request rename of the given block devices"),
288
  ("blockdev_find", SINGLE, TMO_NORMAL, [
289
    ("disk", OBJECT_TO_DICT, None),
290
    ], "self._BlockdevFindPostProc",
291
    "Request identification of a given block device"),
292
  ("blockdev_getmirrorstatus", SINGLE, TMO_NORMAL, [
293
    ("disks", OBJECT_LIST_TO_DICT, None),
294
    ], "self._BlockdevGetMirrorStatusPostProc",
295
    "Request status of a (mirroring) device"),
296
  ("blockdev_getmirrorstatus_multi", MULTI, TMO_NORMAL, [
297
    ("node_disks", NODE_TO_DISK_DICT, None),
298
    ], "self._BlockdevGetMirrorStatusMultiPostProc",
299
    "Request status of (mirroring) devices from multiple nodes"),
300
  ]
301

    
302
_OS_CALLS = [
303
  ("os_diagnose", MULTI, TMO_FAST, [], None,
304
   "Request a diagnose of OS definitions"),
305
  ("os_validate", MULTI, TMO_FAST, [
306
    ("required", None, None),
307
    ("name", None, None),
308
    ("checks", None, None),
309
    ("params", None, None),
310
    ], None, "Run a validation routine for a given OS"),
311
  ("os_get", SINGLE, TMO_FAST, [
312
    ("name", None, None),
313
    ], "self._OsGetPostProc", "Returns an OS definition"),
314
  ]
315

    
316
_NODE_CALLS = [
317
  ("node_has_ip_address", SINGLE, TMO_FAST, [
318
    ("address", None, "IP address"),
319
    ], None, "Checks if a node has the given IP address"),
320
  ("node_info", MULTI, TMO_URGENT, [
321
    ("vg_name", None,
322
     "Name of the volume group to ask for disk space information"),
323
    ("hypervisor_type", None,
324
     "Name of the hypervisor to ask for memory information"),
325
    ], None, "Return node information"),
326
  ("node_verify", MULTI, TMO_NORMAL, [
327
    ("checkdict", None, None),
328
    ("cluster_name", None, None),
329
    ], None, "Request verification of given parameters"),
330
  ("node_volumes", MULTI, TMO_FAST, [], None, "Gets all volumes on node(s)"),
331
  ("node_demote_from_mc", SINGLE, TMO_FAST, [], None,
332
   "Demote a node from the master candidate role"),
333
  ("node_powercycle", SINGLE, TMO_NORMAL, [
334
    ("hypervisor", None, "Hypervisor type"),
335
    ], None, "Tries to powercycle a node"),
336
  ]
337

    
338
_MISC_CALLS = [
339
  ("lv_list", MULTI, TMO_URGENT, [
340
    ("vg_name", None, None),
341
    ], None, "Gets the logical volumes present in a given volume group"),
342
  ("vg_list", MULTI, TMO_URGENT, [], None, "Gets the volume group list"),
343
  ("bridges_exist", SINGLE, TMO_URGENT, [
344
    ("bridges_list", None, "Bridges which must be present on remote node"),
345
    ], None, "Checks if a node has all the bridges given"),
346
  ("etc_hosts_modify", SINGLE, TMO_NORMAL, [
347
    ("mode", None,
348
     "Mode to operate; currently L{constants.ETC_HOSTS_ADD} or"
349
     " L{constants.ETC_HOSTS_REMOVE}"),
350
    ("name", None, "Hostname to be modified"),
351
    ("ip", None, "IP address (L{constants.ETC_HOSTS_ADD} only)"),
352
    ], None, "Modify hosts file with name"),
353
  ("drbd_helper", MULTI, TMO_URGENT, [], None, "Gets DRBD helper"),
354
  ("run_oob", SINGLE, TMO_NORMAL, [
355
    ("oob_program", None, None),
356
    ("command", None, None),
357
    ("remote_node", None, None),
358
    ("timeout", None, None),
359
    ], None, "Runs out-of-band command"),
360
  ("hooks_runner", MULTI, TMO_NORMAL, [
361
    ("hpath", None, None),
362
    ("phase", None, None),
363
    ("env", None, None),
364
    ], None, "Call the hooks runner"),
365
  ("iallocator_runner", SINGLE, TMO_NORMAL, [
366
    ("name", None, "Iallocator name"),
367
    ("idata", None, "JSON-encoded input string"),
368
    ], None, "Call an iallocator on a remote node"),
369
  ("test_delay", MULTI, None, [
370
    ("duration", None, None),
371
    ], None, "Sleep for a fixed time on given node(s)"),
372
  ("hypervisor_validate_params", MULTI, TMO_NORMAL, [
373
    ("hvname", None, "Hypervisor name"),
374
    ("hvfull", None, "Parameters to be validated"),
375
    ], None, "Validate hypervisor params"),
376
  ]
377

    
378
CALLS = {
379
  "RpcClientDefault": (_IMPEXP_CALLS + _X509_CALLS + _OS_CALLS + _NODE_CALLS +
380
    _FILE_STORAGE_CALLS + _MISC_CALLS + _INSTANCE_CALLS + _BLOCKDEV_CALLS +
381
    _STORAGE_CALLS),
382
  "RpcClientJobQueue": [
383
    ("jobqueue_update", MULTI, TMO_URGENT, [
384
      ("file_name", None, None),
385
      ("content", "self._Compress(%s)", None),
386
      ], None, "Update job queue file"),
387
    ("jobqueue_purge", SINGLE, TMO_NORMAL, [], None, "Purge job queue"),
388
    ("jobqueue_rename", MULTI, TMO_URGENT, [
389
      ("rename", None, None),
390
      ], None, "Rename job queue file"),
391
    ],
392
  "RpcClientBootstrap": [
393
    ("node_start_master_daemons", SINGLE, TMO_FAST, [
394
      ("no_voting", None, None),
395
      ], None, "Starts master daemons on a node"),
396
    ("node_activate_master_ip", SINGLE, TMO_FAST, [], None,
397
     "Activates master IP on a node"),
398
    ("node_stop_master", SINGLE, TMO_FAST, [], None,
399
     "Deactivates master IP and stops master daemons on a node"),
400
    ("node_deactivate_master_ip", SINGLE, TMO_FAST, [], None,
401
     "Deactivates master IP on a node"),
402
    ("node_change_master_netmask", SINGLE, TMO_FAST, [
403
      ("netmask", None, None),
404
      ], None, "Change master IP netmask"),
405
    ("node_leave_cluster", SINGLE, TMO_NORMAL, [
406
      ("modify_ssh_setup", None, None),
407
      ], None, "Requests a node to clean the cluster information it has"),
408
    ("master_info", MULTI, TMO_URGENT, [], None, "Query master info"),
409
    ("version", MULTI, TMO_URGENT, [], None, "Query node version"),
410
    ],
411
  "RpcClientConfig": [
412
    ("upload_file", MULTI, TMO_NORMAL, [
413
      ("file_name", "self._PrepareFileUpload(%s)", None),
414
      ], None, "Upload a file"),
415
    ("write_ssconf_files", MULTI, TMO_NORMAL, [
416
      ("values", None, None),
417
      ], None, "Write ssconf files"),
418
    ],
419
  }