mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-02-11 07:55:52 -06:00
Add a auto-retry with exponential backoff to VNC connection, since with auto-console popup we often launch before the VNC daemon has started for the guest
This commit is contained in:
parent
e9decd56cd
commit
820832a007
@ -51,6 +51,8 @@ class vmmConsole(gobject.GObject):
|
||||
self.window.get_widget("console-vnc-align").add(self.vncViewer)
|
||||
self.vncViewer.connect("size-request", self.autosize)
|
||||
self.vncViewer.show()
|
||||
self.vncViewerFailures = 0
|
||||
self.vncViewerRetryDelay = 125
|
||||
|
||||
self.window.get_widget("console-pages").set_show_tabs(False)
|
||||
|
||||
@ -147,6 +149,10 @@ class vmmConsole(gobject.GObject):
|
||||
def _vnc_disconnected(self, src):
|
||||
self.activate_auth_page()
|
||||
|
||||
def retry_login(self):
|
||||
self.try_login()
|
||||
return False
|
||||
|
||||
def try_login(self, src=None):
|
||||
if self.vm.get_id() == 0:
|
||||
return
|
||||
@ -158,7 +164,8 @@ class vmmConsole(gobject.GObject):
|
||||
logging.debug("No graphics configured in guest")
|
||||
return
|
||||
|
||||
logging.debug("Graphics " + str(protocol) + "://" + str(host) + ":" + str(port))
|
||||
uri = str(protocol) + "://" + str(host) + ":" + str(port)
|
||||
logging.debug("Graphics console configured at " + uri)
|
||||
|
||||
if protocol != "vnc":
|
||||
self.activate_unavailable_page()
|
||||
@ -168,10 +175,22 @@ class vmmConsole(gobject.GObject):
|
||||
try:
|
||||
self.vncViewer.connect_to_host(host, port)
|
||||
except:
|
||||
logging.error("Unable to activate console " + str((sys.exc_info())[0]) + " " + str((sys.exc_info())[1]))
|
||||
self.vncViewerFailures = self.vncViewerFailures + 1
|
||||
logging.warn("Unable to activate console " + uri + ": " + str((sys.exc_info())[0]) + " " + str((sys.exc_info())[1]))
|
||||
self.activate_unavailable_page()
|
||||
if self.vncViewerFailures < 10:
|
||||
logging.warn("Retrying connection in %d ms", self.vncViewerRetryDelay)
|
||||
gobject.timeout_add(self.vncViewerRetryDelay, self.retry_login)
|
||||
if self.vncViewerRetryDelay < 2000:
|
||||
self.vncViewerRetryDelay = self.vncViewerRetryDelay * 2
|
||||
else:
|
||||
logging.error("Too many connection failures, not retrying again")
|
||||
return
|
||||
|
||||
# Had a succesfull connect, so reset counters now
|
||||
self.vncViewerFailures = 0
|
||||
self.vncViewerRetryDelay = 125
|
||||
|
||||
if self.vncViewer.is_authenticated():
|
||||
self.activate_viewer_page()
|
||||
elif password or not(self.vncViewer.needs_password()):
|
||||
|
@ -24,6 +24,7 @@ import sys
|
||||
from struct import pack, unpack
|
||||
import pygtk
|
||||
import gtk
|
||||
import logging
|
||||
|
||||
stderr = sys.stderr
|
||||
|
||||
@ -103,15 +104,14 @@ class GRFBFrameBuffer(rfb.RFBFrameBuffer, gobject.GObject):
|
||||
x2 = self.dirtyregion["x2"]
|
||||
y1 = self.dirtyregion["y1"]
|
||||
y2 = self.dirtyregion["y2"]
|
||||
#print "Update %d,%d (%dx%d)" % (x1, y1, (x2-x1), (y2-y1))
|
||||
self.emit("invalidate", x1, y1, x2-x1, y2-y1)
|
||||
self.dirtyregion = None
|
||||
|
||||
def change_cursor(self, width, height, x, y, data):
|
||||
print >>stderr, 'change_cursor'
|
||||
logging.error("Unsupported change_cursor operation requested")
|
||||
|
||||
def move_cursor(self, x, y):
|
||||
print >>stderr, 'move_cursor'
|
||||
logging.error("Unsupported move_cursor operation requested")
|
||||
|
||||
gobject.type_register(GRFBFrameBuffer)
|
||||
|
||||
@ -142,7 +142,7 @@ class GRFBNetworkClient(rfb.RFBNetworkClient, gobject.GObject):
|
||||
try:
|
||||
self.loop1()
|
||||
except Exception, e:
|
||||
print str(e)
|
||||
logging.warn("Failure while handling VNC I/O, closing socket: " + str(e))
|
||||
self.close()
|
||||
self.emit("disconnected")
|
||||
return 0
|
||||
@ -323,8 +323,8 @@ class GRFBViewer(gtk.DrawingArea):
|
||||
self.client.setpass(password)
|
||||
try:
|
||||
self.client.auth()
|
||||
except:
|
||||
print str(sys.exc_info()[0]) + " " + str(sys.exc_info()[1])
|
||||
except Exception, e:
|
||||
logging.warn("Failure while authenticating " + str(e))
|
||||
self.disconnect_from_host()
|
||||
return 0
|
||||
self.authenticated = True
|
||||
|
Loading…
Reference in New Issue
Block a user