From fc171fc31db1f58126225c034435d6d3c390e616 Mon Sep 17 00:00:00 2001 From: Cole Robinson Date: Sat, 11 Apr 2015 12:08:57 -0400 Subject: [PATCH] connection: Bunch of minor tweaks handling TCP URIs --- virtManager/connectauth.py | 18 +++++++++++------- virtManager/connection.py | 11 +++++++---- virtManager/console.py | 2 +- virtManager/engine.py | 4 ++-- virtManager/sshtunnels.py | 7 ++++--- virtinst/connection.py | 12 +++++------- 6 files changed, 30 insertions(+), 24 deletions(-) diff --git a/virtManager/connectauth.py b/virtManager/connectauth.py index e56726c9..03cd0678 100644 --- a/virtManager/connectauth.py +++ b/virtManager/connectauth.py @@ -52,22 +52,22 @@ def do_we_have_session(): return False -def creds_dialog(creds): +def creds_dialog(conn, creds): """ Thread safe wrapper for libvirt openAuth user/pass callback """ retipc = [] - def wrapper(fn, creds): + def wrapper(fn, conn, creds): try: - ret = fn(creds) + ret = fn(conn, creds) except: logging.exception("Error from creds dialog") ret = -1 retipc.append(ret) - GLib.idle_add(wrapper, creds_dialog_main, creds) + GLib.idle_add(wrapper, _creds_dialog_main, conn, creds) while not retipc: time.sleep(.1) @@ -75,7 +75,7 @@ def creds_dialog(creds): return retipc[0] -def creds_dialog_main(creds): +def _creds_dialog_main(conn, creds): """ Libvirt openAuth callback for username/password credentials """ @@ -118,11 +118,15 @@ def creds_dialog_main(creds): ent = Gtk.Entry() if cred[0] == libvirt.VIR_CRED_PASSPHRASE: ent.set_visibility(False) + elif conn.get_uri_username(): + ent.set_text(conn.get_uri_username()) ent.connect("activate", _on_ent_activate) entry.append(ent) - box.attach(label[row], 0, 1, row, row + 1, Gtk.AttachOptions.FILL, 0, 0, 0) - box.attach(entry[row], 1, 2, row, row + 1, Gtk.AttachOptions.FILL, 0, 0, 0) + box.attach(label[row], 0, 1, row, row + 1, + Gtk.AttachOptions.FILL, 0, 0, 0) + box.attach(entry[row], 1, 2, row, row + 1, + Gtk.AttachOptions.FILL, 0, 0, 0) row = row + 1 vbox = dialog.get_child() diff --git a/virtManager/connection.py b/virtManager/connection.py index dc3b0a7a..a653b4d4 100644 --- a/virtManager/connection.py +++ b/virtManager/connection.py @@ -320,10 +320,13 @@ class vmmConnection(vmmGObject): except: return self.get_uri_hostname() + get_uri_username = property(lambda s: + getattr(s, "_backend").get_uri_username) get_uri_hostname = property(lambda s: - getattr(s, "_backend").get_uri_hostname) - get_transport = property(lambda s: - getattr(s, "_backend").get_uri_transport) + getattr(s, "_backend").get_uri_hostname) + get_uri_transport = property(lambda s: + getattr(s, "_backend").get_uri_transport) + get_uri_port = property(lambda s: getattr(s, "_backend").get_uri_port) get_driver = property(lambda s: getattr(s, "_backend").get_uri_driver) is_container = property(lambda s: getattr(s, "_backend").is_container) is_lxc = property(lambda s: getattr(s, "_backend").is_lxc) @@ -887,7 +890,7 @@ class vmmConnection(vmmGObject): def _do_creds_password(self, creds): try: - return connectauth.creds_dialog(creds) + return connectauth.creds_dialog(self, creds) except: logging.debug("Launching creds dialog failed", exc_info=True) return -1 diff --git a/virtManager/console.py b/virtManager/console.py index 3abb0a41..e782a472 100644 --- a/virtManager/console.py +++ b/virtManager/console.py @@ -688,7 +688,7 @@ class vmmConsolePages(vmmGObjectUI): if ginfo.is_bad_localhost(): self._activate_unavailable_page( _("Guest is on a remote host with transport '%s'\n" - "but is only configured to listen on locally.\n" + "but is only configured to listen locally.\n" "Connect using 'ssh' transport or change the\n" "guest's listen address." % ginfo.transport)) return diff --git a/virtManager/engine.py b/virtManager/engine.py index d471d292..696cf6db 100644 --- a/virtManager/engine.py +++ b/virtManager/engine.py @@ -563,12 +563,12 @@ class vmmEngine(vmmGObject): if conn.is_remote(): logging.debug("connect_error: conn transport=%s", - conn.get_transport()) + conn.get_uri_transport()) if re.search(r"nc: .* -- 'U'", tb): hint += _("The remote host requires a version of netcat/nc\n" "which supports the -U option.") show_errmsg = False - elif (conn.get_transport()[0] == "ssh" and + elif (conn.get_uri_transport() == "ssh" and re.search(r"ssh-askpass", tb)): if self.config.askpass_package: diff --git a/virtManager/sshtunnels.py b/virtManager/sshtunnels.py index 3850ffc1..494eab3c 100644 --- a/virtManager/sshtunnels.py +++ b/virtManager/sshtunnels.py @@ -38,10 +38,11 @@ class ConnectionInfo(object): self.gaddr = gdev.listen or "127.0.0.1" self.gtlsport = gdev.tlsPort or None - self.transport, self.connuser = conn.get_transport() + self.transport = conn.get_uri_transport() + self.connuser = conn.get_uri_username() - (self._connhost, - self._connport) = conn.get_backend().get_uri_host_port() + self._connhost = conn.get_uri_hostname() + self._connport = conn.get_uri_port() if self._connhost == "localhost": self._connhost = "127.0.0.1" diff --git a/virtinst/connection.py b/virtinst/connection.py index 6f0decab..b4b4947f 100644 --- a/virtinst/connection.py +++ b/virtinst/connection.py @@ -363,14 +363,12 @@ class VirtualConnection(object): def get_uri_hostname(self): return self._urisplits.hostname or "localhost" - - def get_uri_host_port(self): - return self.get_uri_hostname(), self._urisplits.port - + def get_uri_port(self): + return self._urisplits.port + def get_uri_username(self): + return self._urisplits.username def get_uri_transport(self): - if self._urisplits.transport: - return [self._urisplits.transport, self._urisplits.username] - return [None, None] + return self._urisplits.transport def get_uri_driver(self): return self._urisplits.scheme