Revision ed83f5cc lib/rpc.py
b/lib/rpc.py | ||
---|---|---|
81 | 81 |
calls we can't raise an exception just because one one out of many |
82 | 82 |
failed, and therefore we use this class to encapsulate the result. |
83 | 83 |
|
84 |
@ivar data: the data payload, for successfull results, or None |
|
85 |
@type failed: boolean |
|
86 |
@ivar failed: whether the operation failed at RPC level (not |
|
87 |
application level on the remote node) |
|
88 |
@ivar call: the name of the RPC call |
|
89 |
@ivar node: the name of the node to which we made the call |
|
90 |
@ivar offline: whether the operation failed because the node was |
|
91 |
offline, as opposed to actual failure; offline=True will always |
|
92 |
imply failed=True, in order to allow simpler checking if |
|
93 |
the user doesn't care about the exact failure mode |
|
94 |
|
|
84 | 95 |
""" |
85 |
def __init__(self, data, failed=False, call=None, node=None): |
|
96 |
def __init__(self, data=None, failed=False, offline=False, |
|
97 |
call=None, node=None): |
|
86 | 98 |
self.failed = failed |
87 |
self.call = None |
|
88 |
self.node = None |
|
89 |
if failed: |
|
99 |
self.offline = offline |
|
100 |
self.call = call |
|
101 |
self.node = node |
|
102 |
if offline: |
|
103 |
self.failed = True |
|
104 |
self.error = "Node is marked offline" |
|
105 |
self.data = None |
|
106 |
elif failed: |
|
90 | 107 |
self.error = data |
91 | 108 |
self.data = None |
92 | 109 |
else: |
... | ... | |
239 | 256 |
|
240 | 257 |
""" |
241 | 258 |
all_nodes = self._cfg.GetAllNodesInfo() |
259 |
name_list = [] |
|
242 | 260 |
addr_list = [] |
261 |
skip_dict = {} |
|
243 | 262 |
for node in node_list: |
244 | 263 |
if node in all_nodes: |
264 |
if all_nodes[node].offline: |
|
265 |
skip_dict[node] = RpcResult(node=node, offline=True) |
|
266 |
continue |
|
245 | 267 |
val = all_nodes[node].primary_ip |
246 | 268 |
else: |
247 | 269 |
val = None |
248 | 270 |
addr_list.append(val) |
249 |
client.ConnectList(node_list, address_list=addr_list) |
|
271 |
name_list.append(node) |
|
272 |
if name_list: |
|
273 |
client.ConnectList(name_list, address_list=addr_list) |
|
274 |
return skip_dict |
|
250 | 275 |
|
251 | 276 |
def _ConnectNode(self, client, node): |
252 | 277 |
"""Helper for computing one node's address. |
... | ... | |
259 | 284 |
""" |
260 | 285 |
node_info = self._cfg.GetNodeInfo(node) |
261 | 286 |
if node_info is not None: |
287 |
if node_info.offline: |
|
288 |
return RpcResult(node=node, offline=True) |
|
262 | 289 |
addr = node_info.primary_ip |
263 | 290 |
else: |
264 | 291 |
addr = None |
265 | 292 |
client.ConnectNode(node, address=addr) |
266 | 293 |
|
267 |
def _MultiNodeCall(self, node_list, procedure, args, |
|
268 |
address_list=None): |
|
294 |
def _MultiNodeCall(self, node_list, procedure, args): |
|
269 | 295 |
"""Helper for making a multi-node call |
270 | 296 |
|
271 | 297 |
""" |
272 | 298 |
body = serializer.DumpJson(args, indent=False) |
273 | 299 |
c = Client(procedure, body, self.port) |
274 |
if address_list is None: |
|
275 |
self._ConnectList(c, node_list) |
|
276 |
else: |
|
277 |
c.ConnectList(node_list, address_list=address_list) |
|
278 |
return c.GetResults() |
|
300 |
skip_dict = self._ConnectList(c, node_list) |
|
301 |
skip_dict.update(c.GetResults()) |
|
302 |
return skip_dict |
|
279 | 303 |
|
280 | 304 |
@classmethod |
281 | 305 |
def _StaticMultiNodeCall(cls, node_list, procedure, args, |
... | ... | |
294 | 318 |
""" |
295 | 319 |
body = serializer.DumpJson(args, indent=False) |
296 | 320 |
c = Client(procedure, body, self.port) |
297 |
self._ConnectNode(c, node) |
|
298 |
return c.GetResults().get(node, False) |
|
321 |
result = self._ConnectNode(c, node) |
|
322 |
if result is None: |
|
323 |
# we did connect, node is not offline |
|
324 |
result = c.GetResults()[node] |
|
325 |
return result |
|
299 | 326 |
|
300 | 327 |
@classmethod |
301 | 328 |
def _StaticSingleNodeCall(cls, node, procedure, args): |
... | ... | |
305 | 332 |
body = serializer.DumpJson(args, indent=False) |
306 | 333 |
c = Client(procedure, body, utils.GetNodeDaemonPort()) |
307 | 334 |
c.ConnectNode(node) |
308 |
return c.GetResults().get(node, False)
|
|
335 |
return c.GetResults()[node]
|
|
309 | 336 |
|
310 | 337 |
# |
311 | 338 |
# Begin RPC calls |
Also available in: Unified diff