mirror of
https://gitlab.com/libvirt/libvirt-python.git
synced 2025-08-02 04:21:59 +03:00
Add support for memory failure event callbacks
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
@ -636,6 +636,10 @@ def myDomainEventBlockThresholdCallback(conn: libvirt.virConnect, dom: libvirt.v
|
||||
print("myDomainEventBlockThresholdCallback: Domain %s(%s) block device %s(%s) threshold %d exceeded by %d" % (
|
||||
dom.name(), dom.ID(), dev, path, threshold, excess))
|
||||
|
||||
def myDomainEventMemoryFailureCallback(conn: libvirt.virConnect, dom: libvirt.virDomain, recipient: int, action: int, flags: int, opaque: _T) -> None:
|
||||
print("myDomainEventMemoryFailureCallback: Domain %s(%s) memory failure recipient %d action %d flags %d" % (
|
||||
dom.name(), dom.ID(), recipient, action, flags))
|
||||
|
||||
|
||||
##########################################################################
|
||||
# Network events
|
||||
@ -788,6 +792,7 @@ def main() -> None:
|
||||
vc.domainEventRegisterAny(None, libvirt.VIR_DOMAIN_EVENT_ID_DEVICE_REMOVAL_FAILED, myDomainEventDeviceRemovalFailedCallback, None),
|
||||
vc.domainEventRegisterAny(None, libvirt.VIR_DOMAIN_EVENT_ID_METADATA_CHANGE, myDomainEventMetadataChangeCallback, None),
|
||||
vc.domainEventRegisterAny(None, libvirt.VIR_DOMAIN_EVENT_ID_BLOCK_THRESHOLD, myDomainEventBlockThresholdCallback, None),
|
||||
vc.domainEventRegisterAny(None, libvirt.VIR_DOMAIN_EVENT_ID_MEMORY_FAILURE, myDomainEventMemoryFailureCallback, None),
|
||||
]
|
||||
|
||||
netcallbacks = [
|
||||
|
@ -261,6 +261,15 @@
|
||||
cb(self, virDomain(self, _obj=dom), dev, path, threshold, excess, opaque)
|
||||
return 0
|
||||
|
||||
def _dispatchDomainEventMemoryFailureCallback(self, dom: 'virDomain', recipient: int, action: int, flags: int, cbData: Dict[str, Any]) -> int:
|
||||
"""Dispatches event to python user domain memory failure event callbacks
|
||||
"""
|
||||
cb = cbData["cb"]
|
||||
opaque = cbData["opaque"]
|
||||
|
||||
cb(self, virDomain(self, _obj=dom), recipient, action, flags, opaque)
|
||||
return 0
|
||||
|
||||
def domainEventDeregisterAny(self, callbackID: int) -> None:
|
||||
"""Removes a Domain Event Callback. De-registering for a
|
||||
domain callback will disable delivery of this event type """
|
||||
|
@ -7254,6 +7254,62 @@ libvirt_virConnectDomainEventBlockThresholdCallback(virConnectPtr conn ATTRIBUTE
|
||||
#endif /* VIR_DOMAIN_EVENT_ID_BLOCK_THRESHOLD */
|
||||
|
||||
|
||||
#ifdef VIR_DOMAIN_EVENT_ID_MEMORY_FAILURE
|
||||
static int
|
||||
libvirt_virConnectDomainEventMemoryFailureCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
|
||||
virDomainPtr dom,
|
||||
int recipient,
|
||||
int action,
|
||||
unsigned int flags,
|
||||
void *opaque)
|
||||
{
|
||||
PyObject *pyobj_cbData = (PyObject*)opaque;
|
||||
PyObject *pyobj_dom;
|
||||
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 virDomainPtr */
|
||||
virDomainRef(dom);
|
||||
if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
|
||||
virDomainFree(dom);
|
||||
goto cleanup;
|
||||
}
|
||||
Py_INCREF(pyobj_cbData);
|
||||
|
||||
/* Call the Callback Dispatcher */
|
||||
pyobj_ret = PyObject_CallMethod(pyobj_conn,
|
||||
(char*)"_dispatchDomainEventMemoryFailureCallback",
|
||||
(char*)"OiiiO",
|
||||
pyobj_dom, recipient, action, flags,
|
||||
pyobj_cbData);
|
||||
|
||||
Py_DECREF(pyobj_cbData);
|
||||
Py_DECREF(pyobj_dom);
|
||||
|
||||
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;
|
||||
}
|
||||
#endif /* VIR_DOMAIN_EVENT_ID_MEMORY_FAILURE */
|
||||
|
||||
|
||||
static PyObject *
|
||||
libvirt_virConnectDomainEventRegisterAny(PyObject *self ATTRIBUTE_UNUSED,
|
||||
PyObject *args)
|
||||
@ -7379,6 +7435,11 @@ libvirt_virConnectDomainEventRegisterAny(PyObject *self ATTRIBUTE_UNUSED,
|
||||
cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventBlockThresholdCallback);
|
||||
break;
|
||||
#endif /* VIR_DOMAIN_EVENT_ID_BLOCK_THRESHOLD */
|
||||
#ifdef VIR_DOMAIN_EVENT_ID_MEMORY_FAILURE
|
||||
case VIR_DOMAIN_EVENT_ID_MEMORY_FAILURE:
|
||||
cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventMemoryFailureCallback);
|
||||
break;
|
||||
#endif /* VIR_DOMAIN_EVENT_ID_MEMORY_FAILURE */
|
||||
case VIR_DOMAIN_EVENT_ID_LAST:
|
||||
break;
|
||||
}
|
||||
|
Reference in New Issue
Block a user