libvirtobject: Clarify force_update_status

This commit is contained in:
Cole Robinson
2015-04-09 19:03:27 -04:00
parent c9b882619e
commit 4933cf7600
6 changed files with 28 additions and 14 deletions

View File

@@ -691,7 +691,7 @@ class vmmConnection(vmmGObject):
if obj:
# If the domain disappeared, this will catch it and trigger
# a domain list refresh
self.idle_add(obj.force_update_status, True)
self.idle_add(obj.refresh_status_from_event_loop)
if event == libvirt.VIR_DOMAIN_EVENT_DEFINED:
# Uses forcesignal=True
@@ -706,7 +706,7 @@ class vmmConnection(vmmGObject):
obj = self._nets.get(network.name(), None)
if obj:
self.idle_add(obj.force_update_status, True)
self.idle_add(obj.refresh_status_from_event_loop)
if event == getattr(libvirt, "VIR_NETWORK_EVENT_DEFINED", 0):
# Uses forcesignal=True

View File

@@ -363,8 +363,6 @@ class vmmDomain(vmmLibvirtObject):
self.toggle_sample_mem_stats()
self.toggle_sample_cpu_stats()
self.force_update_status(from_event=True)
# Prime caches
self.refresh_xml()
self.has_managed_save()
@@ -1901,8 +1899,7 @@ class vmmDomain(vmmLibvirtObject):
if stats_update:
self._tick_stats(info)
# This is a no-op if using events
self.force_update_status(newstatus=info[0])
self._refresh_status(newstatus=info and info[0] or None)
if stats_update:
self.idle_emit("resources-sampled")

View File

@@ -46,7 +46,7 @@ class vmmInterface(vmmLibvirtObject):
return self._backend_get_active()
def tick(self):
self.force_update_status()
self._refresh_status()
#####################

View File

@@ -46,6 +46,7 @@ class vmmLibvirtObject(vmmGObject):
self._key = key
self._parseclass = parseclass
self._initial_status_update = False
self.__status = self._STATUS_ACTIVE
self._support_isactive = None
@@ -178,12 +179,28 @@ class vmmLibvirtObject(vmmGObject):
# vmmDomain overwrites this since it has more fine grained statuses
return self._get_status() == self._STATUS_ACTIVE
def force_update_status(self, from_event=False, newstatus=None):
def refresh_status_from_event_loop(self):
"""
Updates VM status, because we received a status event from libvirt's
event implementations. That's the only time this should be used.
"""
return self._refresh_status(skip_if_have_events=False)
def _refresh_status(self, skip_if_have_events=True, newstatus=None):
"""
Grab the object status/active state from libvirt, and if the
status has changed, update the XML cache. Typically called from
object tick functions for manually updating the object state.
:param skip_if_have_events: If this object is served by libvirt
events, we want this to be a no-op for most usages, like
from tick(), so don't do anything.
:param newstatus: Used by vmmDomain as a small optimization to
avoid polling info() twice
avoid polling info() twice
"""
if self._using_events() and not from_event:
if (self._using_events() and
skip_if_have_events and
self._initial_status_update):
return
try:
@@ -204,6 +221,8 @@ class vmmLibvirtObject(vmmGObject):
kwargs = {"force": True, self._conn_tick_poll_param: True}
logging.debug("Scheduling priority tick with: %s", kwargs)
self.conn.schedule_priority_tick(**kwargs)
finally:
self._initial_status_update = True
def _backend_get_active(self):
if self._support_isactive is None:

View File

@@ -44,8 +44,6 @@ class vmmNetwork(vmmLibvirtObject):
def __init__(self, conn, backend, key):
vmmLibvirtObject.__init__(self, conn, backend, key, Network)
self.force_update_status(from_event=True)
##########################
# Required class methods #
@@ -64,7 +62,7 @@ class vmmNetwork(vmmLibvirtObject):
return self._backend_get_active()
def tick(self):
self.force_update_status()
self._refresh_status()
###########

View File

@@ -129,7 +129,7 @@ class vmmStoragePool(vmmLibvirtObject):
return self._backend_get_active()
def tick(self):
self.force_update_status()
self._refresh_status()
###########