Francesco Romani has uploaded a new change for review.

Change subject: virt: drop domain_event_to_string function
......................................................................

virt: drop domain_event_to_string function

The domain_event_to_string function doesn't do validation,
so drop it and just use direct dictionary access.
In the (only) calling site, we use get() to be more
robust and forward compatible.

Change-Id: I767f3e49e7b34d72aada23228d5e8689ea8991af
Signed-off-by: Francesco Romani <from...@redhat.com>
---
M vdsm/virt/libvirt_helpers.py
M vdsm/virt/vm.py
2 files changed, 13 insertions(+), 15 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/32/40432/1

diff --git a/vdsm/virt/libvirt_helpers.py b/vdsm/virt/libvirt_helpers.py
index d89a62f..89a84c7 100644
--- a/vdsm/virt/libvirt_helpers.py
+++ b/vdsm/virt/libvirt_helpers.py
@@ -31,20 +31,17 @@
 
 # These strings are representing libvirt virDomainEventType values
 # http://libvirt.org/html/libvirt-libvirt.html#virDomainEventType
-_DOMAIN_EVENT_STRINGS = (
-    "Defined",
-    "Undefined",
-    "Started",
-    "Suspended",
-    "Resumed",
-    "Stopped",
-    "Shutdown",
-    "PM-Suspended"
-)
-
-
-def domain_event_to_string(event):
-    return _DOMAIN_EVENT_STRINGS[event]
+DOMAIN_EVENT_TO_STRING = {
+    libvirt.VIR_DOMAIN_EVENT_DEFINED: "Defined",
+    libvirt.VIR_DOMAIN_EVENT_UNDEFINED: "Undefined",
+    libvirt.VIR_DOMAIN_EVENT_STARTED: "Started",
+    libvirt.VIR_DOMAIN_EVENT_SUSPENDED: "Suspended",
+    libvirt.VIR_DOMAIN_EVENT_RESUMED: "Resumed",
+    libvirt.VIR_DOMAIN_EVENT_STOPPED: "Stopped",
+    libvirt.VIR_DOMAIN_EVENT_SHUTDOWN: "Shutdown",
+    libvirt.VIR_DOMAIN_EVENT_PMSUSPENDED: "PM-Suspended",
+    libvirt.VIR_DOMAIN_EVENT_CRASHED: "Crashed",
+}
 
 
 class TimeoutError(libvirt.libvirtError):
diff --git a/vdsm/virt/vm.py b/vdsm/virt/vm.py
index b2b400d..7685ba8 100644
--- a/vdsm/virt/vm.py
+++ b/vdsm/virt/vm.py
@@ -4063,7 +4063,8 @@
 
     def _onLibvirtLifecycleEvent(self, event, detail, opaque):
         self.log.debug('event %s detail %s opaque %s',
-                       libvirt_helpers.domain_event_to_string(event),
+                       libvirt_helpers.DOMAIN_EVENT_TO_STRING.get(
+                           event, "Unknown"),
                        detail, opaque)
         if event == libvirt.VIR_DOMAIN_EVENT_STOPPED:
             if (detail == libvirt.VIR_DOMAIN_EVENT_STOPPED_MIGRATED and


-- 
To view, visit https://gerrit.ovirt.org/40432
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I767f3e49e7b34d72aada23228d5e8689ea8991af
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Francesco Romani <from...@redhat.com>
_______________________________________________
vdsm-patches mailing list
vdsm-patches@lists.fedorahosted.org
https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches

Reply via email to