rpc_defs.py 30.6 KB
Newer Older
1 2 3
#
#

4
# Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2014 Google Inc.
Klaus Aehlig's avatar
Klaus Aehlig committed
5
# All rights reserved.
6
#
Klaus Aehlig's avatar
Klaus Aehlig committed
7 8 9
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
10
#
Klaus Aehlig's avatar
Klaus Aehlig committed
11 12
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
13
#
Klaus Aehlig's avatar
Klaus Aehlig committed
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 30 31

"""RPC definitions for communication between master and node daemons.

Michael Hanselmann's avatar
Michael Hanselmann committed
32 33 34 35
RPC definition fields:

  - Name as string
  - L{SINGLE} for single-node calls, L{MULTI} for multi-node
36
  - Name resolver option(s), can be callable receiving all arguments in a tuple
37 38
  - Timeout (e.g. L{constants.RPC_TMO_NORMAL}), or callback receiving all
    arguments in a tuple to calculate timeout
Michael Hanselmann's avatar
Michael Hanselmann committed
39 40 41
  - List of arguments as tuples

    - Name as string
42
    - Argument kind used for encoding/decoding
Michael Hanselmann's avatar
Michael Hanselmann committed
43 44
    - Description for docstring (can be C{None})

45
  - Custom body encoder (e.g. for preparing per-node bodies)
Michael Hanselmann's avatar
Michael Hanselmann committed
46 47 48
  - Return value wrapper (e.g. for deserializing into L{objects}-based objects)
  - Short call description for docstring

49 50
"""

51
from ganeti import constants
52
from ganeti import utils
53
from ganeti import objects
54

55

56
# Guidelines for choosing timeouts:
57 58 59 60 61 62
# - call used during watcher: timeout of 1min, constants.RPC_TMO_URGENT
# - trivial (but be sure it is trivial)
#     (e.g. reading a file): 5min, constants.RPC_TMO_FAST
# - other calls: 15 min, constants.RPC_TMO_NORMAL
# - special calls (instance add, etc.):
#     either constants.RPC_TMO_SLOW (1h) or huge timeouts
63 64 65 66

SINGLE = "single-node"
MULTI = "multi-node"

67 68
ACCEPT_OFFLINE_NODE = object()

69 70 71 72
# Constants for encoding/decoding
(ED_OBJECT_DICT,
 ED_OBJECT_DICT_LIST,
 ED_INST_DICT,
73
 ED_INST_DICT_HVP_BEP_DP,
74
 ED_NODE_TO_DISK_DICT_DP,
75
 ED_INST_DICT_OSP_DP,
76 77 78 79
 ED_IMPEXP_IO,
 ED_FILE_DETAILS,
 ED_FINALIZE_EXPORT_DISKS,
 ED_COMPRESS,
80 81
 ED_BLOCKDEV_RENAME,
 ED_DISKS_DICT_DP,
82
 ED_MULTI_DISKS_DICT_DP,
Dimitris Aragiorgis's avatar
Dimitris Aragiorgis committed
83
 ED_SINGLE_DISK_DICT_DP,
Dimitris Aragiorgis's avatar
Dimitris Aragiorgis committed
84 85
 ED_NIC_DICT,
 ED_DEVICE_DICT) = range(1, 17)
86

87 88 89 90 91 92 93 94

def _Prepare(calls):
  """Converts list of calls to dictionary.

  """
  return utils.SequenceToDict(calls)


95
def _MigrationStatusPostProc(result):
96
  """Post-processor for L{rpc.node.RpcRunner.call_instance_get_migration_status}
97 98 99 100 101 102 103 104

  """
  if not result.fail_msg and result.payload is not None:
    result.payload = objects.MigrationStatus.FromDict(result.payload)
  return result


def _BlockdevFindPostProc(result):
Santi Raffa's avatar
Santi Raffa committed
105
  """Post-processor for L{rpc.node.RpcRunner.call_blockdev_find}.
106 107 108 109 110 111 112 113

  """
  if not result.fail_msg and result.payload is not None:
    result.payload = objects.BlockDevStatus.FromDict(result.payload)
  return result


def _BlockdevGetMirrorStatusPostProc(result):
Santi Raffa's avatar
Santi Raffa committed
114
  """Post-processor for call_blockdev_getmirrorstatus.
115 116 117 118 119 120 121

  """
  if not result.fail_msg:
    result.payload = map(objects.BlockDevStatus.FromDict, result.payload)
  return result


122 123 124 125 126 127 128 129 130 131 132
def _BlockdevGetMirrorStatusMultiPreProc(node, args):
  """Prepares the appropriate node values for blockdev_getmirrorstatus_multi.

  """
  # there should be only one argument to this RPC, already holding a
  # node->disks dictionary, we just need to extract the value for the
  # current node
  assert len(args) == 1
  return [args[0][node]]


133
def _BlockdevGetMirrorStatusMultiPostProc(result):
Santi Raffa's avatar
Santi Raffa committed
134
  """Post-processor for call_blockdev_getmirrorstatus_multi.
135 136

  """
137 138
  if not result.fail_msg:
    for idx, (success, status) in enumerate(result.payload):
139
      if success:
140
        result.payload[idx] = (success, objects.BlockDevStatus.FromDict(status))
141 142 143 144

  return result


