domain: Have get_graphical_console provide more info

This commit is contained in:
Cole Robinson 2010-02-12 16:33:43 -05:00
parent b661b289c9
commit f243ce4f7e
4 changed files with 43 additions and 32 deletions

View File

@ -603,36 +603,28 @@ class vmmConsolePages(gobject.GObject):
return
try:
(protocol, host,
port, trans, username) = self.vm.get_graphics_console()
(protocol, connhost,
vncport, trans, username,
connport, vncuri) = self.vm.get_graphics_console()
except Exception, e:
# We can fail here if VM is destroyed: xen is a bit racy
# and can't handle domain lookups that soon after
logging.debug("Getting graphics console failed: %s" % str(e))
return
connport = None
if host.count(":"):
host, connport = host.split(":", 1)
if protocol is None:
logging.debug("No graphics configured in guest")
self.activate_unavailable_page(
_("Graphical console not configured for guest"))
return
uri = str(protocol) + "://"
if username:
uri = uri + str(username) + '@'
uri = uri + str(host) + ":" + str(port)
if protocol != "vnc":
logging.debug("Not a VNC console, disabling")
self.activate_unavailable_page(
_("Graphical console not supported for guest"))
return
if int(port) == -1:
if vncport == -1:
self.activate_unavailable_page(
_("Graphical console is not yet active for guest"))
self.schedule_retry()
@ -641,20 +633,22 @@ class vmmConsolePages(gobject.GObject):
self.activate_unavailable_page(
_("Connecting to graphical console for guest"))
logging.debug("Starting connect process for %s: %s %s" %
(uri, host, str(port)))
(vncuri, connhost, str(vncport)))
try:
if trans is not None and trans in ("ssh", "ext"):
if trans in ("ssh", "ext"):
if self.vncTunnel:
logging.debug("Tunnel already open, skipping open_tunnel.")
# Tunnel already open, no need to continue
return
fd = self.open_tunnel(host, "127.0.0.1", port, username,
connport)
fd = self.open_tunnel(connhost, "127.0.0.1", vncport,
username, connport)
if fd >= 0:
self.vncViewer.open_fd(fd)
else:
self.vncViewer.open_host(host, str(port))
self.vncViewer.open_host(connhost, str(vncport))
except:
(typ, value, stacktrace) = sys.exc_info ()
details = \

View File

@ -1537,7 +1537,7 @@ class vmmCreate(gobject.GObject):
if self.config.get_console_popup() == 1:
# user has requested console on new created vms only
vm = self.conn.get_vm(guest.uuid)
(gtype, ignore, ignore, ignore, ignore) = vm.get_graphics_console()
gtype = vm.get_graphics_console()[0]
if gtype == "vnc":
self.emit("action-show-console", self.conn.get_uri(),
guest.uuid)

View File

@ -341,24 +341,41 @@ class vmmDomainBase(gobject.GObject):
return self._parse_device_xml(_parse_serial_consoles)
def get_graphics_console(self):
typ = vutil.get_xml_path(self.get_xml(),
"/domain/devices/graphics/@type")
port = None
if typ == "vnc":
port = vutil.get_xml_path(self.get_xml(),
"/domain/devices/graphics[@type='vnc']/@port")
if port is not None:
port = int(port)
gtype = vutil.get_xml_path(self.get_xml(),
"/domain/devices/graphics/@type")
vncport = vutil.get_xml_path(self.get_xml(),
"/domain/devices/graphics[@type='vnc']/@port")
if gtype != "vnc":
vncport = None
else:
vncport = int(vncport)
connhost = self.connection.get_uri_hostname()
transport, username = self.connection.get_transport()
if transport is None:
if transport == None:
# Force use of 127.0.0.1, because some (broken) systems don't
# reliably resolve 'localhost' into 127.0.0.1, either returning
# the public IP, or an IPv6 addr. Neither work since QEMU only
# listens on 127.0.0.1 for VNC.
return [typ, "127.0.0.1", port, None, None]
else:
return [typ, self.connection.get_hostname(), port, transport, username]
connhost = "127.0.0.1"
# Parse URI port
connport = None
if connhost.count(":"):
connhost, connport = connhost.split(":", 1)
# Build VNC uri for debugging
vncuri = None
if gtype:
vncuri = str(gtype) + "://"
if username:
vncuri = vncuri + str(username) + '@'
vncuri += str(connhost) + ":" + str(vncport)
return [gtype, connhost, vncport, transport, username, connport,
vncuri]
# ----------------

View File

@ -814,7 +814,7 @@ class vmmManager(gobject.GObject):
logging.debug("VM %s started" % vm.get_name())
if self.config.get_console_popup() == 2 and not vm.is_management_domain():
# user has requested consoles on all vms
(gtype, ignore, ignore, ignore, ignore) = vm.get_graphics_console()
gtype = vm.get_graphics_console()[0]
if gtype == "vnc":
self.emit("action-show-console", uri, vmuuid)
elif not connection.is_remote():