[PATCH python] examples: event-test: Add network event support

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

 



Just an example of network lifecycle events
---
 examples/event-test.py | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/examples/event-test.py b/examples/event-test.py
index 1402c04..fb750c7 100644
--- a/examples/event-test.py
+++ b/examples/event-test.py
@@ -500,6 +500,14 @@ def myDomainEventPMSuspendDiskCallback(conn, dom, reason, opaque):
 def myDomainEventDeviceRemovedCallback(conn, dom, dev, opaque):
     print("myDomainEventDeviceRemovedCallback: Domain %s(%s) device removed: %s" % (
             dom.name(), dom.ID(), dev))
+def myNetworkEventLifecycleCallback(conn, net, event, detail, opaque):
+    event_to_string = {
+        0: "Defined",
+        1: "Undefined",
+        2: "Started",
+        3: "Stopped",
+    }
+    print("myNetworkEventLifecycleCallback: Network %s: %s detail=%s" % (net.name(), event_to_string.get(event, "event=%s" % event), detail))
 
 run = True
 
@@ -577,6 +585,8 @@ def main():
     vc.domainEventRegisterAny(None, libvirt.VIR_DOMAIN_EVENT_ID_PMSUSPEND_DISK, myDomainEventPMSuspendDiskCallback, None)
     vc.domainEventRegisterAny(None, libvirt.VIR_DOMAIN_EVENT_ID_DEVICE_REMOVED, myDomainEventDeviceRemovedCallback, None)
 
+    vc.networkEventRegisterAny(None, libvirt.VIR_NETWORK_EVENT_ID_LIFECYCLE, myNetworkEventLifecycleCallback, None)
+
     vc.setKeepAlive(5, 3)
 
     # The rest of your app would go here normally, but for sake
-- 
1.8.5.3

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]