[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[virt-tools-list] [PATCH] Drop user back to 'open conn' dialog if connecting fails



In case of connection failure, the user can either maintain the connection
or re-edit it.

Split up `add_connection_to_ui' into `make_conn' and `register_conn'
to handle separately the object creation and its registration in the
list of connections (ui and conf).

Solves: https://bugzilla.redhat.com/show_bug.cgi?id=617386
Signed-off-by: Giuseppe Scrivano <gscrivano gnu org>
---
 virtManager/connect.py | 43 ++++++++++++++++++++++++++++++++-
 virtManager/engine.py  | 64 ++++++++++++++++++++++++++++++++++++--------------
 2 files changed, 88 insertions(+), 19 deletions(-)

diff --git a/virtManager/connect.py b/virtManager/connect.py
index 3aed22f..3b50efd 100644
--- a/virtManager/connect.py
+++ b/virtManager/connect.py
@@ -111,9 +111,11 @@ class vmmConnect(vmmGObjectUI):
         self.topwin.hide()
         self.stop_browse()
 
-    def show(self, parent):
+    def show(self, parent, initial_state=None):
         logging.debug("Showing open connection")
         self.reset_state()
+        if initial_state:
+            self.set_state(initial_state)
         self.topwin.set_transient_for(parent)
         self.topwin.present()
 
@@ -314,6 +316,45 @@ class vmmConnect(vmmGObjectUI):
         default_user = default_conn_user(conn)
         self.widget("username-entry").set_text(default_user)
 
+    def set_state(self, state):
+        hv = None
+        if state.is_xen():
+            hv = HV_XEN
+        elif state.is_qemu():
+            hv = HV_QEMU
+        elif state.is_lxc():
+            hv = HV_LXC
+        is_remote = bool(state.is_remote())
+        host = state.get_uri_hostname()
+        autoconnect = state.get_autoconnect()
+        connection = None
+        transport = state.get_transport()
+        user = transport[1]
+        if transport[0]:
+            if "tls" in transport[0]:
+                connection = CONN_TLS
+            elif "ssh" in transport[0]:
+                connection = CONN_SSH
+            elif "tcp" in transport[0]:
+                connection = CONN_TCP
+
+        self.widget("connection").set_sensitive(is_remote)
+        if connection:
+            self.widget("connection").set_active(connection)
+        self.widget("connect-remote").set_active(is_remote)
+        self.widget("username-entry").set_sensitive(is_remote)
+        self.widget("hostname").set_sensitive(is_remote)
+        if is_remote:
+            self.widget("hostname").get_child().set_text(host)
+        if(hv is not None):
+            self.widget("hypervisor").set_active(hv)
+        if (user):
+            self.widget("username-entry").set_text(user)
+
+        self.widget("autoconnect").set_sensitive(True)
+        self.widget("autoconnect").set_active(autoconnect)
+
+
     def generate_uri(self):
         hv = self.widget("hypervisor").get_active()
         conn = self.widget("connection").get_active()
diff --git a/virtManager/engine.py b/virtManager/engine.py
index 456f597..2c089b9 100644
--- a/virtManager/engine.py
+++ b/virtManager/engine.py
@@ -136,7 +136,8 @@ class vmmEngine(vmmGObject):
         self.application.add_window(self._appwindow)
 
         if self.uri_at_startup:
-            conn = self.add_conn_to_ui(self.uri_at_startup)
+            conn = self.make_conn(self.uri_at_startup)
+            self.register_conn(conn, skip_config=True)
             if conn and self.uri_cb:
                 conn.connect_opt_out("resources-sampled", self.uri_cb)
 
@@ -222,7 +223,8 @@ class vmmEngine(vmmGObject):
             return
         logging.debug("About to connect to uris %s", uris)
         for uri in uris:
-            self.add_conn_to_ui(uri)
+            conn = self.make_conn(uri)
+            self.register_conn(conn, skip_config=True)
 
     def autostart_conns(self):
         for uri in self.conns:
@@ -439,8 +441,7 @@ class vmmEngine(vmmGObject):
         return
 
 
-    def add_conn_to_ui(self, uri):
-        # Public method called from virt-manager.py
+    def make_conn(self, uri, probe=False):
         conn = self._check_conn(uri)
         if conn:
             return conn
@@ -451,23 +452,30 @@ class vmmEngine(vmmGObject):
             "windowHost": None,
             "windowDetails": {},
             "windowClone": None,
+            "probeConnection": probe
         }
 
         conn.connect("vm-removed", self._do_vm_removed)
         conn.connect("state-changed", self._do_conn_changed)
         conn.connect("connect-error", self._connect_error)
         conn.connect("priority-tick", self._schedule_priority_tick)
