Skip to content
Snippets Groups Projects
Commit f287d531 authored by Anael Beutot's avatar Anael Beutot
Browse files

VirtEventLoop is now a singleton.

This prevents client libvirt version 0.8.8 to segfault when reseting libvirt
event handlers.
parent ef2e708f
No related branches found
No related tags found
No related merge requests found
......@@ -707,16 +707,6 @@ class Hypervisor(object):
libvirt.registerErrorHandler(self.vir_error_cb, None)
# libvirt event loop abstraction
self.vir_event_loop = VirEventLoop(self.handler.main.evloop)
# This tells libvirt what event loop implementation it
# should use
libvirt.virEventRegisterImpl(
self.vir_event_loop.add_handle,
self.vir_event_loop.update_handle,
self.vir_event_loop.remove_handle,
self.vir_event_loop.add_timer,
self.vir_event_loop.update_timer,
self.vir_event_loop.remove_timer,
)
self.vir_con = libvirt.open('qemu:///system') # currently only support KVM
......
......@@ -6,6 +6,8 @@ from itertools import chain
import pyev
import libvirt
from cloudcontrol.node.utils import Singleton
logger = logging.getLogger(__name__)
......@@ -162,6 +164,9 @@ class EventLoop(object):
It cannot be used from other threads.
"""
__metaclass__ = Singleton
def __init__(self, loop):
"""
:param loop: pyev loop instance
......@@ -179,6 +184,17 @@ class EventLoop(object):
self.handles = dict()
self.timers = dict()
# This tells libvirt what event loop implementation it
# should use
libvirt.virEventRegisterImpl(
self.add_handle,
self.update_handle,
self.remove_handle,
self.add_timer,
self.update_timer,
self.remove_timer,
)
def add_handle(self, fd, events, cb, opaque):
"""Registers a new file handle 'fd', monitoring for 'events' (libvirt
event constants), firing the callback cb() when an event occurs.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment