+class RpcResult(object):
+ """RPC Result class.
+
+ This class holds an RPC result. It is needed since in multi-node
+ calls we can't raise an exception just because one one out of many
+ failed, and therefore we use this class to encapsulate the result.
+
+ @ivar data: the data payload, for successfull results, or None
+ @type failed: boolean
+ @ivar failed: whether the operation failed at RPC level (not
+ application level on the remote node)
+ @ivar call: the name of the RPC call
+ @ivar node: the name of the node to which we made the call
+ @ivar offline: whether the operation failed because the node was
+ offline, as opposed to actual failure; offline=True will always
+ imply failed=True, in order to allow simpler checking if
+ the user doesn't care about the exact failure mode
+
+ """
+ def __init__(self, data=None, failed=False, offline=False,
+ call=None, node=None):
+ self.failed = failed
+ self.offline = offline
+ self.call = call
+ self.node = node
+ if offline:
+ self.failed = True
+ self.error = "Node is marked offline"
+ self.data = None
+ elif failed:
+ self.error = data
+ self.data = None
+ else:
+ self.data = data
+ self.error = None
+
+ def Raise(self):
+ """If the result has failed, raise an OpExecError.
+
+ This is used so that LU code doesn't have to check for each
+ result, but instead can call this function.
+
+ """
+ if self.failed:
+ raise errors.OpExecError("Call '%s' to node '%s' has failed: %s" %
+ (self.call, self.node, self.error))
+
+