-        self.emit("conn-added", conn)
 
         return conn
 
 
-    def connect_to_uri(self, uri, autoconnect=None, do_start=True):
-        try:
-            conn = self.add_conn_to_ui(uri)
+    def register_conn(self, conn, skip_config=False):
+        # if `skip_config' then the connection is only showed in the ui and
+        # not added to the config.
+        if not skip_config and conn.get_uri() not in \
+                               (self.config.get_conn_uris() or []):
+            self.config.add_conn(conn.get_uri())
+        self.emit("conn-added", conn)
 
-            if conn.get_uri() not in (self.config.get_conn_uris() or []):
-                self.config.add_conn(conn.get_uri())
+
+    def connect_to_uri(self, uri, autoconnect=None, do_start=True, probe=False):
+        try:
+            conn = self.make_conn(uri, probe=probe)
+            self.register_conn(conn)
 
             if autoconnect is not None:
                 conn.set_autoconnect(bool(autoconnect))
@@ -573,7 +581,9 @@ class vmmEngine(vmmGObject):
                 hint += _("Verify that the 'libvirtd' daemon is running.")
                 show_errmsg = False
 
+        probe_connection = self.conns[conn.get_uri()]["probeConnection"]
         msg = _("Unable to connect to libvirt.")
+
         if show_errmsg:
             msg += "\n\n%s" % errmsg
         if hint:
@@ -585,13 +595,24 @@ class vmmEngine(vmmGObject):
         details += "Libvirt URI is: %s\n\n" % conn.get_uri()
         details += tb
 
-        title = _("Virtual Machine Manager Connection Failure")
+        if probe_connection:
+            msg += "\n\n%s" % _("Would you still like to remember this connection?")
 
-        if self._can_exit():
-            self.err.show_err(msg, details, title, async=False)
-            self.idle_add(self.exit_app, conn)
+        title = _("Virtual Machine Manager Connection Failure")
+        if probe_connection:
+            remember_connection = self.err.show_err(msg, details, title,
+                    buttons=Gtk.ButtonsType.YES_NO,
+                    dialog_type=Gtk.MessageType.QUESTION, async=False)
+            if remember_connection:
+                self.conns[conn.get_uri()]["probeConnection"] = False
+            else:
+                self.idle_add(self._do_edit_connect, self.windowManager, conn)
         else:
-            self.err.show_err(msg, details, title)
+            if self._can_exit():
+                self.err.show_err(msg, details, title, async=False)
+                self.idle_add(self.exit_app, conn)
+            else:
+                self.err.show_err(msg, details, title)
 
     ####################
     # Dialog launchers #
@@ -648,7 +669,7 @@ class vmmEngine(vmmGObject):
 
         def completed(src, uri, autoconnect):
             ignore = src
-            return self.connect_to_uri(uri, autoconnect)
+            return self.connect_to_uri(uri, autoconnect, probe=True)
 
         def cancelled(src):
             if len(self.conns.keys()) == 0:
@@ -661,12 +682,19 @@ class vmmEngine(vmmGObject):
         return self.windowConnect
 
 
-    def _do_show_connect(self, src):
+    def _do_show_connect(self, src, initial_state=None):
         try:
-            self._get_connect_dialog().show(src.topwin)
+            self._get_connect_dialog().show(src.topwin, initial_state)
         except Exception, e:
             src.err.show_err(_("Error launching connect dialog: %s") % str(e))
 
+    def _do_edit_connect(self, src, connection):
+        try:
+            self._do_show_connect(src, initial_state=connection)
+        finally:
+            self.remove_conn(None, connection.get_uri())
+
+
     def _get_details_dialog(self, uri, uuid):
         if uuid in self.conns[uri]["windowDetails"]:
             return self.conns[uri]["windowDetails"][uuid]
-- 
1.8.3.1


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]