viewer: move vm from ConnectionInfo to Viewer

I don't really like the VM in Viewer either, since it will encourage
layering violations, but it's a better fit than in ConnectionInfo
This commit is contained in:
Cole Robinson 2016-05-07 18:08:25 -04:00
parent bd725d6cfe
commit 7cc6141618
3 changed files with 7 additions and 10 deletions

View File

@ -621,7 +621,7 @@ class vmmConsolePages(vmmGObjectUI):
gdevs = self.vm.get_graphics_devices() gdevs = self.vm.get_graphics_devices()
gdev = gdevs and gdevs[0] or None gdev = gdevs and gdevs[0] or None
if gdev: if gdev:
ginfo = ConnectionInfo(self.vm, gdev) ginfo = ConnectionInfo(self.vm.conn, gdev)
except Exception, e: except Exception, e:
# We can fail here if VM is destroyed: xen is a bit racy # We can fail here if VM is destroyed: xen is a bit racy
# and can't handle domain lookups that soon after # and can't handle domain lookups that soon after
@ -667,7 +667,7 @@ class vmmConsolePages(vmmGObjectUI):
"SpiceClientGtk missing") "SpiceClientGtk missing")
self._viewer = viewer_class(ginfo) self._viewer = viewer_class(self.vm, ginfo)
self._connect_viewer_signals() self._connect_viewer_signals()
self._refresh_enable_accel() self._refresh_enable_accel()

View File

@ -32,9 +32,7 @@ class ConnectionInfo(object):
""" """
Holds all the bits needed to make a connection to a graphical console Holds all the bits needed to make a connection to a graphical console
""" """
def __init__(self, vm, gdev): def __init__(self, conn, gdev):
conn = vm.conn
self.vm = vm
self.gtype = gdev.type self.gtype = gdev.type
self.gport = gdev.port and str(gdev.port) or None self.gport = gdev.port and str(gdev.port) or None
self.gsocket = gdev.socket self.gsocket = gdev.socket
@ -49,9 +47,6 @@ class ConnectionInfo(object):
if self._connhost == "localhost": if self._connhost == "localhost":
self._connhost = "127.0.0.1" self._connhost = "127.0.0.1"
def get_conn_fd(self):
return self.vm.open_graphics_fd()
def _is_listen_localhost(self, host=None): def _is_listen_localhost(self, host=None):
try: try:
return ipaddr.IPNetwork(host or self.gaddr).is_loopback return ipaddr.IPNetwork(host or self.gaddr).is_loopback

View File

@ -64,9 +64,10 @@ class Viewer(vmmGObject):
"usb-redirect-error": (GObject.SignalFlags.RUN_FIRST, None, [str]), "usb-redirect-error": (GObject.SignalFlags.RUN_FIRST, None, [str]),
} }
def __init__(self, ginfo): def __init__(self, vm, ginfo):
vmmGObject.__init__(self) vmmGObject.__init__(self)
self._display = None self._display = None
self._vm = vm
self._ginfo = ginfo self._ginfo = ginfo
self._tunnels = SSHTunnels(self._ginfo) self._tunnels = SSHTunnels(self._ginfo)
@ -84,6 +85,7 @@ class Viewer(vmmGObject):
if self._display: if self._display:
self._display.destroy() self._display.destroy()
self._display = None self._display = None
self._vm = None
self._tunnels.close_all() self._tunnels.close_all()
@ -137,7 +139,7 @@ class Viewer(vmmGObject):
def _get_fd_for_open(self): def _get_fd_for_open(self):
if self._ginfo.need_tunnel(): if self._ginfo.need_tunnel():
return self._tunnels.open_new() return self._tunnels.open_new()
return self._ginfo.get_conn_fd() return self._vm.open_graphics_fd()
def _open(self): def _open(self):
fd = self._get_fd_for_open() fd = self._get_fd_for_open()