145
def _NodeInfoPreProc(node, args):
146 147 148 149 150 151
  """Prepare the storage_units argument for node_info calls."""
  assert len(args) == 2
  # The storage_units argument is either a dictionary with one value for each
  # node, or a fixed value to be used for all the nodes
  if type(args[0]) is dict:
    return [args[0][node], args[1]]
152 153 154 155
  else:
    return args


156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
def _ImpExpStatusPostProc(result):
  """Post-processor for import/export status.

  @rtype: Payload containing list of L{objects.ImportExportStatus} instances
  @return: Returns a list of the state of each named import/export or None if
           a status couldn't be retrieved

  """
  if not result.fail_msg:
    decoded = []

    for i in result.payload:
      if i is None:
        decoded.append(None)
        continue
      decoded.append(objects.ImportExportStatus.FromDict(i))

    result.payload = decoded

  return result


178 179 180 181 182 183 184
def _TestDelayTimeout((duration, )):
  """Calculate timeout for "test_delay" RPC.

  """
  return int(duration + 5)


Michael Hanselmann's avatar
Michael Hanselmann committed
185
_FILE_STORAGE_CALLS = [
186
  ("file_storage_dir_create", SINGLE, None, constants.RPC_TMO_FAST, [
Michael Hanselmann's avatar
Michael Hanselmann committed
187
    ("file_storage_dir", None, "File storage directory"),
188
    ], None, None, "Create the given file storage directory"),
189
  ("file_storage_dir_remove", SINGLE, None, constants.RPC_TMO_FAST, [
Michael Hanselmann's avatar
Michael Hanselmann committed
190
    ("file_storage_dir", None, "File storage directory"),
191
    ], None, None, "Remove the given file storage directory"),
192
  ("file_storage_dir_rename", SINGLE, None, constants.RPC_TMO_FAST, [
Michael Hanselmann's avatar
Michael Hanselmann committed
193 194
    ("old_file_storage_dir", None, "Old name"),
    ("new_file_storage_dir", None, "New name"),
195
    ], None, None, "Rename file storage directory"),
Michael Hanselmann's avatar
Michael Hanselmann committed
196 197 198
  ]

_STORAGE_CALLS = [
199
  ("storage_list", MULTI, None, constants.RPC_TMO_NORMAL, [
Michael Hanselmann's avatar
Michael Hanselmann committed
200 201 202 203
    ("su_name", None, None),
    ("su_args", None, None),
    ("name", None, None),
    ("fields", None, None),
204
    ], None, None, "Get list of storage units"),
205
  ("storage_modify", SINGLE, None, constants.RPC_TMO_NORMAL, [
Michael Hanselmann's avatar
Michael Hanselmann committed
206 207 208 209
    ("su_name", None, None),
    ("su_args", None, None),
    ("name", None, None),
    ("changes", None, None),
210
    ], None, None, "Modify a storage unit"),
211
  ("storage_execute", SINGLE, None, constants.RPC_TMO_NORMAL, [
Michael Hanselmann's avatar
Michael Hanselmann committed
212 213 214 215
    ("su_name", None, None),
    ("su_args", None, None),
    ("name", None, None),
    ("op", None, None),
216
    ], None, None, "Executes an operation on a storage unit"),
Michael Hanselmann's avatar
Michael Hanselmann committed
217 218 219
  ]

