On 03/18/2014 10:38 AM, Giuseppe Scrivano wrote: > Signed-off-by: Giuseppe Scrivano <gscrivan@xxxxxxxxxx> > --- > 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") > + }, Inconsistent indent with rest of the dictionary. Also, accessing libvirt.VIR_DOMAIN... directly means we will fail to start on a host with libvirt that doesn't have all those states available. Basically it bumps our host libvirt dep to whenever the latest reason was added. So I think we have to do getattr(libvirt, "VIR_DOMAIN_PAUSED_USER", $actual_enum_value) Or do what the libvirt-python event-loop.py example does and just stuff all the strings in a list or tuple, and do lookup by list index. > + 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 > I know you were being consistent here, but if we are adding a status_reason function, make this self._lastStatusReason since it's private. > 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] > Huh? virDomainGetInfo returns the status reason? Or am I misreading things? According to libvirt.h, info[3] should be the number of CPUs allocated to the VM. - Cole > # 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") > _______________________________________________ virt-tools-list mailing list virt-tools-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/virt-tools-list