sjpp / rpms / libvirt-python

Forked from rpms/libvirt-python 3 years ago
Clone

Blame SOURCES/libvirt-python-implement-new-tunable-event.patch

b79911
From 0f7171da1be3b37613bb284789697888c2aef7bd Mon Sep 17 00:00:00 2001
b79911
Message-Id: <0f7171da1be3b37613bb284789697888c2aef7bd@dist-git>
b79911
From: Pavel Hrdina <phrdina@redhat.com>
b79911
Date: Tue, 30 Sep 2014 19:25:05 +0200
b79911
Subject: [PATCH] implement new tunable event
b79911
b79911
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1147639
b79911
b79911
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
b79911
(cherry picked from commit 714aa155e84c4b55e37b5554c9dbc5e7ddd61cd3)
b79911
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
b79911
---
b79911
 examples/event-test.py         |  3 ++
b79911
 libvirt-override-virConnect.py |  9 ++++++
b79911
 libvirt-override.c             | 64 ++++++++++++++++++++++++++++++++++++++++++
b79911
 3 files changed, 76 insertions(+)
b79911
b79911
diff --git a/examples/event-test.py b/examples/event-test.py
b79911
index cd85de3..be7a7d4 100644
b79911
--- a/examples/event-test.py
b79911
+++ b/examples/event-test.py
b79911
@@ -515,6 +515,8 @@ def myDomainEventDeviceRemovedCallback(conn, dom, dev, opaque):
b79911
             dom.name(), dom.ID(), dev))
b79911
 def myDomainEventBlockJob2Callback(conn, dom, disk, type, status, opaque):
b79911
     print("myDomainEventBlockJob2Callback: Domain %s(%s) %s on disk %s %s" % (dom.name(), dom.ID(), blockJobTypeToString(type), disk, blockJobStatusToString(status)))
b79911
+def myDomainEventTunableCallback(conn, dom, params, opaque):
b79911
+    print("myDomainEventTunableCallback: Domain %s(%s) %s" % (dom.name(), dom.ID(), params))
b79911
 
b79911
 ##########################################################################
b79911
 # Network events
b79911
@@ -624,6 +626,7 @@ def main():
b79911
     vc.domainEventRegisterAny(None, libvirt.VIR_DOMAIN_EVENT_ID_PMSUSPEND_DISK, myDomainEventPMSuspendDiskCallback, None)
b79911
     vc.domainEventRegisterAny(None, libvirt.VIR_DOMAIN_EVENT_ID_DEVICE_REMOVED, myDomainEventDeviceRemovedCallback, None)
b79911
     vc.domainEventRegisterAny(None, libvirt.VIR_DOMAIN_EVENT_ID_BLOCK_JOB_2, myDomainEventBlockJob2Callback, None)
b79911
+    vc.domainEventRegisterAny(None, libvirt.VIR_DOMAIN_EVENT_ID_TUNABLE, myDomainEventTunableCallback, None)
b79911
 
b79911
     vc.networkEventRegisterAny(None, libvirt.VIR_NETWORK_EVENT_ID_LIFECYCLE, myNetworkEventLifecycleCallback, None)
b79911
 
b79911
diff --git a/libvirt-override-virConnect.py b/libvirt-override-virConnect.py
b79911
index 218f266..ffb6d6b 100644
b79911
--- a/libvirt-override-virConnect.py
b79911
+++ b/libvirt-override-virConnect.py
b79911
@@ -188,6 +188,15 @@
b79911
         cb(self, virDomain(self, _obj=dom), devAlias, opaque)
b79911
         return 0
b79911
 
b79911
+    def _dispatchDomainEventTunableCallback(self, dom, params, cbData):
b79911
+        """Dispatches event to python user domain tunable event callbacks
b79911
+        """
b79911
+        cb = cbData["cb"]
b79911
+        opaque = cbData["opaque"]
b79911
+
b79911
+        cb(self, virDomain(self, _obj=dom), params, opaque)
b79911
+        return 0
b79911
+
b79911
     def domainEventDeregisterAny(self, callbackID):
b79911
         """Removes a Domain Event Callback. De-registering for a
b79911
            domain callback will disable delivery of this event type """
