Revision 6648cb36

b/Makefile.am
174 174

  
175 175
noinst_PYTHON = \
176 176
	lib/build/__init__.py \
177
	lib/build/rpc_definitions.py \
178 177
	lib/build/sphinx_ext.py
179 178

  
180 179
pkgpython_PYTHON = \
......
203 202
	lib/qlang.py \
204 203
	lib/query.py \
205 204
	lib/rpc.py \
205
	lib/rpc_defs.py \
206 206
	lib/runtime.py \
207 207
	lib/serializer.py \
208 208
	lib/ssconf.py \
......
1020 1020
	  echo "VCS_VERSION = '$$VCSVER'"; \
1021 1021
	} > $@
1022 1022

  
1023
lib/_generated_rpc.py: lib/build/rpc_definitions.py $(BUILD_RPC) | lib/.dir
1023
lib/_generated_rpc.py: lib/rpc_defs.py $(BUILD_RPC) | lib/.dir
1024 1024
	PYTHONPATH=. $(RUN_IN_TEMPDIR) $(CURDIR)/$(BUILD_RPC) $< > $@
1025 1025

  
1026 1026
$(REPLACE_VARS_SED): Makefile
/dev/null
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", None, None),
169
    ("dest_args", "self._EncodeImportExportIO(dest, %s)", None),
170
    ], None, "Starts an import daemon"),
171
  ("export_start", SINGLE, TMO_NORMAL, [
172
    ("opts", OBJECT_TO_DICT, None),
173
    ("host", None, None),
174
    ("port", None, None),
175
    ("instance", INST_TO_DICT, None),
176
    ("component", None, None),
177
    ("source", None, None),
178
    ("source_args", "self._EncodeImportExportIO(source, %s)", None),
179
    ], None, "Starts an export daemon"),
180
  ("impexp_status", SINGLE, TMO_FAST, [
181
    ("names", None, "Import/export names"),
182
    ], "self._ImpExpStatusPostProc", "Gets the status of an import or export"),
183
  ("impexp_abort", SINGLE, TMO_NORMAL, [
184
    ("name", None, "Import/export name"),
185
    ], None, "Aborts an import or export"),
186
  ("impexp_cleanup", SINGLE, TMO_NORMAL, [
187
    ("name", None, "Import/export name"),
188
    ], None, "Cleans up after an import or export"),
189
  ("export_info", SINGLE, TMO_FAST, [
190
    ("path", None, None),
191
    ], None, "Queries the export information in a given path"),
192
  ("finalize_export", SINGLE, TMO_NORMAL, [
193
    ("instance", INST_TO_DICT, None),
194
    ("snap_disks", "self._PrepareFinalizeExportDisks(%s)", None),
195
    ], None, "Request the completion of an export operation"),
196
  ("export_list", MULTI, TMO_FAST, [], None, "Gets the stored exports list"),
197
  ("export_remove", SINGLE, TMO_FAST, [
198
    ("export", None, None),
199
    ], None, "Requests removal of a given export"),
200
  ]
201

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

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

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

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

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

  
380
CALLS = {
381
  "RpcClientDefault": (_IMPEXP_CALLS + _X509_CALLS + _OS_CALLS + _NODE_CALLS +
382
    _FILE_STORAGE_CALLS + _MISC_CALLS + _INSTANCE_CALLS + _BLOCKDEV_CALLS +
383
    _STORAGE_CALLS),
384
  "RpcClientJobQueue": [
385
    ("jobqueue_update", MULTI, TMO_URGENT, [
386
      ("file_name", None, None),
387
      ("content", "self._Compress(%s)", None),
388
      ], None, "Update job queue file"),
389
    ("jobqueue_purge", SINGLE, TMO_NORMAL, [], None, "Purge job queue"),
390
    ("jobqueue_rename", MULTI, TMO_URGENT, [
391
      ("rename", None, None),
392
      ], None, "Rename job queue file"),
393
    ],
394
  "RpcClientBootstrap": [
395
    ("node_start_master_daemons", SINGLE, TMO_FAST, [
396
      ("no_voting", None, None),
397
      ], None, "Starts master daemons on a node"),
398
    ("node_activate_master_ip", SINGLE, TMO_FAST, [], None,
399
     "Activates master IP on a node"),
400
    ("node_stop_master", SINGLE, TMO_FAST, [], None,
401
     "Deactivates master IP and stops master daemons on a node"),
402
    ("node_deactivate_master_ip", SINGLE, TMO_FAST, [], None,
403
     "Deactivates master IP on a node"),
404
    ("node_change_master_netmask", SINGLE, TMO_FAST, [
405
      ("netmask", None, None),
406
      ], None, "Change master IP netmask"),
407
    ("node_leave_cluster", SINGLE, TMO_NORMAL, [
408
      ("modify_ssh_setup", None, None),
409
      ], None, "Requests a node to clean the cluster information it has"),
410
    ("master_info", MULTI, TMO_URGENT, [], None, "Query master info"),
411
    ("version", MULTI, TMO_URGENT, [], None, "Query node version"),
412
    ],
413
  "RpcClientConfig": [
414
    ("upload_file", MULTI, TMO_NORMAL, [
415
      ("file_name", "self._PrepareFileUpload(%s)", None),
416
      ], None, "Upload a file"),
417
    ("write_ssconf_files", MULTI, TMO_NORMAL, [
418
      ("values", None, None),
419
      ], None, "Write ssconf files"),
420
    ],
421
  }
b/lib/rpc_defs.py
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", None, None),
169
    ("dest_args", "self._EncodeImportExportIO(dest, %s)", None),
170
    ], None, "Starts an import daemon"),
171
  ("export_start", SINGLE, TMO_NORMAL, [
172
    ("opts", OBJECT_TO_DICT, None),
173
    ("host", None, None),
174
    ("port", None, None),
175
    ("instance", INST_TO_DICT, None),
176
    ("component", None, None),
177
    ("source", None, None),
178
    ("source_args", "self._EncodeImportExportIO(source, %s)", None),
179
    ], None, "Starts an export daemon"),
180
  ("impexp_status", SINGLE, TMO_FAST, [
181
    ("names", None, "Import/export names"),
182
    ], "self._ImpExpStatusPostProc", "Gets the status of an import or export"),
183
  ("impexp_abort", SINGLE, TMO_NORMAL, [
184
    ("name", None, "Import/export name"),
185
    ], None, "Aborts an import or export"),
186
  ("impexp_cleanup", SINGLE, TMO_NORMAL, [
187
    ("name", None, "Import/export name"),
188
    ], None, "Cleans up after an import or export"),
189
  ("export_info", SINGLE, TMO_FAST, [
190
    ("path", None, None),
191
    ], None, "Queries the export information in a given path"),
192
  ("finalize_export", SINGLE, TMO_NORMAL, [
193
    ("instance", INST_TO_DICT, None),
194
    ("snap_disks", "self._PrepareFinalizeExportDisks(%s)", None),
195
    ], None, "Request the completion of an export operation"),
196
  ("export_list", MULTI, TMO_FAST, [], None, "Gets the stored exports list"),
197
  ("export_remove", SINGLE, TMO_FAST, [
198
    ("export", None, None),
199
    ], None, "Requests removal of a given export"),
200
  ]
201

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

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

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

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

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

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

Also available in: Unified diff