[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [python PATCH] event: Add bindings for agent lifecycle event



Also add the example.
---
 examples/event-test.py | 13 +++++++++++
 libvirt-override.c     | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 73 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..acc7f20
--- a/examples/event-test.py
+++ b/examples/event-test.py
@@ -464,6 +464,15 @@ 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 booted", "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 +526,9 @@ 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 +639,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.c b/libvirt-override.c
index a53b46f..af4f386 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*)"_dispatchDomainEventTunableCallback",
+                                    (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;
     }
-- 
2.1.0


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]