[python PATCH 2/2] event: Add handler for block threshold event

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Unfortunately python doesn't generate those.
---
 examples/event-test.py         |  4 +++
 libvirt-override-virConnect.py |  9 ++++++
 libvirt-override.c             | 62 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 75 insertions(+)

diff --git a/examples/event-test.py b/examples/event-test.py
index d5af33c..a1105a3 100755
--- a/examples/event-test.py
+++ b/examples/event-test.py
@@ -541,6 +541,9 @@ def myDomainEventDeviceRemovalFailedCallback(conn, dom, dev, opaque):
 def myDomainEventMetadataChangeCallback(conn, dom, mtype, nsuri, opaque):
     print("myDomainEventMetadataChangeCallback: Domain %s(%s) changed metadata mtype=%d nsuri=%s" % (
             dom.name(), dom.ID(), mtype, nsuri))
+def myDomainEventBlockThresholdCallback(conn, dom, dev, path, threshold, excess, opaque):
+    print("myDomainEventBlockThresholdCallback: Domain %s(%s) block device %s(%s) threshold %d exceeded by %d" % (
+            dom.name(), dom.ID(), dev, path, threshold, excess))

 ##########################################################################
 # Network events
@@ -710,6 +713,7 @@ def main():
     vc.domainEventRegisterAny(None, libvirt.VIR_DOMAIN_EVENT_ID_JOB_COMPLETED, myDomainEventJobCompletedCallback, None)
     vc.domainEventRegisterAny(None, libvirt.VIR_DOMAIN_EVENT_ID_DEVICE_REMOVAL_FAILED, myDomainEventDeviceRemovalFailedCallback, None)
     vc.domainEventRegisterAny(None, libvirt.VIR_DOMAIN_EVENT_ID_METADATA_CHANGE, myDomainEventMetadataChangeCallback, None)
+    vc.domainEventRegisterAny(None, libvirt.VIR_DOMAIN_EVENT_ID_BLOCK_THRESHOLD, myDomainEventBlockThresholdCallback, None)

     vc.networkEventRegisterAny(None, libvirt.VIR_NETWORK_EVENT_ID_LIFECYCLE, myNetworkEventLifecycleCallback, None)

diff --git a/libvirt-override-virConnect.py b/libvirt-override-virConnect.py
index 35009bb..f26e65a 100644
--- a/libvirt-override-virConnect.py
+++ b/libvirt-override-virConnect.py
@@ -252,6 +252,15 @@
         cb(self, virDomain(self, _obj=dom), mtype, nsuri, opaque)
         return 0

+    def _dispatchDomainEventBlockThresholdCallback(self, dom, dev, path, threshold, excess, cbData):
+        """Dispatches event to python user domain block device threshold event callbacks
+        """
+        cb = cbData["cb"]
+        opaque = cbData["opaque"]
+
+        cb(self, virDomain(self, _obj=dom), dev, path, threshold, excess, opaque)
+        return 0
+
     def domainEventDeregisterAny(self, callbackID):
         """Removes a Domain Event Callback. De-registering for a
            domain callback will disable delivery of this event type """
diff --git a/libvirt-override.c b/libvirt-override.c
index 9e40f00..93c7ef0 100644
--- a/libvirt-override.c
+++ b/libvirt-override.c
@@ -6932,6 +6932,63 @@ libvirt_virConnectDomainEventMetadataChangeCallback(virConnectPtr conn ATTRIBUTE
 }
 #endif /* VIR_DOMAIN_EVENT_ID_METADATA_CHANGE */

+#ifdef VIR_DOMAIN_EVENT_ID_BLOCK_THRESHOLD
+static int
+libvirt_virConnectDomainEventBlockThresholdCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
+                                                    virDomainPtr dom,
+                                                    const char *dev,
+                                                    const char *path,
+                                                    unsigned long long threshold,
+                                                    unsigned long long excess,
+                                                    void *opaque)
+{
+    PyObject *pyobj_cbData = (PyObject*)opaque;
+    PyObject *pyobj_dom;
+    PyObject *pyobj_ret = NULL;
+    PyObject *pyobj_conn;
+    PyObject *dictKey;
+    int ret = -1;
+
+    LIBVIRT_ENSURE_THREAD_STATE;
+
+    if (!(dictKey = libvirt_constcharPtrWrap("conn")))
+        goto cleanup;
+    pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
+    Py_DECREF(dictKey);
+
+    /* Create a python instance of this virDomainPtr */
+    virDomainRef(dom);
+    if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
+        virDomainFree(dom);
+        goto cleanup;
+    }
+    Py_INCREF(pyobj_cbData);
+
+    /* Call the Callback Dispatcher */
+    pyobj_ret = PyObject_CallMethod(pyobj_conn,
+                                    (char*)"_dispatchDomainEventBlockThresholdCallback",
+                                    (char*)"OssiiO",
+                                    pyobj_dom, dev, path, threshold, excess,
+                                    pyobj_cbData);
+
+    Py_DECREF(pyobj_cbData);
+    Py_DECREF(pyobj_dom);
+
+ cleanup:
+    if (!pyobj_ret) {
+        DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
+        PyErr_Print();
+    } else {
+        Py_DECREF(pyobj_ret);
+        ret = 0;
+    }
+
+    LIBVIRT_RELEASE_THREAD_STATE;
+    return ret;
+}
+#endif /* VIR_DOMAIN_EVENT_ID_BLOCK_THRESHOLD */
+
+
 static PyObject *
 libvirt_virConnectDomainEventRegisterAny(PyObject *self ATTRIBUTE_UNUSED,
                                          PyObject *args)
@@ -7052,6 +7109,11 @@ libvirt_virConnectDomainEventRegisterAny(PyObject *self ATTRIBUTE_UNUSED,
         cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventMetadataChangeCallback);
         break;
 #endif /* VIR_DOMAIN_EVENT_ID_METADATA_CHANGE */
+#ifdef VIR_DOMAIN_EVENT_ID_BLOCK_THRESHOLD
+    case VIR_DOMAIN_EVENT_ID_BLOCK_THRESHOLD:
+        cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventBlockThresholdCallback);
+        break;
+#endif /* VIR_DOMAIN_EVENT_ID_BLOCK_THRESHOLD */
     case VIR_DOMAIN_EVENT_ID_LAST:
         break;
     }
-- 
2.12.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]
  Powered by Linux