Revision 26d502d0

b/autotools/build-rpc
117 117
    sw.Write("_CALLS = rpc_defs.CALLS[%r]", clsname)
118 118
    sw.Write("")
119 119

  
120
    for (name, kind, timeout, args, postproc, desc) in calls:
120
    for (name, kind, timeout, args, _, desc) in calls:
121 121
      funcargs = ["self"]
122 122

  
123 123
      if kind == _SINGLE:
......
148 148
        # In case line gets too long and is wrapped in a bad spot
149 149
        buf.write("( ")
150 150

  
151
        if postproc:
152
          buf.write("%s(" % postproc)
153 151
        buf.write("self._Call(_def, ")
154 152
        if kind == _SINGLE:
155 153
          buf.write("[node]")
......
162 160

  
163 161
        if kind == _SINGLE:
164 162
          buf.write("[node]")
165
        if postproc:
166
          buf.write(")")
167 163
        buf.write(")")
168 164

  
169 165
        for line in _WrapCode(buf.getvalue()):
b/lib/rpc.py
434 434
    """Entry point for automatically generated RPC wrappers.
435 435

  
436 436
    """
437
    (procedure, _, _, argdefs, _, _) = cdef
437
    (procedure, _, _, argdefs, postproc_fn, _) = cdef
438 438

  
439 439
    body = serializer.DumpJson(map(self._encoder,
440 440
                                   zip(map(compat.snd, argdefs), args)),
441 441
                               indent=False)
442 442

  
443
    return self._proc(node_list, procedure, body, read_timeout=timeout)
443
    result = self._proc(node_list, procedure, body, read_timeout=timeout)
444

  
445
    if postproc_fn:
446
      return postproc_fn(result)
447
    else:
448
      return result
444 449

  
445 450

  
446 451
def _ObjectToDict(value):
......
615 620
    """
616 621
    return self._InstDict(instance, osp=osparams)
617 622

  
618
  @staticmethod
619
  def _MigrationStatusPostProc(result):
620
    if not result.fail_msg and result.payload is not None:
621
      result.payload = objects.MigrationStatus.FromDict(result.payload)
622
    return result
623

  
624
  @staticmethod
625
  def _BlockdevFindPostProc(result):
626
    if not result.fail_msg and result.payload is not None:
627
      result.payload = objects.BlockDevStatus.FromDict(result.payload)
628
    return result
629

  
630
  @staticmethod
631
  def _BlockdevGetMirrorStatusPostProc(result):
632
    if not result.fail_msg:
633
      result.payload = [objects.BlockDevStatus.FromDict(i)
634
                        for i in result.payload]
635
    return result
636

  
637
  @staticmethod
638
  def _BlockdevGetMirrorStatusMultiPostProc(result):
639
    for nres in result.values():
640
      if nres.fail_msg:
641
        continue
642

  
643
      for idx, (success, status) in enumerate(nres.payload):
644
        if success:
645
          nres.payload[idx] = (success, objects.BlockDevStatus.FromDict(status))
646

  
647
    return result
648

  
649
  @staticmethod
650
  def _OsGetPostProc(result):
651
    if not result.fail_msg and isinstance(result.payload, dict):
652
      result.payload = objects.OS.FromDict(result.payload)
653
    return result
654

  
655
  @staticmethod
656
  def _ImpExpStatusPostProc(result):
657
    """Post-processor for import/export status.
658

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

  
663
    """
664
    if not result.fail_msg:
665
      decoded = []
666

  
667
      for i in result.payload:
668
        if i is None:
669
          decoded.append(None)
670
          continue
671
        decoded.append(objects.ImportExportStatus.FromDict(i))
672

  
673
      result.payload = decoded
674

  
675
    return result
676

  
677 623
  #
678 624
  # Begin RPC calls
679 625
  #
b/lib/rpc_defs.py
37 37
"""
38 38

  
39 39
from ganeti import utils
40
from ganeti import objects
40 41

  
41 42

  
42 43
# Guidelines for choosing timeouts:
......
75 76
  return utils.SequenceToDict(calls)
76 77

  
77 78

  
79
def _MigrationStatusPostProc(result):
80
  """Post-processor for L{rpc.RpcRunner.call_instance_get_migration_status}.
81

  
82
  """
83
  if not result.fail_msg and result.payload is not None:
84
    result.payload = objects.MigrationStatus.FromDict(result.payload)
85
  return result
86

  
87

  
88
def _BlockdevFindPostProc(result):
89
  """Post-processor for L{rpc.RpcRunner.call_blockdev_find}.
90

  
91
  """
92
  if not result.fail_msg and result.payload is not None:
