mirror of
https://gitlab.com/libvirt/libvirt-python.git
synced 2025-11-26 16:23:47 +03:00
Add support for storage pool refesh callback
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
@@ -572,7 +572,6 @@ def storageEventToString(event):
|
|||||||
"Undefined",
|
"Undefined",
|
||||||
"Started",
|
"Started",
|
||||||
"Stopped",
|
"Stopped",
|
||||||
"Refreshed",
|
|
||||||
)
|
)
|
||||||
return storageEventStrings[event]
|
return storageEventStrings[event]
|
||||||
|
|
||||||
@@ -581,6 +580,9 @@ def myStoragePoolEventLifecycleCallback(conn, pool, event, detail, opaque):
|
|||||||
storageEventToString(event),
|
storageEventToString(event),
|
||||||
detail))
|
detail))
|
||||||
|
|
||||||
|
def myStoragePoolEventRefreshCallback(conn, pool, event, detail, opaque):
|
||||||
|
print("myStoragePoolEventRefreshCallback: Storage pool %s" % pool.name())
|
||||||
|
|
||||||
##########################################################################
|
##########################################################################
|
||||||
# Set up and run the program
|
# 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.domainEventRegisterAny(None, libvirt.VIR_DOMAIN_EVENT_ID_DEVICE_REMOVAL_FAILED, myDomainEventDeviceRemovalFailedCallback, None)
|
||||||
|
|
||||||
vc.networkEventRegisterAny(None, libvirt.VIR_NETWORK_EVENT_ID_LIFECYCLE, myNetworkEventLifecycleCallback, 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_LIFECYCLE, myStoragePoolEventLifecycleCallback, None)
|
||||||
|
vc.storagePoolEventRegisterAny(None, libvirt.VIR_STORAGE_POOL_EVENT_ID_REFRESH, myStoragePoolEventRefreshCallback, None)
|
||||||
|
|
||||||
vc.setKeepAlive(5, 3)
|
vc.setKeepAlive(5, 3)
|
||||||
|
|
||||||
|
|||||||
@@ -312,6 +312,16 @@
|
|||||||
cb(self, virStoragePool(self, _obj=pool), event, detail, opaque)
|
cb(self, virStoragePool(self, _obj=pool), event, detail, opaque)
|
||||||
return 0
|
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):
|
def storagePoolEventDeregisterAny(self, callbackID):
|
||||||
"""Removes a Storage Pool Event Callback. De-registering for a
|
"""Removes a Storage Pool Event Callback. De-registering for a
|
||||||
storage pool callback will disable delivery of this event type"""
|
storage pool callback will disable delivery of this event type"""
|
||||||
|
|||||||
@@ -8799,7 +8799,7 @@ libvirt_virConnectStoragePoolEventLifecycleCallback(virConnectPtr conn ATTRIBUTE
|
|||||||
pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
|
pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
|
||||||
Py_DECREF(dictKey);
|
Py_DECREF(dictKey);
|
||||||
|
|
||||||
/* Create a python instance of this virNetworkPtr */
|
/* Create a python instance of this virStoragePoolPtr */
|
||||||
virStoragePoolRef(pool);
|
virStoragePoolRef(pool);
|
||||||
if (!(pyobj_pool = libvirt_virStoragePoolPtrWrap(pool))) {
|
if (!(pyobj_pool = libvirt_virStoragePoolPtrWrap(pool))) {
|
||||||
virStoragePoolFree(pool);
|
virStoragePoolFree(pool);
|
||||||
@@ -8832,6 +8832,56 @@ libvirt_virConnectStoragePoolEventLifecycleCallback(virConnectPtr conn ATTRIBUTE
|
|||||||
return ret;
|
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 *
|
static PyObject *
|
||||||
libvirt_virConnectStoragePoolEventRegisterAny(PyObject *self ATTRIBUTE_UNUSED,
|
libvirt_virConnectStoragePoolEventRegisterAny(PyObject *self ATTRIBUTE_UNUSED,
|
||||||
PyObject *args)
|
PyObject *args)
|
||||||
@@ -8863,6 +8913,10 @@ libvirt_virConnectStoragePoolEventRegisterAny(PyObject *self ATTRIBUTE_UNUSED,
|
|||||||
cb = VIR_STORAGE_POOL_EVENT_CALLBACK(libvirt_virConnectStoragePoolEventLifecycleCallback);
|
cb = VIR_STORAGE_POOL_EVENT_CALLBACK(libvirt_virConnectStoragePoolEventLifecycleCallback);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case VIR_STORAGE_POOL_EVENT_ID_REFRESH:
|
||||||
|
cb = VIR_STORAGE_POOL_EVENT_CALLBACK(libvirt_virConnectStoragePoolEventGenericCallback);
|
||||||
|
break;
|
||||||
|
|
||||||
case VIR_STORAGE_POOL_EVENT_ID_LAST:
|
case VIR_STORAGE_POOL_EVENT_ID_LAST:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user