Statistics
| Branch: | Tag: | Revision:

root / lib / build / rpc_definitions.py @ 46c293f0

History | View | Annotate | Download (14.2 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
  ]
146

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

    
186
_X509_CALLS = [
187
  ("x509_cert_create", SINGLE, TMO_NORMAL, [
188
    ("validity", None, "Validity in seconds"),
189
    ], None, "Creates a new X509 certificate for SSL/TLS"),
190
  ("x509_cert_remove", SINGLE, TMO_NORMAL, [
191
    ("name", None, "Certificate name"),
192
    ], None, "Removes a X509 certificate"),
193
  ]
194

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

    
288
_OS_CALLS = [
289
  ("os_diagnose", MULTI, TMO_FAST, [], None,
290
   "Request a diagnose of OS definitions"),
291
  ("os_validate", MULTI, TMO_FAST, [
292
    ("required", None, None),
293
    ("name", None, None),
294
    ("checks", None, None),
295
    ("params", None, None),
296
    ], None, "Run a validation routine for a given OS"),
297
  ("os_get", SINGLE, TMO_FAST, [
298
    ("name", None, None),
299
    ], "self._OsGetPostProc", "Returns an OS definition"),
300
  ]
301

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

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

    
360
CALLS = {
361
  "RpcClientDefault": (_IMPEXP_CALLS + _X509_CALLS + _OS_CALLS + _NODE_CALLS +
362
    _FILE_STORAGE_CALLS + _MISC_CALLS + _INSTANCE_CALLS + _BLOCKDEV_CALLS +
363
    _STORAGE_CALLS),
364
  }