On 11/24/2014 05:09 PM, Peter Krempa wrote:
Also add the example.
---
Version 2:
- version 2 actually works ...
examples/event-test.py | 11 ++++++++
libvirt-override-virConnect.py | 10 +++++++
libvirt-override.c | 60 ++++++++++++++++++++++++++++++++++++++++++
3 files changed, 81 insertions(+)
mode change 100644 => 100755 examples/event-test.py
diff --git a/examples/event-test.py b/examples/event-test.py
old mode 100644
new mode 100755
index be7a7d4..6cc33ce
--- a/examples/event-test.py
+++ b/examples/event-test.py
@@ -464,6 +464,14 @@ def blockJobStatusToString(status):
blockJobStatus = ( "Completed", "Failed", "Canceled",
"Ready", )
return blockJobStatus[status]
+def agentLifecycleStateToString(state):
+ agentStates = ( "unknown", "connected",
"disconnected", )
+ return agentStates[state]
+
+def agentLifecycleReasonToString(reason):
+ agentReasons = ( "unknown", "domain started", "channel
event", )
+ return agentReasons[reason]
+
def myDomainEventCallback1 (conn, dom, event, detail, opaque):
print("myDomainEventCallback1 EVENT: Domain %s(%s) %s %s" % (dom.name(),
dom.ID(),
domEventToString(event),
@@ -517,6 +525,8 @@ def myDomainEventBlockJob2Callback(conn, dom, disk, type, status,
opaque):
print("myDomainEventBlockJob2Callback: Domain %s(%s) %s on disk %s %s" %
(dom.name(), dom.ID(), blockJobTypeToString(type), disk, blockJobStatusToString(status)))
def myDomainEventTunableCallback(conn, dom, params, opaque):
print("myDomainEventTunableCallback: Domain %s(%s) %s" % (dom.name(),
dom.ID(), params))
+def myDomainEventAgentLifecycleCallback(conn, dom, state, reason, opaque):
+ print("myDomainEventAgentLifecycleCallback: Domain %s(%s) %s %s" %
(dom.name(), dom.ID(), agentLifecycleStateToString(state),
agentLifecycleReasonToString(reason)))
##########################################################################
# Network events
@@ -627,6 +637,7 @@ def main():
vc.domainEventRegisterAny(None, libvirt.VIR_DOMAIN_EVENT_ID_DEVICE_REMOVED,
myDomainEventDeviceRemovedCallback, None)
vc.domainEventRegisterAny(None, libvirt.VIR_DOMAIN_EVENT_ID_BLOCK_JOB_2,
myDomainEventBlockJob2Callback, None)
vc.domainEventRegisterAny(None, libvirt.VIR_DOMAIN_EVENT_ID_TUNABLE,
myDomainEventTunableCallback, None)
+ vc.domainEventRegisterAny(None, libvirt.VIR_DOMAIN_EVENT_ID_AGENT_LIFECYCLE,
myDomainEventAgentLifecycleCallback, None)
vc.networkEventRegisterAny(None, libvirt.VIR_NETWORK_EVENT_ID_LIFECYCLE,
myNetworkEventLifecycleCallback, None)
diff --git a/libvirt-override-virConnect.py b/libvirt-override-virConnect.py
index ffb6d6b..88c864c 100644
--- a/libvirt-override-virConnect.py
+++ b/libvirt-override-virConnect.py
@@ -197,6 +197,16 @@
cb(self, virDomain(self, _obj=dom), params, opaque)
return 0
+ def _dispatchDomainEventAgentLifecycleCallback(self, dom, state, reason, cbData):
+ """Dispatches event to python user domain agent lifecycle event
callback
+ """
+
+ cb = cbData["cb"]
+ opaque = cbData["opaque"]
+
+ cb(self, virDomain(self, _obj=dom), state, 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 8895289..e00d908 100644
--- a/libvirt-override.c
+++ b/libvirt-override.c
@@ -6566,6 +6566,61 @@ libvirt_virConnectDomainEventTunableCallback(virConnectPtr conn
ATTRIBUTE_UNUSED
}
#endif /* LIBVIR_CHECK_VERSION(1, 2, 9) */
+#if LIBVIR_CHECK_VERSION(1, 2, 11)
+static int
+libvirt_virConnectDomainEventAgentLifecycleCallback(virConnectPtr conn
ATTRIBUTE_UNUSED,
+ virDomainPtr dom,
+ int state,
+ int reason,
+ 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*)"_dispatchDomainEventAgentLifecycleCallback",
+ (char*)"OiiO",
+ pyobj_dom, state, reason, 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 /* LIBVIR_CHECK_VERSION(1, 2, 11) */
+
+
static PyObject *
libvirt_virConnectDomainEventRegisterAny(ATTRIBUTE_UNUSED PyObject *self,
PyObject *args)
@@ -6658,6 +6713,11 @@ libvirt_virConnectDomainEventRegisterAny(ATTRIBUTE_UNUSED PyObject
*self,
cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventTunableCallback);
break;
#endif /* LIBVIR_CHECK_VERSION(1, 2, 9) */
+#if LIBVIR_CHECK_VERSION(1, 2, 11)
+ case VIR_DOMAIN_EVENT_ID_AGENT_LIFECYCLE:
+ cb =
VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventAgentLifecycleCallback);
+ break;
+#endif /* LIBVIR_CHECK_VERSION(1, 2, 11) */
case VIR_DOMAIN_EVENT_ID_LAST:
break;
}
ACK
Pavel