_INSTANCE_CALLS = [
220
  ("instance_info", SINGLE, None, constants.RPC_TMO_URGENT, [
Michael Hanselmann's avatar
Michael Hanselmann committed
221 222
    ("instance", None, "Instance name"),
    ("hname", None, "Hypervisor type"),
223
    ("hvparams", None, "Hypervisor parameters"),
224
    ], None, None, "Returns information about a single instance"),
225
  ("all_instances_info", MULTI, None, constants.RPC_TMO_URGENT, [
Michael Hanselmann's avatar
Michael Hanselmann committed
226
    ("hypervisor_list", None, "Hypervisors to query for instances"),
227
    ("all_hvparams", None, "Dictionary mapping hypervisor names to hvparams"),
228 229
    ], None, None,
   "Returns information about all instances on the given nodes"),
230
  ("instance_list", MULTI, None, constants.RPC_TMO_URGENT, [
Michael Hanselmann's avatar
Michael Hanselmann committed
231
    ("hypervisor_list", None, "Hypervisors to query for instances"),
232
    ("hvparams", None, "Hvparams of all hypervisors"),
233
    ], None, None, "Returns the list of running instances on the given nodes"),
234
  ("instance_reboot", SINGLE, None, constants.RPC_TMO_NORMAL, [
235
    ("inst", ED_INST_DICT, "Instance object"),
Michael Hanselmann's avatar
Michael Hanselmann committed
236 237
    ("reboot_type", None, None),
    ("shutdown_timeout", None, None),
238
    ("reason", None, "The reason for the reboot"),
239
    ], None, None, "Returns the list of running instances on the given nodes"),
240
  ("instance_shutdown", SINGLE, None, constants.RPC_TMO_NORMAL, [
241
    ("instance", ED_INST_DICT, "Instance object"),
Michael Hanselmann's avatar
Michael Hanselmann committed
242
    ("timeout", None, None),
243
    ("reason", None, "The reason for the shutdown"),
244
    ], None, None, "Stops an instance"),
245
  ("instance_balloon_memory", SINGLE, None, constants.RPC_TMO_NORMAL, [
246 247 248
    ("instance", ED_INST_DICT, "Instance object"),
    ("memory", None, None),
    ], None, None, "Modify the amount of an instance's runtime memory"),
249
  ("instance_run_rename", SINGLE, None, constants.RPC_TMO_SLOW, [
250
    ("instance", ED_INST_DICT, "Instance object"),
Michael Hanselmann's avatar
Michael Hanselmann committed
251 252
    ("old_name", None, None),
    ("debug", None, None),
253
    ], None, None, "Run the OS rename script for an instance"),
254
  ("instance_migratable", SINGLE, None, constants.RPC_TMO_NORMAL, [
255
    ("instance", ED_INST_DICT, "Instance object"),
256
    ], None, None, "Checks whether the given instance can be migrated"),
257
  ("migration_info", SINGLE, None, constants.RPC_TMO_NORMAL, [
258
    ("instance", ED_INST_DICT, "Instance object"),
259
    ], None, None,
Michael Hanselmann's avatar
Michael Hanselmann committed
260
    "Gather the information necessary to prepare an instance migration"),
261
  ("accept_instance", SINGLE, None, constants.RPC_TMO_NORMAL, [
262
    ("instance", ED_INST_DICT, "Instance object"),
Michael Hanselmann's avatar
Michael Hanselmann committed
263 264
    ("info", None, "Result for the call_migration_info call"),
    ("target", None, "Target hostname (usually an IP address)"),
265
    ], None, None, "Prepare a node to accept an instance"),
266
  ("instance_finalize_migration_dst", SINGLE, None, constants.RPC_TMO_NORMAL, [
267
    ("instance", ED_INST_DICT, "Instance object"),
Michael Hanselmann's avatar
Michael Hanselmann committed
268 269
    ("info", None, "Result for the call_migration_info call"),
    ("success", None, "Whether the migration was a success or failure"),
270
    ], None, None, "Finalize any target-node migration specific operation"),
271
  ("instance_migrate", SINGLE, None, constants.RPC_TMO_SLOW, [
272
    ("cluster_name", None, "Cluster name"),
273
    ("instance", ED_INST_DICT, "Instance object"),
Michael Hanselmann's avatar
Michael Hanselmann committed
274 275
    ("target", None, "Target node name"),
    ("live", None, "Whether the migration should be done live or not"),
276
    ], None, None, "Migrate an instance"),
277
  ("instance_finalize_migration_src", SINGLE, None, constants.RPC_TMO_SLOW, [
278
    ("instance", ED_INST_DICT, "Instance object"),
Michael Hanselmann's avatar
Michael Hanselmann committed
279 280
    ("success", None, "Whether the migration succeeded or not"),
    ("live", None, "Whether the user requested a live migration or not"),
281
    ], None, None, "Finalize the instance migration on the source node"),
282
  ("instance_get_migration_status", SINGLE, None, constants.RPC_TMO_SLOW, [
283
    ("instance", ED_INST_DICT, "Instance object"),
284
    ], None, _MigrationStatusPostProc, "Report migration status"),
285
  ("instance_start", SINGLE, None, constants.RPC_TMO_NORMAL, [
286
    ("instance_hvp_bep", ED_INST_DICT_HVP_BEP_DP, None),
287
    ("startup_paused", None, None),
288
    ("reason", None, "The reason for the startup"),
289
    ], None, None, "Starts an instance"),
290
  ("instance_os_add", SINGLE, None, constants.RPC_TMO_1DAY, [
291 292 293 294 295 296
    ("instance_osp", ED_INST_DICT_OSP_DP, "Tuple: (target instance,"
                                          " temporary OS parameters"
                                          " overriding configuration)"),
    ("reinstall", None, "Whether the instance is being reinstalled"),
    ("debug", None, "Debug level for the OS install script to use"),
    ], None, None, "Installs an operative system onto an instance"),
Dimitris Aragiorgis's avatar
Dimitris Aragiorgis committed
297 298 299 300 301 302 303 304
  ("hotplug_device", SINGLE, None, constants.RPC_TMO_NORMAL, [
    ("instance", ED_INST_DICT, "Instance object"),
    ("action", None, "Hotplug Action"),
    ("dev_type", None, "Device type"),
    ("device", ED_DEVICE_DICT, "Device dict"),
    ("extra", None, "Extra info for device (dev_path for disk)"),
    ("seq", None, "Device seq"),
    ], None, None, "Hoplug a device to a running instance"),
305 306 307
  ("hotplug_supported", SINGLE, None, constants.RPC_TMO_NORMAL, [
    ("instance", ED_INST_DICT, "Instance object"),
    ], None, None, "Check if hotplug is supported"),
Jose A. Lopes's avatar
Jose A. Lopes committed
308 309 310
  ("instance_metadata_modify", SINGLE, None, constants.RPC_TMO_URGENT, [
    ("instance", None, "Instance object"),
    ], None, None, "Modify instance metadata"),
Michael Hanselmann's avatar
Michael Hanselmann committed
311 312 313
  ]

