[libvirt] [PATCH libvirt-python v2 17/22] event-test.py: Convert NETWORK events

Philipp Hahn posted 22 patches 6 years, 2 months ago
[libvirt] [PATCH libvirt-python v2 17/22] event-test.py: Convert NETWORK events
Posted by Philipp Hahn 6 years, 2 months ago
to use new Description class

Signed-off-by: Philipp Hahn <hahn@univention.de>
---
 examples/event-test.py | 29 ++++++++++-------------------
 1 file changed, 10 insertions(+), 19 deletions(-)

diff --git a/examples/event-test.py b/examples/event-test.py
index 5426ecd..2436827 100755
--- a/examples/event-test.py
+++ b/examples/event-test.py
@@ -604,27 +604,18 @@ def myDomainEventBlockThresholdCallback(conn, dom, dev, path, threshold, excess,
 ##########################################################################
 # Network events
 ##########################################################################
-def netEventToString(event):
-    netEventStrings = ( "Defined",
-                     "Undefined",
-                     "Started",
-                     "Stopped",
-    )
-    return netEventStrings[event]
-
-def netDetailToString(event, detail):
-    netEventStrings = (
-        ( "Added", ),
-        ( "Removed", ),
-        ( "Started", ),
-        ( "Stopped", ),
-    )
-    return netEventStrings[event][detail]
+NET_EVENTS = Description(
+    ("Defined", ("Added",)),
+    ("Undefined", ("Removed",)),
+    ("Started", ("Started",)),
+    ("Stopped", ("Stopped",)),
+)
+
 
 def myNetworkEventLifecycleCallback(conn, net, event, detail, opaque):
-    print("myNetworkEventLifecycleCallback: Network %s %s %s" % (net.name(),
-                                                                 netEventToString(event),
-                                                                 netDetailToString(event, detail)))
+    print("myNetworkEventLifecycleCallback: Network %s %s %s" % (
+        net.name(), NET_EVENTS[event], NET_EVENTS[event][detail]))
+
 
 ##########################################################################
 # Storage pool events
-- 
2.11.0

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