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

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

 



to use new Description class

Signed-off-by: Philipp Hahn <hahn@xxxxxxxxxxxxx>
---
 examples/event-test.py | 42 ++++++++++++++----------------------------
 1 file changed, 14 insertions(+), 28 deletions(-)

diff --git a/examples/event-test.py b/examples/event-test.py
index d2d2c60..493828f 100755
--- a/examples/event-test.py
+++ b/examples/event-test.py
@@ -481,32 +481,18 @@ class Description(object):
         raise TypeError(args)
 
 
-def domEventToString(event):
-    domEventStrings = ( "Defined",
-                     "Undefined",
-                     "Started",
-                     "Suspended",
-                     "Resumed",
-                     "Stopped",
-                     "Shutdown",
-                     "PMSuspended",
-                     "Crashed",
-    )
-    return domEventStrings[event]
-
-def domDetailToString(event, detail):
-    domEventStrings = (
-        ( "Added", "Updated", "Renamed", "Snapshot" ),
-        ( "Removed", "Renamed", ),
-        ( "Booted", "Migrated", "Restored", "Snapshot", "Wakeup" ),
-        ( "Paused", "Migrated", "IOError", "Watchdog", "Restored", "Snapshot", "API error", "Postcopy", "Postcopy failed" ),
-        ( "Unpaused", "Migrated", "Snapshot", "Postcopy" ),
-        ( "Shutdown", "Destroyed", "Crashed", "Migrated", "Saved", "Failed", "Snapshot"),
-        ( "Finished", "On guest request", "On host request"),
-        ( "Memory", "Disk" ),
-        ( "Panicked", ),
-        )
-    return domEventStrings[event][detail]
+DOM_EVENTS = Description(
+    ("Defined", ("Added", "Updated", "Renamed", "Snapshot")),
+    ("Undefined", ("Removed", "Renamed")),
+    ("Started", ("Booted", "Migrated", "Restored", "Snapshot", "Wakeup")),
+    ("Suspended", ("Paused", "Migrated", "IOError", "Watchdog", "Restored", "Snapshot", "API error", "Postcopy", "Postcopy failed")),
+    ("Resumed", ("Unpaused", "Migrated", "Snapshot", "Postcopy")),
+    ("Stopped", ("Shutdown", "Destroyed", "Crashed", "Migrated", "Saved", "Failed", "Snapshot")),
+    ("Shutdown", ("Finished", "On guest request", "On host request")),
+    ("PMSuspended", ("Memory", "Disk")),
+    ("Crashed", ("Panicked",)),
+)
+
 
 def blockJobTypeToString(type):
     blockJobTypes = ( "unknown", "Pull", "Copy", "Commit", "ActiveCommit", )
@@ -526,8 +512,8 @@ def agentLifecycleReasonToString(reason):
 
 
 def myDomainEventCallback(conn, dom, event, detail, opaque):
-    print("myDomainEventCallback%d EVENT: Domain %s(%s) %s %s" % (
-        opaque, dom.name(), dom.ID(), domEventToString(event), domDetailToString(event, detail)))
+    print("myDomainEventCallback%s EVENT: Domain %s(%s) %s %s" % (
+        opaque, dom.name(), dom.ID(), DOM_EVENTS[event], DOM_EVENTS[event][detail]))
 
 
 def myDomainEventRebootCallback(conn, dom, opaque):
-- 
2.11.0

--
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]

  Powered by Linux