summaryrefslogtreecommitdiffstats
path: root/libvirt-override-virConnect.py
diff options
context:
space:
mode:
authorDaniel P. Berrange <berrange@redhat.com>2010-03-26 13:22:06 +0000
committerDaniel P. Berrange <berrange@redhat.com>2010-04-08 12:41:40 +0100
commit24f9a46106ff5f55bf225867f259573241061719 (patch)
tree1437bd4247f7a2627266d76c5b231059eec2a125 /libvirt-override-virConnect.py
parentbe5c34b75242f68dce33ba08081c46d27eae05bb (diff)
downloadlibvirt-python-split-24f9a46106ff5f55bf225867f259573241061719.tar.gz
libvirt-python-split-24f9a46106ff5f55bf225867f259573241061719.tar.xz
libvirt-python-split-24f9a46106ff5f55bf225867f259573241061719.zip
Fix up python bindings for new event callbacks
The generator was disabled for the new event callbacks, since they need to be hand written. This patch adds the C and python glue to expose the new APIs in the python binding. The python example program is extended to demonstrate of the code * python/libvirt-override.c: Registration and dispatch of events at the C layer * python/libvirt-override-virConnect.py: Python glue for events * examples/domain-events/events-python/event-test.py: Demo use of new event callbacks
Diffstat (limited to 'libvirt-override-virConnect.py')
-rw-r--r--libvirt-override-virConnect.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/libvirt-override-virConnect.py b/libvirt-override-virConnect.py
index 1fdf548..444a499 100644
--- a/libvirt-override-virConnect.py
+++ b/libvirt-override-virConnect.py
@@ -41,3 +41,48 @@
return 0
except AttributeError:
pass
+
+ def dispatchDomainEventLifecycleCallback(self, dom, event, detail, cbData):
+ """Dispatches events to python user domain event callbacks
+ """
+ cb = cbData["cb"]
+ opaque = cbData["opaque"]
+
+ cb(self, virDomain(self, _obj=dom), event, detail, opaque)
+ return 0
+
+ def dispatchDomainEventGenericCallback(self, dom, cbData):
+ """Dispatches events to python user domain event callbacks
+ """
+ try:
+ cb = cbData["cb"]
+ opaque = cbData["opaque"]
+
+ cb(self, virDomain(self, _obj=dom), opaque)
+ return 0
+ except AttributeError:
+ pass
+
+ def domainEventDeregisterAny(self, callbackID):
+ """Removes a Domain Event Callback. De-registering for a
+ domain callback will disable delivery of this event type """
+ try:
+ ret = libvirtmod.virConnectDomainEventDeregisterAny(self._o, callbackID)
+ if ret == -1: raise libvirtError ('virConnectDomainEventDeregisterAny() failed', conn=self)
+ del self.domainEventCallbackID[callbackID]
+ except AttributeError:
+ pass
+
+ def domainEventRegisterAny(self, dom, eventID, cb, opaque):
+ """Adds a Domain Event Callback. Registering for a domain
+ callback will enable delivery of the events """
+ if not hasattr(self, 'domainEventCallbackID'):
+ self.domainEventCallbackID = {}
+ cbData = { "cb": cb, "conn": self, "opaque": opaque }
+ if dom is None:
+ ret = libvirtmod.virConnectDomainEventRegisterAny(self._o, None, eventID, cbData)
+ else:
+ ret = libvirtmod.virConnectDomainEventRegisterAny(self._o, dom._o, eventID, cbData)
+ if ret == -1:
+ raise libvirtError ('virConnectDomainEventRegisterAny() failed', conn=self)
+ self.domainEventCallbackID[ret] = opaque