[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[virt-tools-list] [PATCH python v2] Use storage pool lifecycle events



Changes since v1: split long lines, remove unnecessary call of tick(),
remove code cleanup
---
 virtManager/connection.py  | 37 +++++++++++++++++++++++++++++++++++++
 virtManager/storagepool.py |  4 +++-
 2 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/virtManager/connection.py b/virtManager/connection.py
index 6cb9cc0..be1e6ac 100644
--- a/virtManager/connection.py
+++ b/virtManager/connection.py
@@ -213,6 +213,8 @@ class vmmConnection(vmmGObject):
         self._domain_cb_ids = []
         self.using_network_events = False
         self._network_cb_ids = []
+        self.using_storage_pool_events = False
+        self._storage_pool_cb_ids = []
 
         self._xml_flags = {}
 
@@ -774,6 +776,21 @@ class vmmConnection(vmmGObject):
         else:
             self.schedule_priority_tick(pollnet=True, force=True)
 
+    def _storage_pool_lifecycle_event(self, conn, pool,
+                                      event, reason, userdata):
+        ignore = conn
+        ignore = userdata
+
+        name = pool.name()
+        logging.debug("storage pool lifecycle event: storage=%s event=%s "
+            "reason=%s", name, event, reason)
+        obj = self.get_pool(name)
+
+        if obj:
+            self.idle_add(obj.refresh_from_event_loop)
+        else:
+            self.schedule_priority_tick(pollpool=True, force=True)
+
     def _add_conn_events(self):
         if not self.check_support(support.SUPPORT_CONN_WORKING_XEN_EVENTS):
             return
@@ -829,6 +846,21 @@ class vmmConnection(vmmGObject):
             self.using_network_events = False
             logging.debug("Error registering network events: %s", e)
 
+        try:
+            if FORCE_DISABLE_EVENTS:
+                raise RuntimeError("FORCE_DISABLE_EVENTS = True")
+
+            eventid = getattr(libvirt,
+                              "VIR_STORAGE_POOL_EVENT_ID_LIFECYCLE", 0)
+            self._storage_pool_cb_ids.append(
+                self.get_backend().storagePoolEventRegisterAny(
+                None, eventid, self._storage_pool_lifecycle_event, None))
+            self.using_storage_pool_events = True
+            logging.debug("Using storage pool events")
+        except Exception, e:
+            self.using_storage_pool_events = False
+            logging.debug("Error registering storage pool events: %s", e)
+
 
     ######################################
     # Connection closing/opening methods #
@@ -849,12 +881,15 @@ class vmmConnection(vmmGObject):
                     self._backend.domainEventDeregisterAny(eid)
                 for eid in self._network_cb_ids:
                     self._backend.networkEventDeregisterAny(eid)
+                for eid in self._storage_pool_cb_ids:
+                    self._backend.storagePoolEventDeregisterAny(eid)
         except:
             logging.debug("Failed to deregister events in conn cleanup",
                 exc_info=True)
         finally:
             self._domain_cb_ids = []
             self._network_cb_ids = []
+            self._storage_pool_cb_ids = []
 
         self._backend.close()
         self._stats = []
@@ -1177,6 +1212,8 @@ class vmmConnection(vmmGObject):
             pollvm = False
         if self.using_network_events and not force:
             pollnet = False
+        if self.using_storage_pool_events and not force:
+            pollpool = False
 
         self._hostinfo = self._backend.getInfo()
 
diff --git a/virtManager/storagepool.py b/virtManager/storagepool.py
index b099fbe..b39fcfb 100644
--- a/virtManager/storagepool.py
+++ b/virtManager/storagepool.py
@@ -40,7 +40,7 @@ class vmmStorageVolume(vmmLibvirtObject):
     ##########################
 
     def _conn_tick_poll_param(self):
-        return None
+        return "pollpool"
     def class_name(self):
         return "volume"
 
@@ -134,6 +134,8 @@ class vmmStoragePool(vmmLibvirtObject):
         return self._backend.XMLDesc(flags)
     def _define(self, xml):
         return self.conn.define_pool(xml)
+    def _using_events(self):
+        return self.conn.using_storage_pool_events
     def _check_supports_isactive(self):
         return self.conn.check_support(
             self.conn.SUPPORT_POOL_ISACTIVE, self._backend)
-- 
2.5.5


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]