Signed-off-by: Aline Manera <aline.manera(a)gmail.com>
---
model/libvirtevents.py | 19 +++++++++++++++++++
model/model.py | 2 ++
2 files changed, 21 insertions(+)
diff --git a/model/libvirtevents.py b/model/libvirtevents.py
index 890ae31..35fb1d0 100644
--- a/model/libvirtevents.py
+++ b/model/libvirtevents.py
@@ -149,3 +149,22 @@ class LibvirtEvents(object):
except libvirt.libvirtError as e:
wok_log.error("Unable to register network event handler: %s" %
e.message)
+
+ def registerDomainEvents(self, conn, cb, arg):
+ """
+ Register libvirt events to listen to any domain change
+ """
+ net_events = [libvirt.VIR_DOMAIN_EVENT_DEFINED,
+ libvirt.VIR_DOMAIN_EVENT_PMSUSPENDED,
+ libvirt.VIR_DOMAIN_EVENT_RESUMED,
+ libvirt.VIR_DOMAIN_EVENT_STARTED,
+ libvirt.VIR_DOMAIN_EVENT_STOPPED,
+ libvirt.VIR_DOMAIN_EVENT_SUSPENDED,
+ libvirt.VIR_DOMAIN_EVENT_UNDEFINED]
+
+ for ev in net_events:
+ try:
+ conn.get().domainEventRegisterAny(None, ev, cb, arg)
+ except libvirt.libvirtError as e:
+ wok_log.error("Unable to register domain event handler: %s" %
+ e.message)
diff --git a/model/model.py b/model/model.py
index aa63519..a72593f 100644
--- a/model/model.py
+++ b/model/model.py
@@ -40,6 +40,8 @@ class Model(BaseModel):
'storages')
self.events.registerNetworkEvents(self.conn, self._events_handler,
'networks')
+ self.events.registerDomainEvents(self.conn, self._events_handler,
+ 'vms')
kargs = {'objstore': self.objstore, 'conn': self.conn,
'eventsloop': self.events}
--
2.9.4