Issue
newVM
is a function that creates new VM. For every guest VM the event callback function is being executed 2 times though the timer callback is executed correctly only one time at every interval. I am not able to figure out the reason for the same
eventLoopThread = None
libvirt.virEventRegisterDefaultImpl()
def virEventLoopNativeStart():
global eventLoopThread
eventLoopThread = threading.Thread(target=virEventLoopNativeRun, name="libvirtEventLoop")
eventLoopThread.setDaemon(True)
eventLoopThread.start()
def domainEventCallback(conn, dom, event, detail, opaque):
print(" event callback %s %s %s", event, dom.name(), dom.state())
def domainTimeoutCalllback(timer, opaque):
print(" Timeout ")
def virEventLoopNativeRun():
while True:
libvirt.virEventRunDefaultImpl()
virEventLoopNativeStart()
conn = libvirt.open('qemu:///system')
if conn == None:
print('Failed to open connection to qemu:///system', file=sys.stderr)
exit(1)
conn.domainEventRegister(domainEventCallback, None)
conn.setKeepAlive(5, 3)
def newVM(xmldata): #xmldata is XML to define guest machine
try:
conn = libvirt.open('qemu:///system')
if conn == None:
print('Failed to open connection to qemu:///system', file=sys.stderr)
exit(1)
dom = conn.defineXML(xmldata)
if dom == None:
print('Failed to define a domain from an XML definition.', file=sys.stderr)
exit(1)
if dom.create() < 0:
print('Can not boot guest domain.', file=sys.stderr)
exit(1)
libvirt.virEventAddTimeout(runTime, domainTimeoutCalllback, None)
except libvirt.libvirtError:
abort(404, "Libvirt could not be configured")
Solution
It is normal for the domain event callback to be invoked many times during startup - it will be given different arguments values each time.
Answered By - DanielB
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.