Signed-off-by: Daniel P. Berrange <berrange@xxxxxxxxxx> --- examples/event-test.py | 6 ++++- libvirt-override-virConnect.py | 10 ++++++++ libvirt-override.c | 54 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 1 deletion(-) diff --git a/examples/event-test.py b/examples/event-test.py index 241369b..f0341b5 100755 --- a/examples/event-test.py +++ b/examples/event-test.py @@ -572,7 +572,6 @@ def storageEventToString(event): "Undefined", "Started", "Stopped", - "Refreshed", ) return storageEventStrings[event] @@ -581,6 +580,9 @@ def myStoragePoolEventLifecycleCallback(conn, pool, event, detail, opaque): storageEventToString(event), detail)) +def myStoragePoolEventRefreshCallback(conn, pool, event, detail, opaque): + print("myStoragePoolEventRefreshCallback: Storage pool %s" % pool.name()) + ########################################################################## # Set up and run the program ########################################################################## @@ -672,7 +674,9 @@ def main(): vc.domainEventRegisterAny(None, libvirt.VIR_DOMAIN_EVENT_ID_DEVICE_REMOVAL_FAILED, myDomainEventDeviceRemovalFailedCallback, None) vc.networkEventRegisterAny(None, libvirt.VIR_NETWORK_EVENT_ID_LIFECYCLE, myNetworkEventLifecycleCallback, None) + vc.storagePoolEventRegisterAny(None, libvirt.VIR_STORAGE_POOL_EVENT_ID_LIFECYCLE, myStoragePoolEventLifecycleCallback, None) + vc.storagePoolEventRegisterAny(None, libvirt.VIR_STORAGE_POOL_EVENT_ID_REFRESH, myStoragePoolEventRefreshCallback, None) vc.setKeepAlive(5, 3) diff --git a/libvirt-override-virConnect.py b/libvirt-override-virConnect.py index 1aaa586..b085b07 100644 --- a/libvirt-override-virConnect.py +++ b/libvirt-override-virConnect.py @@ -312,6 +312,16 @@ cb(self, virStoragePool(self, _obj=pool), event, detail, opaque) return 0 + def _dispatchStoragePoolEventGenericCallback(self, pool, cbData): + """Dispatches events to python user storage pool + generic event callbacks + """ + cb = cbData["cb"] + opaque = cbData["opaque"] + + cb(self, virStoragePool(self, _obj=pool), opaque) + return 0 + def storagePoolEventDeregisterAny(self, callbackID): """Removes a Storage Pool Event Callback. De-registering for a storage pool callback will disable delivery of this event type""" diff --git a/libvirt-override.c b/libvirt-override.c index 4734b7e..79e3d30 100644 --- a/libvirt-override.c +++ b/libvirt-override.c @@ -8832,6 +8832,56 @@ libvirt_virConnectStoragePoolEventLifecycleCallback(virConnectPtr conn ATTRIBUTE return ret; } +static int +libvirt_virConnectStoragePoolEventGenericCallback(virConnectPtr conn ATTRIBUTE_UNUSED, + virStoragePoolPtr pool, + void *opaque) +{ + PyObject *pyobj_cbData = (PyObject*)opaque; + PyObject *pyobj_pool; + 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 virNetworkPtr */ + virStoragePoolRef(pool); + if (!(pyobj_pool = libvirt_virStoragePoolPtrWrap(pool))) { + virStoragePoolFree(pool); + goto cleanup; + } + Py_INCREF(pyobj_cbData); + + /* Call the Callback Dispatcher */ + pyobj_ret = PyObject_CallMethod(pyobj_conn, + (char*)"_dispatchStoragePoolEventGenericCallback", + (char*)"OiiO", + pyobj_pool, + pyobj_cbData); + + Py_DECREF(pyobj_cbData); + Py_DECREF(pyobj_pool); + + 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_virConnectStoragePoolEventRegisterAny(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) @@ -8863,6 +8913,10 @@ libvirt_virConnectStoragePoolEventRegisterAny(PyObject *self ATTRIBUTE_UNUSED, cb = VIR_STORAGE_POOL_EVENT_CALLBACK(libvirt_virConnectStoragePoolEventLifecycleCallback); break; + case VIR_STORAGE_POOL_EVENT_ID_REFRESH: + cb = VIR_STORAGE_POOL_EVENT_CALLBACK(libvirt_virConnectStoragePoolEventGenericCallback); + break; + case VIR_STORAGE_POOL_EVENT_ID_LAST: break; } -- 2.7.4 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list