Commit f59be6d0 authored by Antoine Millet's avatar Antoine Millet

Handle update of devices added/removed from a VM

parent 6c4837c7
......@@ -83,12 +83,20 @@ class KVM(object):
logger.debug('Domains: %s', self.domains)
self.vir_con.domainEventRegister(self.vir_cb, None)
self.vir_cb_id_dev_add = self.vir_con.domainEventRegisterAny(None,
libvirt.VIR_DOMAIN_EVENT_ID_DEVICE_ADDED,
self.vir_cb_devices, None)
self.vir_cb_id_dev_del = self.vir_con.domainEventRegisterAny(None,
libvirt.VIR_DOMAIN_EVENT_ID_DEVICE_REMOVED,
self.vir_cb_devices, None)
def stop(self):
self.vir_event_loop.stop()
# unregister callback
try:
self.vir_con.domainEventDeregister(self.vir_cb)
self.vir_con.domainEventDeregisterAny(self.vir_cb_id_dev_add)
self.vir_con.domainEventDeregisterAny(self.vir_cb_id_dev_del)
except libvirt.libvirtError:
# in case the libvirt connection is broken, it will raise the error
pass
......@@ -167,6 +175,15 @@ class KVM(object):
vm.state = state
self.update_domain_count()
def vir_cb_devices(self, conn, dom, device, opaque):
"""Callback for device add/removed from a domain."""
logger.debug('Received device event on domain %s, dev %s', dom.name(), device)
vm = self.domains.get(dom.name())
if vm is not None:
# Unregister/register VM to update devices list:
self.vm_unregister(vm.name)
self.vm_register(dom)
def vm_register(self, dom, redefine_on_stop=False):
"""Register a VM to the hypervisor object.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment