summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel P. Berrangé <berrange@redhat.com>2021-10-08 11:23:27 +0100
committerDaniel P. Berrangé <berrange@redhat.com>2021-10-08 11:23:27 +0100
commit13ddf17f838900533f4c4646a3cec2174aa34f12 (patch)
tree0549254a95f57a9e53f6b636c85da28ff6ae0cec
parentaa0286fa6ca422458f206cea499c539f2251e672 (diff)
downloadlibvirt-python-13ddf17f838900533f4c4646a3cec2174aa34f12.tar.gz
Add support for domain event for memory device size changev7.9.0
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
-rwxr-xr-xexamples/event-test.py5
-rw-r--r--libvirt-override-virConnect.py9
-rw-r--r--libvirt-override.c60
3 files changed, 74 insertions, 0 deletions
diff --git a/examples/event-test.py b/examples/event-test.py
index d6b2ccf..8ab4944 100755
--- a/examples/event-test.py
+++ b/examples/event-test.py
@@ -640,6 +640,10 @@ def myDomainEventMemoryFailureCallback(conn: libvirt.virConnect, dom: libvirt.vi
print("myDomainEventMemoryFailureCallback: Domain %s(%s) memory failure recipient %d action %d flags %d" % (
dom.name(), dom.ID(), recipient, action, flags))
+def myDomainEventMemoryDeviceSizeChangeCallback(conn: libvirt.virConnect, dom: libvirt.virDomain, recipient: int, action: int, flags: int, opaque: _T) -> None:
+ print("myDomainEventMemoryDeviceSizeChangeCallback: Domain %s(%s) memory device size change alias %s size %d" % (
+ dom.name(), dom.ID(), alias, size))
+
##########################################################################
# Network events
@@ -793,6 +797,7 @@ def main() -> 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),
+ vc.domainEventRegisterAny(None, libvirt.VIR_DOMAIN_EVENT_ID_MEMORY_DEVICE_SIZE_CHANGE, myDomainEventMemoryDeviceSizeChangeCallback, None),
]
netcallbacks = [
diff --git a/libvirt-override-virConnect.py b/libvirt-override-virConnect.py
index 8fbeaa0..5fc2ee3 100644
--- a/libvirt-override-virConnect.py
+++ b/libvirt-override-virConnect.py
@@ -270,6 +270,15 @@
cb(self, virDomain(self, _obj=dom), recipient, action, flags, opaque)
return 0
+ def _dispatchDomainEventMemoryDeviceSizeChangeCallback(self, dom: 'virDomain', alias: str, size: int, cbData: Dict[str, Any]) -> int:
+ """Dispatches event to python user domain memory device size change event callbacks
+ """
+ cb = cbData["cb"]
+ opaque = cbData["opaque"]
+
+ cb(self, virDomain(self, _obj=dom), alias, size, 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 """
diff --git a/libvirt-override.c b/libvirt-override.c
index 8617999..671d90c 100644
--- a/libvirt-override.c
+++ b/libvirt-override.c
@@ -7340,6 +7340,61 @@ libvirt_virConnectDomainEventMemoryFailureCallback(virConnectPtr conn ATTRIBUTE_
#endif /* VIR_DOMAIN_EVENT_ID_MEMORY_FAILURE */
+#ifdef VIR_DOMAIN_EVENT_ID_MEMORY_DEVICE_SIZE_CHANGE
+static int
+libvirt_virConnectDomainEventMemoryDeviceSizeChangeCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
+ virDomainPtr dom,
+ const char *alias,
+ unsigned long long size,
+ 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*)"_dispatchDomainEventMemoryDeviceSizeChangeCallback",
+ (char*)"OsKO",
+ pyobj_dom, alias, size,
+ 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_DEVICE_SIZE_CHANGE */
+
+
static PyObject *
libvirt_virConnectDomainEventRegisterAny(PyObject *self ATTRIBUTE_UNUSED,
PyObject *args)
@@ -7470,6 +7525,11 @@ libvirt_virConnectDomainEventRegisterAny(PyObject *self ATTRIBUTE_UNUSED,
cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventMemoryFailureCallback);
break;
#endif /* VIR_DOMAIN_EVENT_ID_MEMORY_FAILURE */
+#ifdef VIR_DOMAIN_EVENT_ID_MEMORY_DEVICE_SIZE_CHANGE
+ case VIR_DOMAIN_EVENT_ID_MEMORY_DEVICE_SIZE_CHANGE:
+ cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventMemoryDeviceSizeChangeCallback);
+ break;
+#endif /* VIR_DOMAIN_EVENT_ID_MEMORY_DEVICE_SIZE_CHANGE */
case VIR_DOMAIN_EVENT_ID_LAST:
break;
}