_IMPEXP_CALLS = [
314
  ("import_start", SINGLE, None, constants.RPC_TMO_NORMAL, [
315 316
    ("opts", ED_OBJECT_DICT, None),
    ("instance", ED_INST_DICT, None),
317
    ("component", None, None),
318
    ("dest", ED_IMPEXP_IO, "Import destination"),
319
    ], None, None, "Starts an import daemon"),
320
  ("export_start", SINGLE, None, constants.RPC_TMO_NORMAL, [
321
    ("opts", ED_OBJECT_DICT, None),
322 323
    ("host", None, None),
    ("port", None, None),
324
    ("instance", ED_INST_DICT, None),
325
    ("component", None, None),
326
    ("source", ED_IMPEXP_IO, "Export source"),
327
    ], None, None, "Starts an export daemon"),
328
  ("impexp_status", SINGLE, None, constants.RPC_TMO_FAST, [
Michael Hanselmann's avatar
Michael Hanselmann committed
329
    ("names", None, "Import/export names"),
330
    ], None, _ImpExpStatusPostProc, "Gets the status of an import or export"),
331
  ("impexp_abort", SINGLE, None, constants.RPC_TMO_NORMAL, [
Michael Hanselmann's avatar
Michael Hanselmann committed
332
    ("name", None, "Import/export name"),
333
    ], None, None, "Aborts an import or export"),
334
  ("impexp_cleanup", SINGLE, None, constants.RPC_TMO_NORMAL, [
Michael Hanselmann's avatar
Michael Hanselmann committed
335
    ("name", None, "Import/export name"),
336
    ], None, None, "Cleans up after an import or export"),
337
  ("export_info", SINGLE, None, constants.RPC_TMO_FAST, [
Michael Hanselmann's avatar
Michael Hanselmann committed
338
    ("path", None, None),
339
    ], None, None, "Queries the export information in a given path"),
340
  ("finalize_export", SINGLE, None, constants.RPC_TMO_NORMAL, [
341 342
    ("instance", ED_INST_DICT, None),
    ("snap_disks", ED_FINALIZE_EXPORT_DISKS, None),
343
    ], None, None, "Request the completion of an export operation"),
344
  ("export_list", MULTI, None, constants.RPC_TMO_FAST, [], None, None,
345
   "Gets the stored exports list"),
346
  ("export_remove", SINGLE, None, constants.RPC_TMO_FAST, [
Michael Hanselmann's avatar
Michael Hanselmann committed
347
    ("export", None, None),
348
    ], None, None, "Requests removal of a given export"),
Michael Hanselmann's avatar
Michael Hanselmann committed
349 350 351
  ]

_X509_CALLS = [
352
  ("x509_cert_create", SINGLE, None, constants.RPC_TMO_NORMAL, [
Michael Hanselmann's avatar
Michael Hanselmann committed
353
    ("validity", None, "Validity in seconds"),
354
    ], None, None, "Creates a new X509 certificate for SSL/TLS"),
355
  ("x509_cert_remove", SINGLE, None, constants.RPC_TMO_NORMAL, [
Michael Hanselmann's avatar
Michael Hanselmann committed
356
    ("name", None, "Certificate name"),
357
    ], None, None, "Removes a X509 certificate"),
Michael Hanselmann's avatar
Michael Hanselmann committed
358 359 360
  ]

