Signed-off-by: Aline Manera <aline.manera(a)gmail.com>
---
model/libvirtevents.py | 16 ++++++++++++++++
model/model.py | 2 ++
2 files changed, 18 insertions(+)
diff --git a/model/libvirtevents.py b/model/libvirtevents.py
index 2401c5d..890ae31 100644
--- a/model/libvirtevents.py
+++ b/model/libvirtevents.py
@@ -133,3 +133,19 @@ class LibvirtEvents(object):
except libvirt.libvirtError as e:
wok_log.error("Unable to register pool event handler: %s" %
e.message)
+
+ def registerNetworkEvents(self, conn, cb, arg):
+ """
+ Register libvirt events to listen to any network change
+ """
+ net_events = [libvirt.VIR_NETWORK_EVENT_DEFINED,
+ libvirt.VIR_NETWORK_EVENT_STARTED,
+ libvirt.VIR_NETWORK_EVENT_STOPPED,
+ libvirt.VIR_NETWORK_EVENT_UNDEFINED]
+
+ for ev in net_events:
+ try:
+ conn.get().networkEventRegisterAny(None, ev, cb, arg)
+ except libvirt.libvirtError as e:
+ wok_log.error("Unable to register network event handler: %s" %
+ e.message)
diff --git a/model/model.py b/model/model.py
index 97def98..aa63519 100644
--- a/model/model.py
+++ b/model/model.py
@@ -38,6 +38,8 @@ class Model(BaseModel):
self.events.handleEnospc(self.conn)
self.events.registerPoolEvents(self.conn, self._events_handler,
'storages')
+ self.events.registerNetworkEvents(self.conn, self._events_handler,
+ 'networks')
kargs = {'objstore': self.objstore, 'conn': self.conn,
'eventsloop': self.events}
--
2.9.4