c2ca854
commit 54d007b2875a887b1579604e45b122dde286b9be
c2ca854
Author: Cole Robinson <crobinso@redhat.com>
c2ca854
Date:   Thu Feb 2 16:45:18 2012 -0500
c2ca854
c2ca854
    manager: Fix error reporting when can't connect remotely
c2ca854
    
c2ca854
    Also rejigger the error building again to be more useful and
c2ca854
    less scary in cases where we are pretty confident we know what the
c2ca854
    problem is.
c2ca854
c2ca854
diff --git a/src/virtManager/manager.py b/src/virtManager/manager.py
c2ca854
index 2e8a679..a4b2df5 100644
c2ca854
--- a/src/virtManager/manager.py
c2ca854
+++ b/src/virtManager/manager.py
c2ca854
@@ -646,42 +646,55 @@ class vmmManager(vmmGObjectUI):
c2ca854
             conn.open()
c2ca854
             return True
c2ca854
 
c2ca854
-    def _connect_error(self, conn, shortmsg, tb, warnconsole):
c2ca854
-        shortmsg = shortmsg.strip(" \n")
c2ca854
+    def _connect_error(self, conn, errmsg, tb, warnconsole):
c2ca854
+        errmsg = errmsg.strip(" \n")
c2ca854
         tb = tb.strip(" \n")
c2ca854
-        msg = _("Unable to connect to libvirt:\n\n%s\n\n") % shortmsg
c2ca854
+        hint = ""
c2ca854
+        show_errmsg = True
c2ca854
+
c2ca854
+        if conn.is_remote():
c2ca854
+            logging.debug(conn.get_transport())
c2ca854
+            if re.search(r"nc: .* -- 'U'", tb):
c2ca854
+                hint += _("The remote host requires a version of netcat/nc\n"
c2ca854
+                          "which supports the -U option.")
c2ca854
+                show_errmsg = False
c2ca854
+            elif conn.get_transport()[0] == "ssh" and re.search(r"ssh-askpass", tb):
c2ca854
+                hint += _("You need to install openssh-askpass or similar\n"
c2ca854
+                          "to connect to this host.")
c2ca854
+                show_errmsg = False
c2ca854
+            else:
c2ca854
+                hint += _("Verify that the 'libvirtd' daemon is running\n"
c2ca854
+                          "on the remote host.")
c2ca854
 
c2ca854
-        if conn.is_xen() and not conn.is_remote():
c2ca854
-            msg += _("Verify that:\n"
c2ca854
-                     " - A Xen host kernel was booted\n"
c2ca854
-                     " - The Xen service has been started\n")
c2ca854
-            msg = msg.strip("\n")
c2ca854
-            details = "%s\n\n%s" % (msg, tb)
c2ca854
+        elif conn.is_xen():
c2ca854
+            hint += _("Verify that:\n"
c2ca854
+                      " - A Xen host kernel was booted\n"
c2ca854
+                      " - The Xen service has been started")
c2ca854
 
c2ca854
         else:
c2ca854
-            hints = []
c2ca854
-            if conn.is_remote() and re.search(r"nc: .* -- 'U'", details):
c2ca854
-                hints.append(
c2ca854
-                    _("\n - The remote netcat understands the '-U' option"))
c2ca854
-
c2ca854
             if warnconsole:
c2ca854
-                msg += _("Could not detect a local session: if you are \n"
c2ca854
-                         "running virt-manager over ssh -X or VNC, you \n"
c2ca854
-                         "may not be able to connect to libvirt as a \n"
c2ca854
-                         "regular user. Try running as root.\n\n")
c2ca854
-            else:
c2ca854
-                msg += _("Verify that:\n" +
c2ca854
-                         " - The 'libvirtd' daemon has been started")
c2ca854
-                for hint in hints:
c2ca854
-                    msg += hint
c2ca854
-
c2ca854
-            msg = msg.strip("\n")
c2ca854
-            details = (("%s\n\n" % msg) +
c2ca854
-                       (_("Libvirt URI is: %s\n\n") % conn.get_uri()) +
c2ca854
-                       tb)
c2ca854
-
c2ca854
-        self.err.show_err(msg, details,
c2ca854
-                    title=_("Virtual Machine Manager Connection Failure"))
c2ca854
+                hint += _("Could not detect a local session: if you are \n"
c2ca854
+                          "running virt-manager over ssh -X or VNC, you \n"
c2ca854
+                          "may not be able to connect to libvirt as a \n"
c2ca854
+                          "regular user. Try running as root.")
c2ca854
+                show_errmsg = False
c2ca854
+            elif re.search(r"libvirt-sock", tb):
c2ca854
+                hint += _("Verify that the 'libvirtd' daemon is running.")
c2ca854
+                show_errmsg = False
c2ca854
+
c2ca854
+        msg = _("Unable to connect to libvirt.")
c2ca854
+        if show_errmsg:
c2ca854
+            msg += "\n\n%s" % errmsg
c2ca854
+        if hint:
c2ca854
+            msg += "\n\n%s" % hint
c2ca854
+
c2ca854
+        msg = msg.strip("\n")
c2ca854
+        details = msg
c2ca854
+        details += "\n\n"
c2ca854
+        details += "Libvirt URI is: %s\n\n" % conn.get_uri()
c2ca854
+        details += tb
c2ca854
+
c2ca854
+        self.err.show_err(msg, details, title=_("Virtual Machine Manager Connection Failure"))
c2ca854
 
c2ca854
 
c2ca854
     ####################################