Signed-off-by: Aline Manera <aline.manera(a)gmail.com>
---
model/libvirtevents.py | 18 +++++++++++++++++-
model/model.py | 14 +++++++++++---
2 files changed, 28 insertions(+), 4 deletions(-)
diff --git a/model/libvirtevents.py b/model/libvirtevents.py
index 716420c..2401c5d 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 listen 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..97def98 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,11 @@ 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,
+ 'storages')
kargs = {'objstore': self.objstore, 'conn': self.conn,
'eventsloop': self.events}
@@ -46,4 +49,9 @@ class Model(BaseModel):
for instance in instances:
models.append(instance(**kargs))
- return super(Model, self).__init__(models)
+ 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', opaque, 'METHOD')
--
2.9.4