commit 261117c274a2864366bc6eab7ce601c4837fee7a
Author: Radek Novacek <rnovacek(a)redhat.com>
Date: Wed Jul 11 08:51:44 2012 +0200
Fix event loop to receive migration events
event.py | 11 +----------
virt-who.py | 8 ++++----
virt.py | 4 +++-
3 files changed, 8 insertions(+), 15 deletions(-)
---
diff --git a/event.py b/event.py
index 30940fd..0f035e6 100644
--- a/event.py
+++ b/event.py
@@ -86,8 +86,6 @@ class virEventLoopPure:
def __init__(self):
self.poll = select.poll()
self.pipetrick = os.pipe()
- self.pendingWakeup = False
- self.runningPoll = False
self.nextHandleID = 1
self.nextTimerID = 1
self.handles = []
@@ -161,7 +159,6 @@ class virEventLoopPure:
# these pointless repeated tiny sleeps.
def run_once(self):
sleep = -1
- self.runningPoll = True
next = self.next_timeout()
if next > 0:
now = int(time.time() * 1000)
@@ -178,7 +175,6 @@ class virEventLoopPure:
# telling us to wakup. if so, then discard
# the data just continue
if fd == self.pipetrick[0]:
- self.pendingWakeup = False
data = os.read(fd, 1)
continue
@@ -199,9 +195,6 @@ class virEventLoopPure:
t.set_last_fired(now)
t.dispatch()
- self.runningPoll = False
-
-
# Actually the event loop forever
def run_loop(self):
self.quit = False
@@ -209,9 +202,7 @@ class virEventLoopPure:
self.run_once()
def interrupt(self):
- if self.runningPoll and not self.pendingWakeup:
- self.pendingWakeup = True
- os.write(self.pipetrick[1], 'c')
+ os.write(self.pipetrick[1], 'c')
# Registers a new file handle 'fd', monitoring for 'events'
(libvirt
diff --git a/virt-who.py b/virt-who.py
index ed04792..f154b14 100644
--- a/virt-who.py
+++ b/virt-who.py
@@ -103,7 +103,6 @@ class VirtWho(object):
try:
self.subscriptionManager = SubscriptionManager(self.logger)
self.subscriptionManager.connect()
- self.tryRegisterEventCallback()
except NoOptionError, e:
self.logger.error("Error in reading configuration file
(/etc/rhsm/rhsm.conf)")
# Unability to parse configuration file is fatal error, so we'll quit
@@ -113,6 +112,9 @@ class VirtWho(object):
# virt-who can't work properly without certificate, exitting
sys.exit(5)
+ if self.options.virtType == "libvirt":
+ self.tryRegisterEventCallback()
+
def tryRegisterEventCallback(self):
"""
This method register the handler which listen to guest changes
@@ -124,9 +126,7 @@ class VirtWho(object):
if self.options.background and self.options.virtType == "libvirt":
if self.virt is not None and self.subscriptionManager is not None:
# Send list of virt guests when something changes in libvirt
-
self.virt.domainListChangedCallback(self.subscriptionManager.sendVirtGuests)
- # Register listener for domain changes
- self.virt.virt.domainEventRegister(self.virt.changed, None)
+
self.virt.domainEventRegisterCallback(self.subscriptionManager.sendVirtGuests)
def checkConnections(self):
"""
diff --git a/virt.py b/virt.py
index bbedbf6..d439c30 100644
--- a/virt.py
+++ b/virt.py
@@ -33,6 +33,8 @@ class Virt:
libvirt.registerErrorHandler(lambda ctx, error: None, None)
#self.logger.exception(error), None)
try:
self.virt = libvirt.openReadOnly("")
+ # Register listener for domain changes
+ self.virt.domainEventRegister(self.changed, None)
except libvirt.libvirtError, e:
raise VirtError(str(e))
@@ -84,7 +86,7 @@ class Virt:
l.append(dom)
self.changedCallback(l)
- def domainListChangedCallback(self, callback):
+ def domainEventRegisterCallback(self, callback):
self.changedCallback = callback
def ping(self):
Show replies by date