_BLOCKDEV_CALLS = [
361
  ("bdev_sizes", MULTI, None, constants.RPC_TMO_URGENT, [
Michael Hanselmann's avatar
Michael Hanselmann committed
362
    ("devices", None, None),
363 364
    ], None, None,
   "Gets the sizes of requested block devices present on a node"),
365
  ("blockdev_create", SINGLE, None, constants.RPC_TMO_NORMAL, [
366
    ("bdev", ED_SINGLE_DISK_DICT_DP, None),
Michael Hanselmann's avatar
Michael Hanselmann committed
367 368 369 370
    ("size", None, None),
    ("owner", None, None),
    ("on_primary", None, None),
    ("info", None, None),
371
    ("exclusive_storage", None, None),
372
    ], None, None, "Request creation of a given block device"),
373 374 375 376 377
  ("blockdev_convert", SINGLE, None, constants.RPC_TMO_SLOW, [
    ("bdev_src", ED_SINGLE_DISK_DICT_DP, None),
    ("bdev_dest", ED_SINGLE_DISK_DICT_DP, None),
    ], None, None,
    "Request the copy of the source block device to the destination one"),
378 379 380 381 382 383
  ("blockdev_image", SINGLE, None, constants.RPC_TMO_SLOW, [
    ("bdev", ED_SINGLE_DISK_DICT_DP, None),
    ("image", None, None),
    ("size", None, None),
    ], None, None,
    "Request to dump an image with given size onto a block device"),
384
  ("blockdev_wipe", SINGLE, None, constants.RPC_TMO_SLOW, [
385
    ("bdev", ED_SINGLE_DISK_DICT_DP, None),
Michael Hanselmann's avatar
Michael Hanselmann committed
386 387
    ("offset", None, None),
    ("size", None, None),
388
    ], None, None,
Michael Hanselmann's avatar
Michael Hanselmann committed
389
    "Request wipe at given offset with given size of a block device"),
390
  ("blockdev_remove", SINGLE, None, constants.RPC_TMO_NORMAL, [
391
    ("bdev", ED_SINGLE_DISK_DICT_DP, None),
392
    ], None, None, "Request removal of a given block device"),
393
  ("blockdev_pause_resume_sync", SINGLE, None, constants.RPC_TMO_NORMAL, [
394
    ("disks", ED_DISKS_DICT_DP, None),
Michael Hanselmann's avatar
Michael Hanselmann committed
395
    ("pause", None, None),
396
    ], None, None, "Request a pause/resume of given block device"),
397
  ("blockdev_assemble", SINGLE, None, constants.RPC_TMO_NORMAL, [
398
    ("disk", ED_SINGLE_DISK_DICT_DP, None),
399
    ("instance", ED_INST_DICT, None),
Michael Hanselmann's avatar
Michael Hanselmann committed
400 401
    ("on_primary", None, None),
    ("idx", None, None),
402
    ], None, None, "Request assembling of a given block device"),
403
  ("blockdev_shutdown", SINGLE, None, constants.RPC_TMO_NORMAL, [
404
    ("disk", ED_SINGLE_DISK_DICT_DP, None),
405
    ], None, None, "Request shutdown of a given block device"),
406
  ("blockdev_addchildren", SINGLE, None, constants.RPC_TMO_NORMAL, [
407
    ("bdev", ED_SINGLE_DISK_DICT_DP, None),
408
    ("ndevs", ED_DISKS_DICT_DP, None),
409 410
    ], None, None,
   "Request adding a list of children to a (mirroring) device"),
411
  ("blockdev_removechildren", SINGLE, None, constants.RPC_TMO_NORMAL, [
412 413
    ("bdev", ED_SINGLE_DISK_DICT_DP, None),
    ("ndevs", ED_DISKS_DICT_DP, None),
414 415
    ], None, None,
   "Request removing a list of children from a (mirroring) device"),
416
  ("blockdev_close", SINGLE, None, constants.RPC_TMO_NORMAL, [
Michael Hanselmann's avatar
Michael Hanselmann committed
417
    ("instance_name", None, None),
418
    ("disks", ED_DISKS_DICT_DP, None),
419
    ], None, None, "Closes the given block devices"),
420 421 422 423 424
  ("blockdev_open", SINGLE, None, constants.RPC_TMO_NORMAL, [
    ("instance_name", None, None),
    ("disks", ED_DISKS_DICT_DP, None),
    ("exclusive", None, None),
    ], None, None, "Opens the given block devices in required mode"),
425
  ("blockdev_getdimensions", SINGLE, None, constants.RPC_TMO_NORMAL, [
426
    ("disks", ED_MULTI_DISKS_DICT_DP, None),
427
    ], None, None, "Returns size and spindles of the given disks"),
428
  ("drbd_disconnect_net", MULTI, None, constants.RPC_TMO_NORMAL, [
429 430
    ("disks", ED_DISKS_DICT_DP, None),
    ], None, None,
Thomas Thrainer's avatar
Thomas Thrainer committed
431
   "Disconnects the network of the given drbd devices"),
432
  ("drbd_attach_net", MULTI, None, constants.RPC_TMO_NORMAL, [
433
    ("disks", ED_DISKS_DICT_DP, None),
Michael Hanselmann's avatar
Michael Hanselmann committed
434
    ("multimaster", None, None),
435
    ], None, None, "Connects the given DRBD devices"),
436
  ("drbd_wait_sync", MULTI, None, constants.RPC_TMO_SLOW, [
437
    ("disks", ED_DISKS_DICT_DP, None),
438
    ], None, None,
439
   "Waits for the synchronization of drbd devices is complete"),
440 441
  ("drbd_needs_activation", SINGLE, None, constants.RPC_TMO_NORMAL, [
    ("disks", ED_MULTI_DISKS_DICT_DP, None),
442
    ], None, None,
443
   "Returns the drbd disks which need activation"),
444
  ("blockdev_grow", SINGLE, None, constants.RPC_TMO_NORMAL, [
445
    ("cf_bdev", ED_SINGLE_DISK_DICT_DP, None),
Michael Hanselmann's avatar
Michael Hanselmann committed
446 447
    ("amount", None, None),
    ("dryrun", None, None),
Iustin Pop's avatar
Iustin Pop committed
448
    ("backingstore", None, None),
449
    ("es_flag", None, None),
Iustin Pop's avatar
Iustin Pop committed
450 451
    ], None, None, "Request growing of the given block device by a"
   " given amount"),
452
  ("blockdev_snapshot", SINGLE, None, constants.RPC_TMO_NORMAL, [
453
    ("cf_bdev", ED_SINGLE_DISK_DICT_DP, None),
454 455
    ("snap_name", None, None),
    ("snap_size", None, None),
456
    ], None, None, "Export a given disk to another node"),
457
  ("blockdev_rename", SINGLE, None, constants.RPC_TMO_NORMAL, [
458
    ("devlist", ED_BLOCKDEV_RENAME, None),
459
    ], None, None, "Request rename of the given block devices"),
460
  ("blockdev_find", SINGLE, None, constants.RPC_TMO_NORMAL, [
461
    ("disk", ED_SINGLE_DISK_DICT_DP, None),
462
    ], None, _BlockdevFindPostProc,
Michael Hanselmann's avatar
Michael Hanselmann committed
463
    "Request identification of a given block device"),
464
  ("blockdev_getmirrorstatus", SINGLE, None, constants.RPC_TMO_NORMAL, [
465
    ("disks", ED_DISKS_DICT_DP, None),
466
    ], None, _BlockdevGetMirrorStatusPostProc,
Michael Hanselmann's avatar
Michael Hanselmann committed
467
    "Request status of a (mirroring) device"),
468
  ("blockdev_getmirrorstatus_multi", MULTI, None, constants.RPC_TMO_NORMAL, [
469
    ("node_disks", ED_NODE_TO_DISK_DICT_DP, None),
470 471
    ], _BlockdevGetMirrorStatusMultiPreProc,
   _BlockdevGetMirrorStatusMultiPostProc,
Michael Hanselmann's avatar
Michael Hanselmann committed
472
    "Request status of (mirroring) devices from multiple nodes"),
473
  ("blockdev_setinfo", SINGLE, None, constants.RPC_TMO_NORMAL, [
474
    ("disk", ED_SINGLE_DISK_DICT_DP, None),
475 476
    ("info", None, None),
    ], None, None, "Sets metadata information on a given block device"),
Michael Hanselmann's avatar
Michael Hanselmann committed
477 478 479
  ]