b79911
diff --git a/libvirt-override.c b/libvirt-override.c
b79911
index 2dbe339..d94c292 100644
b79911
--- a/libvirt-override.c
b79911
+++ b/libvirt-override.c
b79911
@@ -6506,6 +6506,65 @@ libvirt_virConnectDomainEventDeviceRemovedCallback(virConnectPtr conn ATTRIBUTE_
b79911
 }
b79911
 #endif /* LIBVIR_CHECK_VERSION(1, 1, 1) */
b79911
 
b79911
+#if LIBVIR_CHECK_VERSION(1, 2, 9)
b79911
+static int
b79911
+libvirt_virConnectDomainEventTunableCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
b79911
+                                             virDomainPtr dom,
b79911
+                                             virTypedParameterPtr params,
b79911
+                                             int nparams,
b79911
+                                             void *opaque)
b79911
+{
b79911
+    PyObject *pyobj_cbData = (PyObject*)opaque;
b79911
+    PyObject *pyobj_dom;
b79911
+    PyObject *pyobj_ret = NULL;
b79911
+    PyObject *pyobj_conn;
b79911
+    PyObject *dictKey;
b79911
+    PyObject *pyobj_dict = NULL;
b79911
+    int ret = -1;
b79911
+
b79911
+    LIBVIRT_ENSURE_THREAD_STATE;
b79911
+
b79911
+    pyobj_dict = getPyVirTypedParameter(params, nparams);
b79911
+    if (!pyobj_dict)
b79911
+        goto cleanup;
b79911
+
b79911
+    if (!(dictKey = libvirt_constcharPtrWrap("conn")))
b79911
+        goto cleanup;
b79911
+    pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
b79911
+    Py_DECREF(dictKey);
b79911
+
b79911
+    /* Create a python instance of this virDomainPtr */
b79911
+    virDomainRef(dom);
b79911
+    if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
b79911
+        virDomainFree(dom);
b79911
+        goto cleanup;
b79911
+    }
b79911
+    Py_INCREF(pyobj_cbData);
b79911
+
b79911
+    /* Call the Callback Dispatcher */
b79911
+    pyobj_ret = PyObject_CallMethod(pyobj_conn,
b79911
+                                    (char*)"_dispatchDomainEventTunableCallback",
b79911
+                                    (char*)"OOO",
b79911
+                                    pyobj_dom, pyobj_dict, pyobj_cbData);
b79911
+
b79911
+    Py_DECREF(pyobj_cbData);
b79911
+    Py_DECREF(pyobj_dom);
b79911
+
b79911
+ cleanup:
b79911
+    if (!pyobj_ret) {
b79911
+        DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
b79911
+        PyErr_Print();
b79911
+        Py_XDECREF(pyobj_dict);
b79911
+    } else {
b79911
+        Py_DECREF(pyobj_ret);
b79911
+        ret = 0;
b79911
+    }
b79911
+
b79911
+    LIBVIRT_RELEASE_THREAD_STATE;
b79911
+    return ret;
b79911
+
b79911
+}
b79911
+#endif /* LIBVIR_CHECK_VERSION(1, 2, 9) */
b79911
 
b79911
 static PyObject *
b79911
 libvirt_virConnectDomainEventRegisterAny(ATTRIBUTE_UNUSED PyObject *self,
b79911
@@ -6594,6 +6653,11 @@ libvirt_virConnectDomainEventRegisterAny(ATTRIBUTE_UNUSED PyObject *self,
b79911
         cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventDeviceRemovedCallback);
b79911
         break;
b79911
 #endif /* LIBVIR_CHECK_VERSION(1, 1, 1) */
b79911
+#if LIBVIR_CHECK_VERSION(1, 2, 9)
b79911
+    case VIR_DOMAIN_EVENT_ID_TUNABLE:
b79911
+        cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventTunableCallback);
b79911
+        break;
b79911
+#endif /* LIBVIR_CHECK_VERSION(1, 2, 9) */
b79911
     case VIR_DOMAIN_EVENT_ID_LAST:
b79911
         break;
b79911
     }
b79911
-- 
b79911
2.1.3
b79911