[PATCH python 1/2] Add support for secret event APIs

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

 



Signed-off-by: Daniel P. Berrange <berrange@xxxxxxxxxx>
---
 generator.py                   |   2 +
 libvirt-override-virConnect.py |  43 +++++++++
 libvirt-override.c             | 203 +++++++++++++++++++++++++++++++++++++++++
 sanitytest.py                  |   3 +
 4 files changed, 251 insertions(+)

diff --git a/generator.py b/generator.py
index afb1d34..e9be8b1 100755
--- a/generator.py
+++ b/generator.py
@@ -528,6 +528,8 @@ skip_function = (
     'virConnectStoragePoolEventDeregisterAny', # overridden in virConnect.py
     'virConnectNodeDeviceEventRegisterAny',   # overridden in virConnect.py
     'virConnectNodeDeviceEventDeregisterAny', # overridden in virConnect.py
+    'virConnectSecretEventRegisterAny',   # overridden in virConnect.py
+    'virConnectSecretEventDeregisterAny', # overridden in virConnect.py
     'virSaveLastError', # We have our own python error wrapper
     'virFreeError', # Only needed if we use virSaveLastError
     'virConnectListAllDomains', # overridden in virConnect.py
diff --git a/libvirt-override-virConnect.py b/libvirt-override-virConnect.py
index fb3d476..d26b480 100644
--- a/libvirt-override-virConnect.py
+++ b/libvirt-override-virConnect.py
@@ -392,6 +392,49 @@
         self.nodeDeviceEventCallbackID[ret] = opaque
         return ret
 
+    def _dispatchSecretEventLifecycleCallback(self, net, event, detail, cbData):
+        """Dispatches events to python user secret lifecycle event callbacks
+        """
+        cb = cbData["cb"]
+        opaque = cbData["opaque"]
+
+        cb(self, virSecret(self, _obj=net), event, detail, opaque)
+        return 0
+
+    def _dispatchSecretEventGEnericCallback(self, net, cbData):
+        """Dispatches events to python user secret generic event callbacks
+        """
+        cb = cbData["cb"]
+        opaque = cbData["opaque"]
+
+        cb(self, virSecret(self, _obj=net), opaque)
+        return 0
+
+    def secretEventDeregisterAny(self, callbackID):
+        """Removes a Secret Event Callback. De-registering for a
+           secret callback will disable delivery of this event type"""
+        try:
+            ret = libvirtmod.virConnectSecretEventDeregisterAny(self._o, callbackID)
+            if ret == -1: raise libvirtError ('virConnectSecretEventDeregisterAny() failed', conn=self)
+            del self.secretEventCallbackID[callbackID]
+        except AttributeError:
+            pass
+
+    def secretEventRegisterAny(self, net, eventID, cb, opaque):
+        """Adds a Secret Event Callback. Registering for a secret
+           callback will enable delivery of the events"""
+        if not hasattr(self, 'secretEventCallbackID'):
+            self.secretEventCallbackID = {}
+        cbData = { "cb": cb, "conn": self, "opaque": opaque }
+        if net is None:
+            ret = libvirtmod.virConnectSecretEventRegisterAny(self._o, None, eventID, cbData)
+        else:
+            ret = libvirtmod.virConnectSecretEventRegisterAny(self._o, net._o, eventID, cbData)
+        if ret == -1:
+            raise libvirtError ('virConnectSecretEventRegisterAny() failed', conn=self)
+        self.secretEventCallbackID[ret] = opaque
+        return ret
+
     def listAllDomains(self, flags=0):
         """List all domains and returns a list of domain objects"""
         ret = libvirtmod.virConnectListAllDomains(self._o, flags)
diff --git a/libvirt-override.c b/libvirt-override.c
index db14244..c15ab2d 100644
--- a/libvirt-override.c
+++ b/libvirt-override.c
@@ -9138,6 +9138,205 @@ libvirt_virConnectNodeDeviceEventDeregisterAny(PyObject *self ATTRIBUTE_UNUSED,
 
 #endif /* LIBVIR_CHECK_VERSION(2, 2, 0)*/
 
+#if LIBVIR_CHECK_VERSION(3, 0, 0)
+static void
+libvirt_virConnectSecretEventFreeFunc(void *opaque)
+{
+    PyObject *pyobj_conn = (PyObject*)opaque;
+    LIBVIRT_ENSURE_THREAD_STATE;
+    Py_DECREF(pyobj_conn);
+    LIBVIRT_RELEASE_THREAD_STATE;
+}
+
+static int
+libvirt_virConnectSecretEventLifecycleCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
+                                               virSecretPtr secret,
+                                               int event,
+                                               int detail,
+                                               void *opaque)
+{
+    PyObject *pyobj_cbData = (PyObject*)opaque;
+    PyObject *pyobj_secret;
+    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 virSecretPtr */
+    virSecretRef(secret);
+    if (!(pyobj_secret = libvirt_virSecretPtrWrap(secret))) {
+        virSecretFree(secret);
+        goto cleanup;
+    }
+    Py_INCREF(pyobj_cbData);
+
+    /* Call the Callback Dispatcher */
+    pyobj_ret = PyObject_CallMethod(pyobj_conn,
+                                    (char*)"_dispatchSecretEventLifecycleCallback",
+                                    (char*)"OiiO",
+                                    pyobj_secret,
+                                    event,
+                                    detail,
+                                    pyobj_cbData);
+
+    Py_DECREF(pyobj_cbData);
+    Py_DECREF(pyobj_secret);
+
+ 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;
+}
+
+static int
+libvirt_virConnectSecretEventGenericCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
+                                             virSecretPtr secret,
+                                             void *opaque)
+{
+    PyObject *pyobj_cbData = (PyObject*)opaque;
+    PyObject *pyobj_secret;
+    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 virSecretPtr */
+    virSecretRef(secret);
+    if (!(pyobj_secret = libvirt_virSecretPtrWrap(secret))) {
+        virSecretFree(secret);
+        goto cleanup;
+    }
+    Py_INCREF(pyobj_cbData);
+
+    /* Call the Callback Dispatcher */
+    pyobj_ret = PyObject_CallMethod(pyobj_conn,
+                                    (char*)"_dispatchSecretEventGenericCallback",
+                                    (char*)"OO",
+                                    pyobj_secret,
+                                    pyobj_cbData);
+
+    Py_DECREF(pyobj_cbData);
+    Py_DECREF(pyobj_secret);
+
+ 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;
+}
+
+static PyObject *
+libvirt_virConnectSecretEventRegisterAny(PyObject *self ATTRIBUTE_UNUSED,
+                                          PyObject *args)
+{
+    PyObject *pyobj_conn;       /* virConnectPtr */
+    PyObject *pyobj_secret;
+    PyObject *pyobj_cbData;     /* hash of callback data */
+    int eventID;
+    virConnectPtr conn;
+    int ret = 0;
+    virConnectSecretEventGenericCallback cb = NULL;
+    virSecretPtr secret;
+
+    if (!PyArg_ParseTuple(args,
+                          (char *) "OOiO:virConnectSecretEventRegisterAny",
+                          &pyobj_conn, &pyobj_secret, &eventID, &pyobj_cbData))
+        return NULL;
+
+    DEBUG("libvirt_virConnectSecretEventRegister(%p %p %d %p) called\n",
+          pyobj_conn, pyobj_secret, eventID, pyobj_cbData);
+    conn = PyvirConnect_Get(pyobj_conn);
+    if (pyobj_secret == Py_None)
+        secret = NULL;
+    else
+        secret = PyvirSecret_Get(pyobj_secret);
+
+    switch ((virSecretEventID) eventID) {
+    case VIR_SECRET_EVENT_ID_LIFECYCLE:
+        cb = VIR_SECRET_EVENT_CALLBACK(libvirt_virConnectSecretEventLifecycleCallback);
+        break;
+
+    case VIR_SECRET_EVENT_ID_VALUE_CHANGED:
+        cb = VIR_SECRET_EVENT_CALLBACK(libvirt_virConnectSecretEventGenericCallback);
+        break;
+
+    case VIR_SECRET_EVENT_ID_LAST:
+        break;
+    }
+
+    if (!cb) {
+        return VIR_PY_INT_FAIL;
+    }
+
+    Py_INCREF(pyobj_cbData);
+
+    LIBVIRT_BEGIN_ALLOW_THREADS;
+    ret = virConnectSecretEventRegisterAny(conn, secret, eventID,
+                                            cb, pyobj_cbData,
+                                            libvirt_virConnectSecretEventFreeFunc);
+    LIBVIRT_END_ALLOW_THREADS;
+
+    if (ret < 0) {
+        Py_DECREF(pyobj_cbData);
+    }
+
+    return libvirt_intWrap(ret);
+}
+
+static PyObject *
+libvirt_virConnectSecretEventDeregisterAny(PyObject *self ATTRIBUTE_UNUSED,
+                                            PyObject *args)
+{
+    PyObject *pyobj_conn;
+    int callbackID;
+    virConnectPtr conn;
+    int ret = 0;
+
+    if (!PyArg_ParseTuple(args, (char *) "Oi:virConnectSecretEventDeregister",
+                          &pyobj_conn, &callbackID))
+        return NULL;
+
+    DEBUG("libvirt_virConnectSecretEventDeregister(%p) called\n", pyobj_conn);
+
+    conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
+
+    LIBVIRT_BEGIN_ALLOW_THREADS;
+
+    ret = virConnectSecretEventDeregisterAny(conn, callbackID);
+
+    LIBVIRT_END_ALLOW_THREADS;
+
+    return libvirt_intWrap(ret);
+}
+#endif /* LIBVIR_CHECK_VERSION(3, 0, 0)*/
+
 /************************************************************************
  *									*
  *			The registration stuff				*
@@ -9357,6 +9556,10 @@ static PyMethodDef libvirtMethods[] = {
     {(char *) "virConnectNodeDeviceEventRegisterAny", libvirt_virConnectNodeDeviceEventRegisterAny, METH_VARARGS, NULL},
     {(char *) "virConnectNodeDeviceEventDeregisterAny", libvirt_virConnectNodeDeviceEventDeregisterAny, METH_VARARGS, NULL},
 #endif /* LIBVIR_CHECK_VERSION(2, 2, 0) */
+#if LIBVIR_CHECK_VERSION(3, 0, 0)
+    {(char *) "virConnectSecretEventRegisterAny", libvirt_virConnectSecretEventRegisterAny, METH_VARARGS, NULL},
+    {(char *) "virConnectSecretEventDeregisterAny", libvirt_virConnectSecretEventDeregisterAny, METH_VARARGS, NULL},
+#endif /* LIBVIR_CHECK_VERSION(3, 0, 0) */
     {NULL, NULL, 0, NULL}
 };
 
diff --git a/sanitytest.py b/sanitytest.py
index 3cfde24..a140ba2 100644
--- a/sanitytest.py
+++ b/sanitytest.py
@@ -179,6 +179,9 @@ for cname in wantfunctions:
     if (name.startswith("virConnectNodeDeviceEvent") and
         name.endswith("Callback")):
         continue
+    if (name.startswith("virConnectSecretEvent") and
+        name.endswith("Callback")):
+        continue
 
 
     # virEvent APIs go into main 'libvirt' namespace not any class
-- 
2.9.3

--
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