_OS_CALLS = [
480
  ("os_diagnose", MULTI, None, constants.RPC_TMO_FAST, [], None, None,
Michael Hanselmann's avatar
Michael Hanselmann committed
481
   "Request a diagnose of OS definitions"),
482
  ("os_validate", MULTI, None, constants.RPC_TMO_FAST, [
Michael Hanselmann's avatar
Michael Hanselmann committed
483 484 485 486
    ("required", None, None),
    ("name", None, None),
    ("checks", None, None),
    ("params", None, None),
487
    ("force_variant", None, None),
488
    ], None, None, "Run a validation routine for a given OS"),
Jose A. Lopes's avatar
Jose A. Lopes committed
489 490
  ("os_export", SINGLE, None, constants.RPC_TMO_FAST, [
    ("instance", ED_INST_DICT, None),
491
    ("override_env", None, None),
Jose A. Lopes's avatar
Jose A. Lopes committed
492
    ], None, None, "Export an OS for a given instance"),
Michael Hanselmann's avatar
Michael Hanselmann committed
493 494
  ]

495 496 497 498 499
_EXTSTORAGE_CALLS = [
  ("extstorage_diagnose", MULTI, None, constants.RPC_TMO_FAST, [], None, None,
   "Request a diagnose of ExtStorage Providers"),
  ]

Michael Hanselmann's avatar
Michael Hanselmann committed
500
_NODE_CALLS = [
501
  ("node_has_ip_address", SINGLE, None, constants.RPC_TMO_FAST, [
Michael Hanselmann's avatar
Michael Hanselmann committed
502
    ("address", None, "IP address"),
503
    ], None, None, "Checks if a node has the given IP address"),
504
  ("node_info", MULTI, None, constants.RPC_TMO_URGENT, [
505
    ("storage_units", None,
506 507
     "List of tuples '<storage_type>,<key>,[<param>]' to ask for disk space"
     " information; the parameter list varies depending on the storage_type"),
508 509 510
    ("hv_specs", None,
     "List of hypervisor specification (name, hvparams) to ask for node "
     "information"),
511
    ], _NodeInfoPreProc, None, "Return node information"),
512
  ("node_verify", MULTI, None, constants.RPC_TMO_NORMAL, [
513 514 515
    ("checkdict", None, "What to verify"),
    ("cluster_name", None, "Cluster name"),
    ("all_hvparams", None, "Dictionary mapping hypervisor names to hvparams"),
516 517 518
    ("node_groups", None, "node names mapped to their group uuids"),
    ("groups_cfg", None,
      "a dictionary mapping group uuids to their configuration"),
519
    ], None, None, "Request verification of given parameters"),
520
  ("node_volumes", MULTI, None, constants.RPC_TMO_FAST, [], None, None,
521
   "Gets all volumes on node(s)"),
522
  ("node_demote_from_mc", SINGLE, None, constants.RPC_TMO_FAST, [], None, None,
Michael Hanselmann's avatar
Michael Hanselmann committed
523
   "Demote a node from the master candidate role"),
524
  ("node_powercycle", SINGLE, ACCEPT_OFFLINE_NODE, constants.RPC_TMO_NORMAL, [
Michael Hanselmann's avatar
Michael Hanselmann committed
525
    ("hypervisor", None, "Hypervisor type"),
526
    ("hvparams", None, "Hypervisor parameters"),
527
    ], None, None, "Tries to powercycle a node"),
528 529 530 531
  ("node_configure_ovs", SINGLE, None, constants.RPC_TMO_NORMAL, [
    ("ovs_name", None, "Name of the OpenvSwitch to create"),
    ("ovs_link", None, "Link of the OpenvSwitch to the outside"),
    ], None, None, "This will create and setup the OpenvSwitch"),
532
  ("node_crypto_tokens", SINGLE, None, constants.RPC_TMO_SLOW, [
533 534 535
    ("token_request", None,
     "List of tuples of requested crypto token types, actions"),
    ], None, None, "Handle crypto tokens of the node."),
536 537 538 539
  ("node_ensure_daemon", MULTI, None, constants.RPC_TMO_URGENT, [
    ("daemon", None, "Daemon name"),
    ("run", None, "Whether the daemon should be running or stopped"),
    ], None, None, "Ensure daemon is running on the node."),
540 541 542
  ("node_ssh_key_add", MULTI, None, constants.RPC_TMO_URGENT, [
    ("node_uuid", None, "UUID of the node whose key is distributed"),
    ("node_name", None, "Name of the node whose key is distributed"),
543 544
    ("potential_master_candidates", None, "Potential master candidates"),
    ("ssh_port_map", None, "Map of nodes' SSH ports to be used for transfers"),
545 546 547 548 549
    ("to_authorized_keys", None, "Whether the node's key should be added"
     " to all nodes' 'authorized_keys' file"),
    ("to_public_keys", None, "Whether the node's key should be added"
     " to all nodes' public key file"),
    ("get_public_keys", None, "Whether the node should get the other nodes'"
550
     " public keys")],
551
    None, None, "Distribute a new node's public SSH key on the cluster."),
552 553 554
  ("node_ssh_key_remove", MULTI, None, constants.RPC_TMO_URGENT, [
    ("node_uuid", None, "UUID of the node whose key is removed"),
    ("node_name", None, "Name of the node whose key is removed"),
555 556 557
    ("master_candidate_uuids", None, "List of UUIDs of master candidates."),
    ("potential_master_candidates", None, "Potential master candidates"),
    ("ssh_port_map", None, "Map of nodes' SSH ports to be used for transfers"),
558 559 560 561 562 563
    ("from_authorized_keys", None,
     "If the key should be removed from the 'authorized_keys' file."),
    ("from_public_keys", None,
     "If the key should be removed from the public key file."),
    ("clear_authorized_keys", None,
     "If the 'authorized_keys' file of the node should be cleared."),
564
    ("clear_public_keys", None,
565
     "If the 'ganeti_pub_keys' file of the node should be cleared.")],
566
    None, None, "Remove a node's SSH key from the other nodes' key files."),
567
  ("node_ssh_keys_renew", MULTI, None, constants.RPC_TMO_SLOW, [
Helga Velroyen's avatar
Helga Velroyen committed
568 569 570 571 572 573
    ("node_uuids", None, "UUIDs of the nodes whose key is renewed"),
    ("node_names", None, "Names of the nodes whose key is renewed"),
    ("ssh_port_map", None, "Map of nodes' SSH ports to be used for transfers"),
    ("master_candidate_uuids", None, "List of UUIDs of master candidates."),
    ("potential_master_candidates", None, "Potential master candidates")],
    None, None, "Renew all SSH key pairs of all nodes nodes."),
Michael Hanselmann's avatar
Michael Hanselmann committed
574 575 576
  ]