93
    result.payload = objects.BlockDevStatus.FromDict(result.payload)
94
  return result
95

  
96

  
97
def _BlockdevGetMirrorStatusPostProc(result):
98
  """Post-processor for L{rpc.RpcRunner.call_blockdev_getmirrorstatus}.
99

  
100
  """
101
  if not result.fail_msg:
102
    result.payload = map(objects.BlockDevStatus.FromDict, result.payload)
103
  return result
104

  
105

  
106
def _BlockdevGetMirrorStatusMultiPostProc(result):
107
  """Post-processor for L{rpc.RpcRunner.call_blockdev_getmirrorstatus_multi}.
108

  
109
  """
110
  for nres in result.values():
111
    if nres.fail_msg:
112
      continue
113

  
114
    for idx, (success, status) in enumerate(nres.payload):
115
      if success:
116
        nres.payload[idx] = (success, objects.BlockDevStatus.FromDict(status))
117

  
118
  return result
119

  
120

  
121
def _OsGetPostProc(result):
122
  """Post-processor for L{rpc.RpcRunner.call_os_get}.
123

  
124
  """
125
  if not result.fail_msg and isinstance(result.payload, dict):
126
    result.payload = objects.OS.FromDict(result.payload)
127
  return result
128

  
129

  
130
def _ImpExpStatusPostProc(result):
131
  """Post-processor for import/export status.
132

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

  
137
  """
138
  if not result.fail_msg:
139
    decoded = []
140

  
141
    for i in result.payload:
142
      if i is None:
143
        decoded.append(None)
144
        continue
145
      decoded.append(objects.ImportExportStatus.FromDict(i))
146

  
147
    result.payload = decoded
148

  
149
  return result
150

  
151

  
78 152
_FILE_STORAGE_CALLS = [
79 153
  ("file_storage_dir_create", SINGLE, TMO_FAST, [
80 154
    ("file_storage_dir", None, "File storage directory"),
......
163 237
    ], None, "Finalize the instance migration on the source node"),
164 238
  ("instance_get_migration_status", SINGLE, TMO_SLOW, [
165 239
    ("instance", ED_INST_DICT, "Instance object"),
166
    ], "self._MigrationStatusPostProc", "Report migration status"),
240
    ], _MigrationStatusPostProc, "Report migration status"),
167 241
  ("instance_start", SINGLE, TMO_NORMAL, [
168 242
    ("instance_hvp_bep", ED_INST_DICT_HVP_BEP, None),
169 243
    ("startup_paused", None, None),
......
192 266
    ], None, "Starts an export daemon"),
193 267
  ("impexp_status", SINGLE, TMO_FAST, [
194 268
    ("names", None, "Import/export names"),
195
    ], "self._ImpExpStatusPostProc", "Gets the status of an import or export"),
269
    ], _ImpExpStatusPostProc, "Gets the status of an import or export"),
196 270
  ("impexp_abort", SINGLE, TMO_NORMAL, [
197 271
    ("name", None, "Import/export name"),
198 272
    ], None, "Aborts an import or export"),
......
302 376
    ], None, "Request rename of the given block devices"),
303 377
  ("blockdev_find", SINGLE, TMO_NORMAL, [
304 378
    ("disk", ED_OBJECT_DICT, None),
305
    ], "self._BlockdevFindPostProc",
379
    ], _BlockdevFindPostProc,
306 380
    "Request identification of a given block device"),
307 381
  ("blockdev_getmirrorstatus", SINGLE, TMO_NORMAL, [
308 382
    ("disks", ED_OBJECT_DICT_LIST, None),
309
    ], "self._BlockdevGetMirrorStatusPostProc",
383
    ], _BlockdevGetMirrorStatusPostProc,
310 384
    "Request status of a (mirroring) device"),
311 385
  ("blockdev_getmirrorstatus_multi", MULTI, TMO_NORMAL, [
312 386
    ("node_disks", ED_NODE_TO_DISK_DICT, None),
313
    ], "self._BlockdevGetMirrorStatusMultiPostProc",
387
    ], _BlockdevGetMirrorStatusMultiPostProc,
314 388
    "Request status of (mirroring) devices from multiple nodes"),
315 389
  ]
316 390

  
......
325 399
    ], None, "Run a validation routine for a given OS"),
326 400
  ("os_get", SINGLE, TMO_FAST, [
327 401
    ("name", None, None),
328
    ], "self._OsGetPostProc", "Returns an OS definition"),
402
    ], _OsGetPostProc, "Returns an OS definition"),
329 403
  ]
330 404

  
331 405
_NODE_CALLS = [

Also available in: Unified diff