+class RPCFail(Exception):
+ """Class denoting RPC failure.
+
+ Its argument is the error message.
+
+ """
+
+def _Fail(msg, *args, **kwargs):
+ """Log an error and the raise an RPCFail exception.
+
+ This exception is then handled specially in the ganeti daemon and
+ turned into a 'failed' return type. As such, this function is a
+ useful shortcut for logging the error and returning it to the master
+ daemon.
+
+ @type msg: string
+ @param msg: the text of the exception
+ @raise RPCFail
+
+ """
+ if args:
+ msg = msg % args
+ if "exc" in kwargs and kwargs["exc"]:
+ logging.exception(msg)
+ else:
+ logging.error(msg)
+ raise RPCFail(msg)
+
+