_MISC_CALLS = [
577
  ("lv_list", MULTI, None, constants.RPC_TMO_URGENT, [
Michael Hanselmann's avatar
Michael Hanselmann committed
578
    ("vg_name", None, None),
579
    ], None, None, "Gets the logical volumes present in a given volume group"),
580
  ("vg_list", MULTI, None, constants.RPC_TMO_URGENT, [], None, None,
581
   "Gets the volume group list"),
582
  ("bridges_exist", SINGLE, None, constants.RPC_TMO_URGENT, [
Michael Hanselmann's avatar
Michael Hanselmann committed
583
    ("bridges_list", None, "Bridges which must be present on remote node"),
584
    ], None, None, "Checks if a node has all the bridges given"),
585
  ("etc_hosts_modify", SINGLE, None, constants.RPC_TMO_NORMAL, [
Michael Hanselmann's avatar
Michael Hanselmann committed
586 587 588 589 590
    ("mode", None,
     "Mode to operate; currently L{constants.ETC_HOSTS_ADD} or"
     " L{constants.ETC_HOSTS_REMOVE}"),
    ("name", None, "Hostname to be modified"),
    ("ip", None, "IP address (L{constants.ETC_HOSTS_ADD} only)"),
591
    ], None, None, "Modify hosts file with name"),
592 593
  ("drbd_helper", MULTI, None, constants.RPC_TMO_URGENT, [],
   None, None, "Gets DRBD helper"),
594 595 596
  ("restricted_command", MULTI, None, constants.RPC_TMO_SLOW, [
    ("cmd", None, "Command name"),
    ], None, None, "Runs restricted command"),
597
  ("run_oob", SINGLE, None, constants.RPC_TMO_NORMAL, [
Michael Hanselmann's avatar
Michael Hanselmann committed
598 599 600 601
    ("oob_program", None, None),
    ("command", None, None),
    ("remote_node", None, None),
    ("timeout", None, None),
602
    ], None, None, "Runs out-of-band command"),
603
  ("hooks_runner", MULTI, None, constants.RPC_TMO_NORMAL, [
Michael Hanselmann's avatar
Michael Hanselmann committed
604 605 606
    ("hpath", None, None),
    ("phase", None, None),
    ("env", None, None),
607
    ], None, None, "Call the hooks runner"),
608
  ("iallocator_runner", SINGLE, None, constants.RPC_TMO_NORMAL, [
Michael Hanselmann's avatar
Michael Hanselmann committed
609 610
    ("name", None, "Iallocator name"),
    ("idata", None, "JSON-encoded input string"),
611
    ("default_iallocator_params", None, "Additional iallocator parameters"),
612
    ], None, None, "Call an iallocator on a remote node"),
613
  ("test_delay", MULTI, None, _TestDelayTimeout, [
Michael Hanselmann's avatar
Michael Hanselmann committed
614
    ("duration", None, None),
615
    ], None, None, "Sleep for a fixed time on given node(s)"),
616
  ("hypervisor_validate_params", MULTI, None, constants.RPC_TMO_NORMAL, [
617 618
    ("hvname", None, "Hypervisor name"),
    ("hvfull", None, "Parameters to be validated"),
619
    ], None, None, "Validate hypervisor params"),
620 621
  ("get_watcher_pause", SINGLE, None, constants.RPC_TMO_URGENT, [],
    None, None, "Get watcher pause end"),
622 623 624
  ("set_watcher_pause", MULTI, None, constants.RPC_TMO_URGENT, [
    ("until", None, None),
    ], None, None, "Set watcher pause end"),
Hrvoje Ribicic's avatar
Hrvoje Ribicic committed
625 626 627
  ("get_file_info", SINGLE, None, constants.RPC_TMO_FAST, [
    ("file_path", None, None),
    ], None, None, "Checks if a file exists and reports on it"),
Michael Hanselmann's avatar
Michael Hanselmann committed
628 629
  ]

