Can I log event callbacks using the python libvirt module with the QEMU backend?

I would like to write event monitoring code for QEMU domains managed by libvirt. However, when trying to register an event handler, the following error appears:

>>> import libvirt >>> conn = libvirt.openReadOnly('qemu:///system') >>> conn.domainEventRegister(callback, None) libvir: Remote error : this function is not supported by the connection driver: no event support 

(The "callback" in this case is a stub that simply prints its arguments.)

The examples I could find regarding the handling of libvirt events do not seem specific as to which server hypervisors support which functions. Is this expected to work for QEMU backends?

I am running a Fedora 16 system that includes libvirt 0.9.6 and qemu-kvm 0.15.1 .

For people finding themselves here via <searchengine>:

UPDATE 2013-10-04

For many months and several Fedora releases, event-test.py in libvirt git works correctly in Fedora 19.

+7
source share
1 answer

Before registering for events, make sure you register in the libvirt event loop (or configure your own).

A good example of event handling that comes with the libvirt source (a file called event-test.py). I am attaching an example based on this code;

 import libvirt import time import threading def callback(conn, dom, event, detail, opaque): print "EVENT: Domain %s(%s) %s %s" % (dom.name(), dom.ID(), event, detail) eventLoopThread = None def virEventLoopNativeRun(): while True: libvirt.virEventRunDefaultImpl() def virEventLoopNativeStart(): global eventLoopThread libvirt.virEventRegisterDefaultImpl() eventLoopThread = threading.Thread(target=virEventLoopNativeRun, name="libvirtEventLoop") eventLoopThread.setDaemon(True) eventLoopThread.start() if __name__ == '__main__': virEventLoopNativeStart() conn = libvirt.openReadOnly('qemu:///system') conn.domainEventRegister(callback, None) conn.setKeepAlive(5, 3) while conn.isAlive() == 1: time.sleep(1) 

Good luck

// Seto

+8
source

All Articles