Improved user feedback on console access. Initial support for connecting to remote guest consoles

This commit is contained in:
Daniel P. Berrange 2007-08-27 21:35:22 -04:00
parent 3db06d56f7
commit 7b3fb2d1bd
4 changed files with 44 additions and 20 deletions

View File

@ -176,7 +176,7 @@ class vmmConnection(gobject.GObject):
def get_hostname(self):
try:
(scheme, netloc, path, query, fragment) = self.uri_split()
(scheme, username, netloc, path, query, fragment) = self.uri_split()
if netloc != "":
return netloc
@ -187,7 +187,7 @@ class vmmConnection(gobject.GObject):
def get_name(self):
try:
(scheme, netloc, path, query, fragment) = self.uri_split()
(scheme, username, netloc, path, query, fragment) = self.uri_split()
i = scheme.find("+")
if i > 0:
@ -212,13 +212,24 @@ class vmmConnection(gobject.GObject):
def is_remote(self):
try:
(scheme, netloc, path, query, fragment) = self.uri_split()
(scheme, username, netloc, path, query, fragment) = self.uri_split()
if netloc == "":
return False
return True
except:
return True
def get_transport(self):
try:
(scheme, username, netloc, path, query, fragment) = self.uri_split()
if scheme:
offset = scheme.index("+")
if offset > 0:
return [scheme[offset:], username]
except:
pass
return None
def get_uri(self):
return self.uri
@ -621,12 +632,16 @@ class vmmConnection(gobject.GObject):
def uri_split(self):
uri = self.uri
netloc = query = fragment = ''
username = netloc = query = fragment = ''
i = uri.find(":")
if i > 0:
scheme, uri = uri[:i].lower(), uri[i+1:]
if uri[:2] == '//':
netloc, uri = self._splitnetloc(uri, 2)
offset = netloc.find("@")
if offset > 0:
username = netloc[0:offset]
netloc = netloc[offset+1:]
if '#' in uri:
uri, fragment = uri.split('#', 1)
if '?' in uri:
@ -634,7 +649,7 @@ class vmmConnection(gobject.GObject):
else:
scheme = uri.lower()
return scheme, netloc, uri, query, fragment
return scheme, username, netloc, uri, query, fragment
def _splitnetloc(self, url, start=0):
for c in '/?#': # the order is important!

View File

@ -231,7 +231,7 @@ class vmmConsole(gobject.GObject):
def _vnc_disconnected(self, src):
logging.debug("VNC disconnected")
self.vncViewerFailures = self.vncViewerFailures + 1
self.activate_unavailable_page()
self.activate_unavailable_page(_("Console was disconnected from guest"))
if not self.is_visible():
return
@ -265,28 +265,32 @@ class vmmConsole(gobject.GObject):
def try_login(self, src=None):
if self.vm.get_id() <= 0:
self.activate_unavailable_page(_("Console not available for inactive guest"))
return
logging.debug("Trying console login")
password = self.window.get_widget("console-auth-password").get_text()
protocol, host, port = self.vm.get_graphics_console()
protocol, host, port, trans = self.vm.get_graphics_console()
if protocol is None:
logging.debug("No graphics configured in guest")
self.activate_unavailable_page(_("Console not configured for guest"))
return
uri = str(protocol) + "://" + str(host) + ":" + str(port)
logging.debug("Graphics console configured at " + uri)
if protocol != "vnc":
logging.debug("Not a VNC console, disabling")
self.activate_unavailable_page(_("Console not supported for guest"))
return
if int(port) == -1:
self.activate_unavailable_page(_("Console is not yet active for guest"))
self.schedule_retry()
return
if protocol != "vnc":
logging.debug("Not a VNC console, disabling")
self.activate_unavailable_page()
return
self.activate_unavailable_page(_("Connecting to console for guest"))
logging.debug("Starting connect process for %s %s" % (host, str(port)))
try:
self.vncViewer.open_host(host, str(port))
@ -313,9 +317,10 @@ class vmmConsole(gobject.GObject):
self.activate_auth_page()
def activate_unavailable_page(self):
def activate_unavailable_page(self, msg):
self.window.get_widget("console-pages").set_current_page(PAGE_UNAVAILABLE)
self.window.get_widget("menu-vm-screenshot").set_sensitive(False)
self.window.get_widget("console-unavailable").set_label("<b>" + msg + "</b>")
def activate_screenshot_page(self):
self.window.get_widget("console-pages").set_current_page(PAGE_SCREENSHOT)
@ -495,9 +500,9 @@ class vmmConsole(gobject.GObject):
if self.window.get_widget("console-pages").get_current_page() != PAGE_UNAVAILABLE:
self.vncViewer.close()
self.window.get_widget("console-pages").set_current_page(PAGE_UNAVAILABLE)
self.activate_unavailable_page(_("Console not available for inactive guest"))
else:
if status == libvirt.VIR_DOMAIN_PAUSED:
screenshot = None
if self.window.get_widget("console-pages").get_current_page() == PAGE_VNCVIEWER:
screenshot = self.vncViewer.take_screenshot()
cr = screenshot.cairo_create()
@ -523,7 +528,7 @@ class vmmConsole(gobject.GObject):
else:
if self.window.get_widget("console-pages").get_current_page() != PAGE_UNAVAILABLE:
self.vncViewer.close()
self.activate_unavailable_page()
self.activate_unavailable_page(_("Console not available while paused"))
else:
if self.window.get_widget("console-pages").get_current_page() == PAGE_UNAVAILABLE:
self.vncViewerFailures = 0

View File

@ -452,8 +452,12 @@ class vmmDomain(gobject.GObject):
if type == "vnc":
port = self.get_xml_string("/domain/devices/graphics[@type='vnc']/@port")
if port is not None:
return [type, "127.0.0.1", int(port)]
return [type, None, None]
port = int(port)
transport, username = self.connection.get_transport()
return [type, self.connection.get_hostname(), int(port), transport]
def get_disk_devices(self):
xml = self.get_xml()

View File

@ -336,10 +336,10 @@ 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, host, port) = vm.get_graphics_console()
(gtype, host, port, transport) = vm.get_graphics_console()
if gtype == "vnc":
self.emit("action-show-console", uri, vmuuid)
else:
elif not connect.is_remote():
self.emit("action-show-terminal", uri, vmuuid)
def _append_vm(self, model, vm, conn):