diff options
author | Daniel P. Berrange <berrange@redhat.com> | 2016-06-24 18:37:09 +0100 |
---|---|---|
committer | Daniel P. Berrange <berrange@redhat.com> | 2016-06-24 21:49:09 +0100 |
commit | cb84e36cb3af64a84d2346b590c757b32eadb4f2 (patch) | |
tree | 3dad53077cba346816bc3f2f42b877ff7e10c1bb | |
parent | 923a2d9b8651f4cc36661583f93e6bfa6af35075 (diff) | |
download | libvirt-python-cb84e36cb3af64a84d2346b590c757b32eadb4f2.tar.gz |
Add support for storage pool refesh callbackv2.0.0
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
-rwxr-xr-x | examples/event-test.py | 6 | ||||
-rw-r--r-- | libvirt-override-virConnect.py | 10 | ||||
-rw-r--r-- | libvirt-override.c | 56 |
3 files changed, 70 insertions, 2 deletions
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..8f21cfd 100644 --- a/libvirt-override.c +++ b/libvirt-override.c @@ -8799,7 +8799,7 @@ libvirt_virConnectStoragePoolEventLifecycleCallback(virConnectPtr conn ATTRIBUTE pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey); Py_DECREF(dictKey); - /* Create a python instance of this virNetworkPtr */ + /* Create a python instance of this virStoragePoolPtr */ virStoragePoolRef(pool); if (!(pyobj_pool = libvirt_virStoragePoolPtrWrap(pool))) { virStoragePoolFree(pool); @@ -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 virStoragePoolPtr */ + 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; } |