diff options
author | Martin Kletzander <mkletzan@redhat.com> | 2012-10-12 21:13:39 +0200 |
---|---|---|
committer | Martin Kletzander <mkletzan@redhat.com> | 2012-10-15 12:09:10 +0200 |
commit | 4248becb86df45d87e6a641d19cbe29a8ef94cf5 (patch) | |
tree | 38c2a0d962b831bbf0501b78a25fdf993792fd97 | |
parent | c360b84ba0d464c06d0e617ed753a71a84e8e8ee (diff) | |
download | libvirt-python-4248becb86df45d87e6a641d19cbe29a8ef94cf5.tar.gz |
Add support for SUSPEND_DISK event
This patch adds support for SUSPEND_DISK event; both lifecycle and
separated. The support is added for QEMU, machines are changed to
PMSUSPENDED, but as QEMU sends SHUTDOWN afterwards, the state changes
to shut-off. This and much more needs to be done in order for libvirt
to work with transient devices, wake-ups etc. This patch is not
aiming for that functionality.
-rw-r--r-- | libvirt-override-virConnect.py | 9 | ||||
-rw-r--r-- | libvirt-override.c | 50 |
2 files changed, 59 insertions, 0 deletions
diff --git a/libvirt-override-virConnect.py b/libvirt-override-virConnect.py index 6bec66d..cb8d892 100644 --- a/libvirt-override-virConnect.py +++ b/libvirt-override-virConnect.py @@ -170,6 +170,15 @@ cb(self, virDomain(self, _obj=dom), actual, opaque) return 0 + def _dispatchDomainEventPMSuspendDiskCallback(self, dom, reason, cbData): + """Dispatches event to python user domain pmsuspend-disk event callbacks + """ + cb = cbData["cb"] + opaque = cbData["opaque"] + + cb(self, virDomain(self, _obj=dom), reason, opaque) + return 0; + def domainEventDeregisterAny(self, callbackID): """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 81099b1..83dc925 100644 --- a/libvirt-override.c +++ b/libvirt-override.c @@ -5812,6 +5812,53 @@ libvirt_virConnectDomainEventBalloonChangeCallback(virConnectPtr conn ATTRIBUTE_ return ret; } +static int +libvirt_virConnectDomainEventPMSuspendDiskCallback(virConnectPtr conn ATTRIBUTE_UNUSED, + virDomainPtr dom, + int reason, + void *opaque) +{ + PyObject *pyobj_cbData = (PyObject*)opaque; + PyObject *pyobj_dom; + PyObject *pyobj_ret; + PyObject *pyobj_conn; + PyObject *dictKey; + int ret = -1; + + LIBVIRT_ENSURE_THREAD_STATE; + /* Create a python instance of this virDomainPtr */ + virDomainRef(dom); + + pyobj_dom = libvirt_virDomainPtrWrap(dom); + Py_INCREF(pyobj_cbData); + + dictKey = libvirt_constcharPtrWrap("conn"); + pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey); + Py_DECREF(dictKey); + + /* Call the Callback Dispatcher */ + pyobj_ret = PyObject_CallMethod(pyobj_conn, + (char*)"_dispatchDomainEventPMSuspendDiskCallback", + (char*)"OiO", + pyobj_dom, + reason, + pyobj_cbData); + + Py_DECREF(pyobj_cbData); + Py_DECREF(pyobj_dom); + + 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_virConnectDomainEventRegisterAny(ATTRIBUTE_UNUSED PyObject * self, PyObject * args) @@ -5884,6 +5931,9 @@ libvirt_virConnectDomainEventRegisterAny(ATTRIBUTE_UNUSED PyObject * self, case VIR_DOMAIN_EVENT_ID_BALLOON_CHANGE: cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventBalloonChangeCallback); break; + case VIR_DOMAIN_EVENT_ID_PMSUSPEND_DISK: + cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventPMSuspendDiskCallback); + break; } if (!cb) { |