diff --git a/lib/cli.py b/lib/cli.py index 917b3458c630b5ad95fecda607d64354e5ee75db..167f28cb862f1247990e0519ab70fb5666e39b22 100644 --- a/lib/cli.py +++ b/lib/cli.py @@ -466,6 +466,15 @@ def FormatError(err): obuf.write("Failure: invalid tag(s) given:\n%s" % msg) elif isinstance(err, errors.GenericError): obuf.write("Unhandled Ganeti error: %s" % msg) + elif isinstance(err, luxi.NoMasterError): + obuf.write("Cannot communicate with the master daemon.\nIs it running" + " and listening on '%s'?" % err.args[0]) + elif isinstance(err, luxi.TimeoutError): + obuf.write("Timeout while talking to the master daemon. Error:\n" + "%s" % msg) + elif isinstance(err, luxi.ProtocolError): + obuf.write("Unhandled protocol error while talking to the master daemon:\n" + "%s" % msg) else: obuf.write("Unhandled exception: %s" % msg) return retcode, obuf.getvalue().rstrip('\n') @@ -517,7 +526,7 @@ def GenericMain(commands, override=None, aliases=None): try: result = func(options, args) - except errors.GenericError, err: + except (errors.GenericError, luxi.ProtocolError), err: result, err_msg = FormatError(err) logger.ToStderr(err_msg) diff --git a/lib/luxi.py b/lib/luxi.py index df9ed89a39d0c5baba1473bda2a9d7b752b1e7bc..993907d496cb2de5f96c16d0cb3a1837c9411570 100644 --- a/lib/luxi.py +++ b/lib/luxi.py @@ -33,6 +33,7 @@ import socket import collections import simplejson import time +import errno from ganeti import opcodes from ganeti import constants @@ -80,6 +81,14 @@ class RequestError(ProtocolError): """ +class NoMasterError(ProtocolError): + """The master cannot be reached + + This means that the master daemon is not running or the socket has + been removed. + + """ + def SerializeJob(job): """Convert a job description to a string format. @@ -153,9 +162,13 @@ class Transport: try: self.socket.connect(address) except socket.timeout, err: - raise TimeoutError("Connection timed out: %s" % str(err)) + raise TimeoutError("Connect timed out: %s" % str(err)) + except socket.error, err: + if err.args[0] == errno.ENOENT: + raise NoMasterError((address,)) + raise self.socket.settimeout(self._rwtimeout) - except socket.error: + except (socket.error, NoMasterError): if self.socket is not None: self.socket.close() self.socket = None