connection: Bunch of minor tweaks handling TCP URIs

This commit is contained in:
Cole Robinson 2015-04-11 12:08:57 -04:00
parent ee9aa0ef11
commit fc171fc31d
6 changed files with 30 additions and 24 deletions

View File

@ -52,22 +52,22 @@ def do_we_have_session():
return False return False
def creds_dialog(creds): def creds_dialog(conn, creds):
""" """
Thread safe wrapper for libvirt openAuth user/pass callback Thread safe wrapper for libvirt openAuth user/pass callback
""" """
retipc = [] retipc = []
def wrapper(fn, creds): def wrapper(fn, conn, creds):
try: try:
ret = fn(creds) ret = fn(conn, creds)
except: except:
logging.exception("Error from creds dialog") logging.exception("Error from creds dialog")
ret = -1 ret = -1
retipc.append(ret) retipc.append(ret)
GLib.idle_add(wrapper, creds_dialog_main, creds) GLib.idle_add(wrapper, _creds_dialog_main, conn, creds)
while not retipc: while not retipc:
time.sleep(.1) time.sleep(.1)
@ -75,7 +75,7 @@ def creds_dialog(creds):
return retipc[0] return retipc[0]
def creds_dialog_main(creds): def _creds_dialog_main(conn, creds):
""" """
Libvirt openAuth callback for username/password credentials Libvirt openAuth callback for username/password credentials
""" """
@ -118,11 +118,15 @@ def creds_dialog_main(creds):
ent = Gtk.Entry() ent = Gtk.Entry()
if cred[0] == libvirt.VIR_CRED_PASSPHRASE: if cred[0] == libvirt.VIR_CRED_PASSPHRASE:
ent.set_visibility(False) ent.set_visibility(False)
elif conn.get_uri_username():
ent.set_text(conn.get_uri_username())
ent.connect("activate", _on_ent_activate) ent.connect("activate", _on_ent_activate)
entry.append(ent) entry.append(ent)
box.attach(label[row], 0, 1, row, row + 1, Gtk.AttachOptions.FILL, 0, 0, 0) box.attach(label[row], 0, 1, row, row + 1,
box.attach(entry[row], 1, 2, row, row + 1, Gtk.AttachOptions.FILL, 0, 0, 0) Gtk.AttachOptions.FILL, 0, 0, 0)
box.attach(entry[row], 1, 2, row, row + 1,
Gtk.AttachOptions.FILL, 0, 0, 0)
row = row + 1 row = row + 1
vbox = dialog.get_child() vbox = dialog.get_child()

View File

@ -320,10 +320,13 @@ class vmmConnection(vmmGObject):
except: except:
return self.get_uri_hostname() return self.get_uri_hostname()
get_uri_username = property(lambda s:
getattr(s, "_backend").get_uri_username)
get_uri_hostname = property(lambda s: get_uri_hostname = property(lambda s:
getattr(s, "_backend").get_uri_hostname) getattr(s, "_backend").get_uri_hostname)
get_transport = property(lambda s: get_uri_transport = property(lambda s:
getattr(s, "_backend").get_uri_transport) 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) get_driver = property(lambda s: getattr(s, "_backend").get_uri_driver)
is_container = property(lambda s: getattr(s, "_backend").is_container) is_container = property(lambda s: getattr(s, "_backend").is_container)
is_lxc = property(lambda s: getattr(s, "_backend").is_lxc) is_lxc = property(lambda s: getattr(s, "_backend").is_lxc)
@ -887,7 +890,7 @@ class vmmConnection(vmmGObject):
def _do_creds_password(self, creds): def _do_creds_password(self, creds):
try: try:
return connectauth.creds_dialog(creds) return connectauth.creds_dialog(self, creds)
except: except:
logging.debug("Launching creds dialog failed", exc_info=True) logging.debug("Launching creds dialog failed", exc_info=True)
return -1 return -1

View File

@ -688,7 +688,7 @@ class vmmConsolePages(vmmGObjectUI):
if ginfo.is_bad_localhost(): if ginfo.is_bad_localhost():
self._activate_unavailable_page( self._activate_unavailable_page(
_("Guest is on a remote host with transport '%s'\n" _("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" "Connect using 'ssh' transport or change the\n"
"guest's listen address." % ginfo.transport)) "guest's listen address." % ginfo.transport))
return return

View File

@ -563,12 +563,12 @@ class vmmEngine(vmmGObject):
if conn.is_remote(): if conn.is_remote():
logging.debug("connect_error: conn transport=%s", logging.debug("connect_error: conn transport=%s",
conn.get_transport()) conn.get_uri_transport())
if re.search(r"nc: .* -- 'U'", tb): if re.search(r"nc: .* -- 'U'", tb):
hint += _("The remote host requires a version of netcat/nc\n" hint += _("The remote host requires a version of netcat/nc\n"
"which supports the -U option.") "which supports the -U option.")
show_errmsg = False show_errmsg = False
elif (conn.get_transport()[0] == "ssh" and elif (conn.get_uri_transport() == "ssh" and
re.search(r"ssh-askpass", tb)): re.search(r"ssh-askpass", tb)):
if self.config.askpass_package: if self.config.askpass_package:

View File

@ -38,10 +38,11 @@ class ConnectionInfo(object):
self.gaddr = gdev.listen or "127.0.0.1" self.gaddr = gdev.listen or "127.0.0.1"
self.gtlsport = gdev.tlsPort or None 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._connhost = conn.get_uri_hostname()
self._connport) = conn.get_backend().get_uri_host_port() self._connport = conn.get_uri_port()
if self._connhost == "localhost": if self._connhost == "localhost":
self._connhost = "127.0.0.1" self._connhost = "127.0.0.1"

View File

@ -363,14 +363,12 @@ class VirtualConnection(object):
def get_uri_hostname(self): def get_uri_hostname(self):
return self._urisplits.hostname or "localhost" return self._urisplits.hostname or "localhost"
def get_uri_port(self):
def get_uri_host_port(self): return self._urisplits.port
return self.get_uri_hostname(), self._urisplits.port def get_uri_username(self):
return self._urisplits.username
def get_uri_transport(self): def get_uri_transport(self):
if self._urisplits.transport: return self._urisplits.transport
return [self._urisplits.transport, self._urisplits.username]
return [None, None]
def get_uri_driver(self): def get_uri_driver(self):
return self._urisplits.scheme return self._urisplits.scheme