[Kimchi-devel] [PATCH] [Kimchi 2/4] Add Events support to VM's Devices attach/detach.
pvital at linux.vnet.ibm.com
pvital at linux.vnet.ibm.com
Thu Apr 14 19:49:35 UTC 2016
From: Paulo Vital <pvital at linux.vnet.ibm.com>
Register libvirt events to handle and add callbacks to log information about
device's add and remove into VMs.
This patch is part of the solution for Kimchi Issue #817
Signed-off-by: Paulo Vital <pvital at linux.vnet.ibm.com>
---
model/vmhostdevs.py | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/model/vmhostdevs.py b/model/vmhostdevs.py
index 5f33d10..c40c5c2 100644
--- a/model/vmhostdevs.py
+++ b/model/vmhostdevs.py
@@ -45,7 +45,9 @@ WINDOW_SIZE_BAR = 0x800000000
class VMHostDevsModel(object):
def __init__(self, **kargs):
self.conn = kargs['conn']
+ self.events = kargs['eventsloop']
self.caps = CapabilitiesModel(**kargs)
+ self._register_device_event()
def get_list(self, vmid):
dom = VMModel.get_vm(vmid, self.conn)
@@ -371,6 +373,36 @@ class VMHostDevsModel(object):
dom.attachDeviceFlags(xmlstr, get_vm_config_flag(dom, mode='all'))
return dev_info['name']
+ def _vm_event_device_added_cb(self, conn, dom, dev, opaque):
+ """
+ Callback to register event when device is added to domain
+ """
+ msg = "Device %s added to domain %s" % (dev, dom.name())
+ wok_log.error(msg)
+
+ def _vm_event_device_removed_cb(self, conn, dom, dev, opaque):
+ """
+ Callback to register event when device is removed from a domain
+ """
+ msg = "Device %s removed from domain %s" % (dev, dom.name())
+ wok_log.error(msg)
+
+ def _register_device_event(self):
+ """
+ Register Libvirt domain events related to add/remove devices.
+ """
+ conn = self.conn.get()
+ dev_events = {'add': [libvirt.VIR_DOMAIN_EVENT_ID_DEVICE_ADDED,
+ self._vm_event_device_added_cb],
+ 'remove':[libvirt.VIR_DOMAIN_EVENT_ID_DEVICE_REMOVED,
+ self._vm_event_device_removed_cb]}
+ try:
+ for event in dev_events.keys():
+ conn.domainEventRegisterAny(None, dev_events[event][0],
+ dev_events[event][1], None)
+ except Exception, e:
+ wok_log.error("Error registering domain event: ", e)
+
class VMHostDevModel(object):
def __init__(self, **kargs):
--
2.5.5
More information about the Kimchi-devel
mailing list