[Kimchi-devel] [PATCH] [Kimchi 1/2] Register for libvirt storage pools events to update the UI accordindly

Aline Manera aline.manera at gmail.com
Tue Jul 25 18:38:37 UTC 2017


Signed-off-by: Aline Manera <aline.manera at gmail.com>
---
 model/libvirtevents.py | 18 +++++++++++++++++-
 model/model.py         | 11 +++++++++--
 2 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/model/libvirtevents.py b/model/libvirtevents.py
index 716420c..64a102c 100644
--- a/model/libvirtevents.py
+++ b/model/libvirtevents.py
@@ -1,7 +1,7 @@
 #
 # Project Kimchi
 #
-# Copyright IBM Corp, 2016
+# Copyright IBM Corp, 2016-2017
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -117,3 +117,19 @@ class LibvirtEvents(object):
 
         except libvirt.libvirtError as e:
             wok_log.error("register detach event failed: %s" % e.message)
+
+    def registerPoolEvents(self, conn, cb, arg):
+        """
+        Register libvirt events to list to any pool change
+        """
+        pool_events = [libvirt.VIR_STORAGE_POOL_EVENT_DEFINED,
+                       libvirt.VIR_STORAGE_POOL_EVENT_STARTED,
+                       libvirt.VIR_STORAGE_POOL_EVENT_STOPPED,
+                       libvirt.VIR_STORAGE_POOL_EVENT_UNDEFINED]
+
+        for ev in pool_events:
+            try:
+                conn.get().storagePoolEventRegisterAny(None, ev, cb, arg)
+            except libvirt.libvirtError as e:
+                wok_log.error("Unable to register pool event handler: %s" %
+                              e.message)
diff --git a/model/model.py b/model/model.py
index 719652d..b04e5e9 100644
--- a/model/model.py
+++ b/model/model.py
@@ -1,7 +1,7 @@
 #
 # Project Kimchi
 #
-# Copyright IBM Corp, 2015-2016
+# Copyright IBM Corp, 2015-2017
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -20,6 +20,7 @@
 from wok.basemodel import BaseModel
 from wok.objectstore import ObjectStore
 from wok.plugins.kimchi import config
+from wok.pushserver import send_wok_notification
 from wok.utils import get_all_model_instances, get_model_instances
 
 from wok.plugins.kimchi.model.libvirtconnection import LibvirtConnection
@@ -32,9 +33,10 @@ class Model(BaseModel):
         self.objstore = ObjectStore(objstore_loc or config.get_object_store())
         self.conn = LibvirtConnection(libvirt_uri)
 
-        # Register for Libvirt's host ENOSPC event and notify UI if it happens
+        # Register for libvirt events
         self.events = LibvirtEvents()
         self.events.handleEnospc(self.conn)
+        self.events.registerPoolEvents(self.conn, self._events_handler, self)
 
         kargs = {'objstore': self.objstore, 'conn': self.conn,
                  'eventsloop': self.events}
@@ -47,3 +49,8 @@ class Model(BaseModel):
             models.append(instance(**kargs))
 
         return super(Model, self).__init__(models)
+
+    def _events_handler(self, conn, pool, ev, details, opaque):
+        # Do not use any known method (POST, PUT, DELETE) as it is used by Wok
+        # engine and may lead in having 2 notifications for the same action
+        send_wok_notification('/plugins/kimchi', 'storages', 'METHOD')
-- 
2.9.4



More information about the Kimchi-devel mailing list