Statistics
| Branch: | Tag: | Revision:

root / lib / build / rpc_definitions.py @ c4de9b7a

History | View | Annotate | Download (15.8 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
# Various time constants for the timeout table
41
TMO_URGENT = 60 # one minute
42
TMO_FAST = 5 * 60 # five minutes
43
TMO_NORMAL = 15 * 60 # 15 minutes
44
TMO_SLOW = 3600 # one hour
45
TMO_4HRS = 4 * 3600
46
TMO_1DAY = 86400
47

    
48
SINGLE = "single-node"
49
MULTI = "multi-node"
50

    
51
OBJECT_TO_DICT = "%s.ToDict()"
52
OBJECT_LIST_TO_DICT = "map(lambda d: d.ToDict(), %s)"
53
INST_TO_DICT = "self._InstDict(%s)"
54

    
55
NODE_TO_DISK_DICT = \
56
  ("dict((name, %s) for name, disks in %%s.items())" %
57
   (OBJECT_LIST_TO_DICT % "disks"))
58

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

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

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

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

    
195
_X509_CALLS = [
196
  ("x509_cert_create", SINGLE, TMO_NORMAL, [
197
    ("validity", None, "Validity in seconds"),
198
    ], None, "Creates a new X509 certificate for SSL/TLS"),
199
  ("x509_cert_remove", SINGLE, TMO_NORMAL, [
200
    ("name", None, "Certificate name"),
201
    ], None, "Removes a X509 certificate"),
202
  ]
203

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

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

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

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

    
369
CALLS = {
370
  "RpcClientDefault": (_IMPEXP_CALLS + _X509_CALLS + _OS_CALLS + _NODE_CALLS +
371
    _FILE_STORAGE_CALLS + _MISC_CALLS + _INSTANCE_CALLS + _BLOCKDEV_CALLS +
372
    _STORAGE_CALLS),
373
  "RpcClientJobQueue": [
374
    ("jobqueue_update", MULTI, TMO_URGENT, [
375
      ("file_name", None, None),
376
      ("content", "self._Compress(%s)", None),
377
      ], None, "Update job queue file"),
378
    ("jobqueue_purge", SINGLE, TMO_NORMAL, [], None, "Purge job queue"),
379
    ("jobqueue_rename", MULTI, TMO_URGENT, [
380
      ("rename", None, None),
381
      ], None, "Rename job queue file"),
382
    ],
383
  "RpcClientBootstrap": [
384
    ("node_start_master_daemons", SINGLE, TMO_FAST, [
385
      ("no_voting", None, None),
386
      ], None, "Starts master daemons on a node"),
387
    ("node_activate_master_ip", SINGLE, TMO_FAST, [], None,
388
     "Activates master IP on a node"),
389
    ("node_stop_master", SINGLE, TMO_FAST, [], None,
390
     "Deactivates master IP and stops master daemons on a node"),
391
    ("node_deactivate_master_ip", SINGLE, TMO_FAST, [], None,
392
     "Deactivates master IP on a node"),
393
    ("node_change_master_netmask", SINGLE, TMO_FAST, [
394
      ("netmask", None, None),
395
      ], None, "Change master IP netmask"),
396
    ("node_leave_cluster", SINGLE, TMO_NORMAL, [
397
      ("modify_ssh_setup", None, None),
398
      ], None, "Requests a node to clean the cluster information it has"),
399
    ("master_info", MULTI, TMO_URGENT, [], None, "Query master info"),
400
    ("version", MULTI, TMO_URGENT, [], None, "Query node version"),
401
    ],
402
  }