1
0
mirror of https://gitlab.com/libvirt/libvirt-python.git synced 2025-07-29 19:41:52 +03:00

Add support for storage pool refesh callback

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrange
2016-06-24 18:37:09 +01:00
parent 923a2d9b86
commit cb84e36cb3
3 changed files with 70 additions and 2 deletions

View File

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

View File

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

View File

@ -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;
}