630
CALLS = {
Iustin Pop's avatar
Iustin Pop committed
631
  "RpcClientDefault":
632 633
    _Prepare(_IMPEXP_CALLS + _X509_CALLS + _OS_CALLS + _NODE_CALLS +
             _FILE_STORAGE_CALLS + _MISC_CALLS + _INSTANCE_CALLS +
634
             _BLOCKDEV_CALLS + _STORAGE_CALLS + _EXTSTORAGE_CALLS),
635
  "RpcClientJobQueue": _Prepare([
636
    ("jobqueue_update", MULTI, None, constants.RPC_TMO_URGENT, [
637
      ("file_name", None, None),
638
      ("content", ED_COMPRESS, None),
639
      ], None, None, "Update job queue file"),
640
    ("jobqueue_purge", SINGLE, None, constants.RPC_TMO_NORMAL, [], None, None,
641
     "Purge job queue"),
642
    ("jobqueue_rename", MULTI, None, constants.RPC_TMO_URGENT, [
643
      ("rename", None, None),
644
      ], None, None, "Rename job queue file"),
645 646 647
    ("jobqueue_set_drain_flag", MULTI, None, constants.RPC_TMO_URGENT, [
      ("flag", None, None),
      ], None, None, "Set job queue drain flag"),
648 649
    ]),
  "RpcClientBootstrap": _Prepare([
650
    ("node_start_master_daemons", SINGLE, None, constants.RPC_TMO_FAST, [
651
      ("no_voting", None, None),
652
      ], None, None, "Starts master daemons on a node"),
653
    ("node_activate_master_ip", SINGLE, None, constants.RPC_TMO_FAST, [
654
      ("master_params", ED_OBJECT_DICT, "Network parameters of the master"),
655 656
      ("use_external_mip_script", None,
       "Whether to use the user-provided master IP address setup script"),
657
      ], None, None,
658
      "Activates master IP on a node"),
659
    ("node_stop_master", SINGLE, None, constants.RPC_TMO_FAST, [], None, None,
660
     "Deactivates master IP and stops master daemons on a node"),
661
    ("node_deactivate_master_ip", SINGLE, None, constants.RPC_TMO_FAST, [
662
      ("master_params", ED_OBJECT_DICT, "Network parameters of the master"),
663 664
      ("use_external_mip_script", None,
       "Whether to use the user-provided master IP address setup script"),
665
      ], None, None,
666
     "Deactivates master IP on a node"),
667
    ("node_change_master_netmask", SINGLE, None, constants.RPC_TMO_FAST, [
668 669 670 671
      ("old_netmask", None, "The old value of the netmask"),
      ("netmask", None, "The new value of the netmask"),
      ("master_ip", None, "The master IP"),
      ("master_netdev", None, "The master network device"),
672
      ], None, None, "Change master IP netmask"),
673
    ("node_leave_cluster", SINGLE, None, constants.RPC_TMO_NORMAL, [
674
      ("modify_ssh_setup", None, None),
675 676
      ], None, None,
     "Requests a node to clean the cluster information it has"),
Jose A. Lopes's avatar
Jose A. Lopes committed
677 678
    ("master_node_name", MULTI, None, constants.RPC_TMO_URGENT, [], None, None,
     "Returns the master node name"),
679 680
    ]),
  "RpcClientDnsOnly": _Prepare([
681 682
    ("version", MULTI, ACCEPT_OFFLINE_NODE, constants.RPC_TMO_URGENT, [], None,
     None, "Query node version"),
683
    ("node_verify_light", MULTI, None, constants.RPC_TMO_NORMAL, [
684 685 686
      ("checkdict", None, "What to verify"),
      ("cluster_name", None, "Cluster name"),
      ("hvparams", None, "Dictionary mapping hypervisor names to hvparams"),
687 688 689
      ("node_groups", None, "node names mapped to their group uuids"),
      ("groups_cfg", None,
       "a dictionary mapping group uuids to their configuration"),
690
      ], None, None, "Request verification of given parameters"),
691 692
    ]),
  "RpcClientConfig": _Prepare([
693
    ("upload_file", MULTI, None, constants.RPC_TMO_NORMAL, [
694
      ("file_name", ED_FILE_DETAILS, None),
695 696 697 698 699 700 701 702 703 704
      ], None, None, "Upload files"),
    ("upload_file_single", MULTI, None, constants.RPC_TMO_NORMAL, [
      ("file_name", None, "The name of the file"),
      ("content", ED_COMPRESS, "The data to be uploaded"),
      ("mode", None, "The mode of the file or None"),
      ("uid", None, "The owner of the file"),
      ("gid", None, "The group of the file"),
      ("atime", None, "The file's last access time"),
      ("mtime", None, "The file's last modification time"),
      ], None, None, "Upload files"),
705
    ("write_ssconf_files", MULTI, None, constants.RPC_TMO_NORMAL, [
706
      ("values", None, None),
707
      ], None, None, "Write ssconf files"),
708
    ]),
709
  }