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
Setomidor
source share