Statistics
| Branch: | Tag: | Revision:

root / lib / build / rpc_definitions.py @ 0d1e78dd

History | View | Annotate | Download (16.5 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_start", SINGLE, TMO_NORMAL, [
150
    ("instance_hvp_bep", "self._InstDictHvpBep(%s)", None),
151
    ("startup_paused", None, None),
152
    ], None, "Starts an instance"),
153
  ("instance_os_add", SINGLE, TMO_1DAY, [
154
    ("instance_osp", "self._InstDictOsp(%s)", None),
155
    ("reinstall", None, None),
156
    ("debug", None, None),
157
    ], None, "Starts an instance"),
158
  ]
159

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

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

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

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

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

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

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