connection: Only attempt to talk to HAL if absolutely required.

This commit is contained in:
Cole Robinson 2009-11-30 13:05:35 -05:00
parent 085f2de8f0
commit 5d9d6a6fc4
2 changed files with 29 additions and 18 deletions

View File

@ -96,10 +96,11 @@ class vmmConnection(gobject.GObject):
STATE_ACTIVE = 2
STATE_INACTIVE = 3
def __init__(self, config, uri, readOnly=None, hal_helper=None):
def __init__(self, config, uri, readOnly=None, engine=None):
self.__gobject_init__()
self.config = config
self.engine = engine
self.connectThread = None
self.connectThreadEvent = threading.Event()
@ -139,7 +140,6 @@ class vmmConnection(gobject.GObject):
self.record = []
self.hostinfo = None
self.hal_helper = hal_helper
self.hal_helper_remove_sig = None
self.netdev_initialized = False
@ -153,10 +153,15 @@ class vmmConnection(gobject.GObject):
# Init routines #
#################
def _set_hal_remove_sig(self):
def get_hal_helper(self):
if self.engine:
return self.engine.get_hal_helper()
return None
def _set_hal_remove_sig(self, hal_helper):
if not self.hal_helper_remove_sig:
sig = self.hal_helper.connect("device-removed",
self._haldev_removed)
sig = hal_helper.connect("device-removed",
self._haldev_removed)
self.hal_helper_remove_sig = sig
def _init_netdev(self):
@ -170,17 +175,18 @@ class vmmConnection(gobject.GObject):
except Exception, e:
self.netdev_error = _("Could build physical interface "
"list via libvirt: %s") % str(e)
elif self.hal_helper:
elif self.get_hal_helper():
hal_helper = self.get_hal_helper()
if self.is_remote():
self.netdev_error = _("Libvirt version does not support "
"physical interface listing")
else:
error = self.hal_helper.get_init_error()
error = hal_helper.get_init_error()
if not error:
self.hal_helper.connect("netdev-added",
self._netdev_added)
self._set_hal_remove_sig()
hal_helper.connect("netdev-added", self._netdev_added)
self._set_hal_remove_sig(hal_helper)
else:
self.netdev_error = _("Could not initialize HAL for "
@ -199,17 +205,18 @@ class vmmConnection(gobject.GObject):
logging.debug("Using HAL for netdev enumeration")
def _init_optical(self):
if self.hal_helper:
if self.get_hal_helper():
hal_helper = self.get_hal_helper()
if self.is_remote():
self.optical_error = _("Libvirt version does not support "
"optical media listing.")
else:
error = self.hal_helper.get_init_error()
error = hal_helper.get_init_error()
if not error:
self.hal_helper.connect("optical-added",
self._optical_added)
self._set_hal_remove_sig()
hal_helper.connect("optical-added", self._optical_added)
self._set_hal_remove_sig(hal_helper)
else:
self.optical_error = _("Could not initialize HAL for "

View File

@ -86,7 +86,7 @@ class vmmEngine(gobject.GObject):
# keep running in system tray if enabled
self.windows = 0
self.halHelper = vmmHalHelper()
self.hal_helper = None
self.init_systray()
self.config.on_stats_update_interval_changed(self.reschedule_timer)
@ -118,6 +118,11 @@ class vmmEngine(gobject.GObject):
# Show the manager so that the user can control the application
self.show_manager()
def get_hal_helper(self):
if not self.hal_helper:
self.hal_helper = vmmHalHelper()
return self.hal_helper
def load_stored_uris(self):
uris = self.config.get_connections()
if uris != None:
@ -439,8 +444,7 @@ class vmmEngine(gobject.GObject):
self.windowCreate.show(uri)
def add_connection(self, uri, readOnly=None, autoconnect=False):
conn = vmmConnection(self.get_config(), uri, readOnly,
self.halHelper)
conn = vmmConnection(self.get_config(), uri, readOnly, self)
self.connections[uri] = {
"connection": conn,
"windowHost": None,