mirror of
https://gitlab.com/libvirt/libvirt-python.git
synced 2025-07-10 00:59:41 +03:00
Add support for JOB_COMPLETED event
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
This commit is contained in:
@ -533,6 +533,8 @@ def myDomainEventDeviceAddedCallback(conn, dom, dev, opaque):
|
||||
def myDomainEventMigrationIteration(conn, dom, iteration, opaque):
|
||||
print("myDomainEventMigrationIteration: Domain %s(%s) started migration iteration %d" % (
|
||||
dom.name(), dom.ID(), iteration))
|
||||
def myDomainEventJobCompletedCallback(conn, dom, params, opaque):
|
||||
print("myDomainEventJobCompletedCallback: Domain %s(%s) %s" % (dom.name(), dom.ID(), params))
|
||||
|
||||
##########################################################################
|
||||
# Network events
|
||||
@ -646,6 +648,7 @@ def main():
|
||||
vc.domainEventRegisterAny(None, libvirt.VIR_DOMAIN_EVENT_ID_AGENT_LIFECYCLE, myDomainEventAgentLifecycleCallback, None)
|
||||
vc.domainEventRegisterAny(None, libvirt.VIR_DOMAIN_EVENT_ID_DEVICE_ADDED, myDomainEventDeviceAddedCallback, None)
|
||||
vc.domainEventRegisterAny(None, libvirt.VIR_DOMAIN_EVENT_ID_MIGRATION_ITERATION, myDomainEventMigrationIteration, None)
|
||||
vc.domainEventRegisterAny(None, libvirt.VIR_DOMAIN_EVENT_ID_JOB_COMPLETED, myDomainEventJobCompletedCallback, None)
|
||||
|
||||
vc.networkEventRegisterAny(None, libvirt.VIR_NETWORK_EVENT_ID_LIFECYCLE, myNetworkEventLifecycleCallback, None)
|
||||
|
||||
|
@ -225,6 +225,15 @@
|
||||
cb(self, virDomain(self, _obj=dom), iteration, opaque)
|
||||
return 0
|
||||
|
||||
def _dispatchDomainEventJobCompletedCallback(self, dom, params, cbData):
|
||||
"""Dispatches event to python user domain job completed callbacks
|
||||
"""
|
||||
cb = cbData["cb"]
|
||||
opaque = cbData["opaque"]
|
||||
|
||||
cb(self, virDomain(self, _obj=dom), params, 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 """
|
||||
|
@ -6835,6 +6835,65 @@ libvirt_virConnectDomainEventMigrationIterationCallback(virConnectPtr conn ATTRI
|
||||
}
|
||||
#endif /* VIR_DOMAIN_EVENT_ID_MIGRATION_ITERATION */
|
||||
|
||||
#ifdef VIR_DOMAIN_EVENT_ID_JOB_COMPLETED
|
||||
static int
|
||||
libvirt_virConnectDomainEventJobCompletedCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
|
||||
virDomainPtr dom,
|
||||
virTypedParameterPtr params,
|
||||
int nparams,
|
||||
void *opaque)
|
||||
{
|
||||
PyObject *pyobj_cbData = (PyObject*)opaque;
|
||||
PyObject *pyobj_dom;
|
||||
PyObject *pyobj_ret = NULL;
|
||||
PyObject *pyobj_conn;
|
||||
PyObject *dictKey;
|
||||
PyObject *pyobj_dict = NULL;
|
||||
int ret = -1;
|
||||
|
||||
LIBVIRT_ENSURE_THREAD_STATE;
|
||||
|
||||
pyobj_dict = getPyVirTypedParameter(params, nparams);
|
||||
if (!pyobj_dict)
|
||||
goto cleanup;
|
||||
|
||||
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*)"_dispatchDomainEventJobCompletedCallback",
|
||||
(char*)"OOO",
|
||||
pyobj_dom, pyobj_dict, pyobj_cbData);
|
||||
|
||||
Py_DECREF(pyobj_cbData);
|
||||
Py_DECREF(pyobj_dom);
|
||||
|
||||
cleanup:
|
||||
if (!pyobj_ret) {
|
||||
DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
|
||||
PyErr_Print();
|
||||
Py_XDECREF(pyobj_dict);
|
||||
} else {
|
||||
Py_DECREF(pyobj_ret);
|
||||
ret = 0;
|
||||
}
|
||||
|
||||
LIBVIRT_RELEASE_THREAD_STATE;
|
||||
return ret;
|
||||
}
|
||||
#endif /* VIR_DOMAIN_EVENT_ID_JOB_COMPLETED */
|
||||
|
||||
static PyObject *
|
||||
libvirt_virConnectDomainEventRegisterAny(PyObject *self ATTRIBUTE_UNUSED,
|
||||
PyObject *args)
|
||||
@ -6940,6 +6999,11 @@ libvirt_virConnectDomainEventRegisterAny(PyObject *self ATTRIBUTE_UNUSED,
|
||||
cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventMigrationIterationCallback);
|
||||
break;
|
||||
#endif /* VIR_DOMAIN_EVENT_ID_MIGRATION_ITERATION */
|
||||
#ifdef VIR_DOMAIN_EVENT_ID_JOB_COMPLETED
|
||||
case VIR_DOMAIN_EVENT_ID_JOB_COMPLETED:
|
||||
cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventJobCompletedCallback);
|
||||
break;
|
||||
#endif /* VIR_DOMAIN_EVENT_ID_JOB_COMPLETED */
|
||||
case VIR_DOMAIN_EVENT_ID_LAST:
|
||||
break;
|
||||
}
|
||||
|
Reference in New Issue
Block a user