[virt-tools-list] [PATCH virt-manager 1/2] virtManager: read the reason for the domain state

Giuseppe Scrivano gscrivan at redhat.com
Tue Mar 18 14:38:22 UTC 2014


Signed-off-by: Giuseppe Scrivano <gscrivan at redhat.com>
---
 virtManager/domain.py | 65 +++++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 61 insertions(+), 4 deletions(-)

diff --git a/virtManager/domain.py b/virtManager/domain.py
index a308aab..6543919 100644
--- a/virtManager/domain.py
+++ b/virtManager/domain.py
@@ -232,6 +232,54 @@ class vmmDomain(vmmLibvirtObject):
         logging.debug("Unknown status %d, returning 'Unknown'", status)
         return _("Unknown")
 
+    @staticmethod
+    def pretty_status_reason(status, reason):
+        reasons = {
+            libvirt.VIR_DOMAIN_RUNNING : {
+                      libvirt.VIR_DOMAIN_RUNNING_BOOTED :  _("Booted"),
+                      libvirt.VIR_DOMAIN_RUNNING_MIGRATED : _("Migrated"),
+                      libvirt.VIR_DOMAIN_RUNNING_RESTORED : _("Restored"),
+                      libvirt.VIR_DOMAIN_RUNNING_FROM_SNAPSHOT :
+                _("From snapshot"),
+                      libvirt.VIR_DOMAIN_RUNNING_UNPAUSED : _("Unpaused"),
+                      libvirt.VIR_DOMAIN_RUNNING_MIGRATION_CANCELED :
+                _("Migration canceled"),
+                      libvirt.VIR_DOMAIN_RUNNING_SAVE_CANCELED :
+                _("Save canceled"),
+                      libvirt.VIR_DOMAIN_RUNNING_WAKEUP : _("Event wakeup"),
+                      libvirt.VIR_DOMAIN_RUNNING_CRASHED : _("Crashed")
+            },
+            libvirt.VIR_DOMAIN_PAUSED : {
+                libvirt.VIR_DOMAIN_PAUSED_USER : _("User"),
+                libvirt.VIR_DOMAIN_PAUSED_MIGRATION : _("Migrating"),
+                libvirt.VIR_DOMAIN_PAUSED_SAVE : _("Saving"),
+                libvirt.VIR_DOMAIN_PAUSED_DUMP : _("Dumping"),
+                libvirt.VIR_DOMAIN_PAUSED_IOERROR : _("I/O error"),
+                libvirt.VIR_DOMAIN_PAUSED_WATCHDOG : _("Watchdog"),
+                libvirt.VIR_DOMAIN_PAUSED_FROM_SNAPSHOT : _("From snapshot"),
+                libvirt.VIR_DOMAIN_PAUSED_SHUTTING_DOWN : _("Shutting down"),
+                libvirt.VIR_DOMAIN_PAUSED_SNAPSHOT : _("Creating snapshot"),
+                libvirt.VIR_DOMAIN_PAUSED_CRASHED : _("Crashed"),
+            },
+            libvirt.VIR_DOMAIN_SHUTDOWN : {
+                libvirt.VIR_DOMAIN_SHUTDOWN_USER : _("User")
+            },
+            libvirt.VIR_DOMAIN_SHUTOFF : {
+                libvirt.VIR_DOMAIN_SHUTOFF_SHUTDOWN: _("Shutdown"),
+                libvirt.VIR_DOMAIN_SHUTOFF_DESTROYED : _("Destroyed"),
+                libvirt.VIR_DOMAIN_SHUTOFF_CRASHED : _("Crashed"),
+                libvirt.VIR_DOMAIN_SHUTOFF_MIGRATED : _("Migrated"),
+                libvirt.VIR_DOMAIN_SHUTOFF_SAVED : _("Saved"),
+                libvirt.VIR_DOMAIN_SHUTOFF_FAILED : _("Failed"),
+                libvirt.VIR_DOMAIN_SHUTOFF_FROM_SNAPSHOT : _("From snapshot")
+            },
+            libvirt.VIR_DOMAIN_CRASHED : {
+                libvirt.VIR_DOMAIN_CRASHED_PANICKED : _("Panicked")
+            }
+        }
+        return (reasons.get(status) and reasons[status].get(reason)
+                or _("Unknown"))
+
     def __init__(self, conn, backend, key):
         vmmLibvirtObject.__init__(self, conn, backend, key, Guest)
 
@@ -254,6 +302,7 @@ class vmmDomain(vmmLibvirtObject):
         self._snapshot_list = None
 
         self.lastStatus = libvirt.VIR_DOMAIN_SHUTOFF
+        self.lastStatusReason = libvirt.VIR_DOMAIN_SHUTOFF_SHUTDOWN
 
         self.managedsave_supported = False
         self.remote_console_supported = False
@@ -373,6 +422,9 @@ class vmmDomain(vmmLibvirtObject):
     def status(self):
         return self.lastStatus
 
+    def status_reason(self):
+        return self.lastStatusReason
+
     def get_cloning(self):
         return self.cloning
     def set_cloning(self, val):
@@ -1647,6 +1699,10 @@ class vmmDomain(vmmLibvirtObject):
 
     def run_status(self):
         return self.pretty_run_status(self.status(), self.hasSavedImage())
+
+    def run_status_reason(self):
+        return self.pretty_status_reason(self.status(), self.status_reason())
+
     def run_status_icon_name(self):
         status = self.status()
         if status not in vm_status_icons:
@@ -1663,7 +1719,7 @@ class vmmDomain(vmmLibvirtObject):
 
         try:
             info = self._backend.info()
-            self._update_status(info[0])
+            self._update_status(info)
         except libvirt.libvirtError:
             # Transient domain might have disappeared, tell the connection
             # to update the domain list
@@ -1671,18 +1727,19 @@ class vmmDomain(vmmLibvirtObject):
                 "list refresh")
             self.conn.schedule_priority_tick(pollvm=True, force=True)
 
-    def _update_status(self, status):
+    def _update_status(self, info):
         """
         Internal helper to change cached status to 'status' and signal
         clients if we actually changed state
         """
-        status = self._normalize_status(status)
+        status = self._normalize_status(info[0])
 
         if status == self.lastStatus:
             return
 
         oldstatus = self.lastStatus
         self.lastStatus = status
+        self.lastStatusReason = info[3]
 
         # Send 'config-changed' before a status-update, so users
         # are operating with fresh XML
@@ -1867,7 +1924,7 @@ class vmmDomain(vmmLibvirtObject):
             self._tick_stats(info)
 
         if not self._using_events():
-            self._update_status(info[0])
+            self._update_status(info)
 
         if stats_update:
             self.idle_emit("resources-sampled")
-- 
1.8.5.3




More information about the virt-tools-list mailing list