[libvirt] [PATCH] Fix printing of event detail in python events demo program

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

 



The events demo program is slightly misleading printing

  myDomainEventCallback1 EVENT: Domain f14i686(-1) Added

which is not distinguishing Add vs Update events. It should have
been doing

  myDomainEventCallback1 EVENT: Domain f14i686(-1) Defined Updated

* examples/domain-events/events-python/event-test.py: Fully print
  event detail info string
---
 examples/domain-events/events-python/event-test.py |   27 ++++++++++++++-----
 1 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/examples/domain-events/events-python/event-test.py b/examples/domain-events/events-python/event-test.py
index 0c6e2f0..7c5af68 100644
--- a/examples/domain-events/events-python/event-test.py
+++ b/examples/domain-events/events-python/event-test.py
@@ -396,21 +396,34 @@ def virEventLoopPureStart():
 # Everything that now follows is a simple demo of domain lifecycle events
 ##########################################################################
 def eventToString(event):
-    eventStrings = ( "Added",
-                     "Removed",
+    eventStrings = ( "Defined",
+                     "Undefined",
                      "Started",
                      "Suspended",
                      "Resumed",
-                     "Stopped",
-                     "Saved",
-                     "Restored" );
+                     "Stopped" );
     return eventStrings[event];
 
+def detailToString(event, detail):
+    eventStrings = (
+        ( "Added", "Updated" ),
+        ( "Removed" ),
+        ( "Booted", "Migrated", "Restored", "Snapshot" ),
+        ( "Paused", "Migrated", "IOError", "Watchdog" ),
+        ( "Unpaused", "Migrated"),
+        ( "Shutdown", "Destroyed", "Crashed", "Migrated", "Saved", "Failed", "Snapshot")
+        )
+    return eventStrings[event][detail]
+
 def myDomainEventCallback1 (conn, dom, event, detail, opaque):
-    print "myDomainEventCallback1 EVENT: Domain %s(%s) %s %d" % (dom.name(), dom.ID(), eventToString(event), detail)
+    print "myDomainEventCallback1 EVENT: Domain %s(%s) %s %s" % (dom.name(), dom.ID(),
+                                                                 eventToString(event),
+                                                                 detailToString(event, detail))
 
 def myDomainEventCallback2 (conn, dom, event, detail, opaque):
-    print "myDomainEventCallback2 EVENT: Domain %s(%s) %s %d" % (dom.name(), dom.ID(), eventToString(event), detail)
+    print "myDomainEventCallback2 EVENT: Domain %s(%s) %s %s" % (dom.name(), dom.ID(),
+                                                                 eventToString(event),
+                                                                 detailToString(event, detail))
 
 def myDomainEventRebootCallback(conn, dom, opaque):
     print "myDomainEventRebootCallback: Domain %s(%s)" % (dom.name(), dom.ID())
-- 
1.6.6.1

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