snapshots: Make state type/icon UI match other usage

This commit is contained in:
Cole Robinson 2013-09-30 17:11:22 -04:00
parent 3629dabeb0
commit 45e84d46ec
4 changed files with 140 additions and 58 deletions

View File

@ -783,6 +783,74 @@ test-many-devices, like an alternate RNG.
<active>0</active>
</test:domainsnapshot>
<test:domainsnapshot>
<name>snap-paused</name>
<state>paused</state>
<creationTime>1375903080</creationTime>
<memory snapshot='internal'/>
<disks>
<disk name='hda' snapshot='internal'/>
</disks>
<domain type='test'>
<name>test-internal-snapshots</name>
<uuid>12345678-1234-fddf-1234-12345678ffff</uuid>
<memory unit='KiB'>409600</memory>
<currentMemory unit='KiB'>409600</currentMemory>
<vcpu placement='static'>1</vcpu>
<bootloader>/tmp/bootfoo</bootloader>
<os>
<type arch='i686'>xen</type>
</os>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
<disk type='file' device='disk'>
<source file='/dev/default-pool/test-clone-simple.img'/>
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
</disk>
<controller type='ide' index='0'/>
</devices>
</domain>
<active>0</active>
</test:domainsnapshot>
<test:domainsnapshot>
<name>snap-pmsuspended</name>
<state>pmsuspended</state>
<creationTime>1375903080</creationTime>
<memory snapshot='internal'/>
<disks>
<disk name='hda' snapshot='internal'/>
</disks>
<domain type='test'>
<name>test-internal-snapshots</name>
<uuid>12345678-1234-fddf-1234-12345678ffff</uuid>
<memory unit='KiB'>409600</memory>
<currentMemory unit='KiB'>409600</currentMemory>
<vcpu placement='static'>1</vcpu>
<bootloader>/tmp/bootfoo</bootloader>
<os>
<type arch='i686'>xen</type>
</os>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
<disk type='file' device='disk'>
<source file='/dev/default-pool/test-clone-simple.img'/>
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
</disk>
<controller type='ide' index='0'/>
</devices>
</domain>
<active>0</active>
</test:domainsnapshot>
</domain>

View File

@ -27,8 +27,12 @@ import time
import threading
import libvirt
import virtinst
from virtinst import DomainSnapshot
from virtinst import Guest
from virtinst import util
from virtinst import VirtualChannelDevice
from virtinst import VirtualController
from virtManager import uihelpers
from virtManager.libvirtobject import vmmLibvirtObject
@ -146,7 +150,7 @@ class vmmDomainSnapshot(vmmLibvirtObject):
"""
def __init__(self, conn, backend):
vmmLibvirtObject.__init__(self, conn, backend, backend.getName(),
virtinst.DomainSnapshot)
DomainSnapshot)
self.refresh_xml()
@ -161,13 +165,22 @@ class vmmDomainSnapshot(vmmLibvirtObject):
ignore = force
self._backend.delete()
def run_status(self):
status = DomainSnapshot.state_str_to_int(self.get_xmlobj().state)
return vmmDomain.pretty_run_status(status)
def run_status_icon_name(self):
status = DomainSnapshot.state_str_to_int(self.get_xmlobj().state)
if status not in uihelpers.vm_status_icons:
logging.debug("Unknown status %d, using NOSTATE", status)
status = libvirt.VIR_DOMAIN_NOSTATE
return uihelpers.vm_status_icons[status]
class vmmDomain(vmmLibvirtObject):
"""
Class wrapping virDomain libvirt objects. Is also extended to be
backed by a virtinst.Guest object for new VM 'customize before install'
"""
__gsignals__ = {
"status-changed": (GObject.SignalFlags.RUN_FIRST, None, [int, int]),
"resources-sampled": (GObject.SignalFlags.RUN_FIRST, None, []),
@ -175,9 +188,30 @@ class vmmDomain(vmmLibvirtObject):
"pre-startup": (GObject.SignalFlags.RUN_FIRST, None, [object]),
}
@staticmethod
def pretty_run_status(status, has_saved=False):
if status == libvirt.VIR_DOMAIN_RUNNING:
return _("Running")
elif status == libvirt.VIR_DOMAIN_PAUSED:
return _("Paused")
elif status == libvirt.VIR_DOMAIN_SHUTDOWN:
return _("Shutting Down")
elif status == libvirt.VIR_DOMAIN_SHUTOFF:
if has_saved:
return _("Saved")
else:
return _("Shutoff")
elif status == libvirt.VIR_DOMAIN_CRASHED:
return _("Crashed")
elif (hasattr(libvirt, "VIR_DOMAIN_PMSUSPENDED") and
status == libvirt.VIR_DOMAIN_PMSUSPENDED):
return _("Suspended")
logging.debug("Unknown status %d, returning 'Unknown'", status)
return _("Unknown")
def __init__(self, conn, backend, key):
vmmLibvirtObject.__init__(self, conn, backend, key,
virtinst.Guest)
vmmLibvirtObject.__init__(self, conn, backend, key, Guest)
self.uuid = key
self.cloning = False
@ -215,7 +249,7 @@ class vmmDomain(vmmLibvirtObject):
self.inspection = vmmInspectionData()
if isinstance(self._backend, virtinst.Guest):
if isinstance(self._backend, Guest):
return
self._libvirt_init()
@ -702,10 +736,10 @@ class vmmDomain(vmmLibvirtObject):
return
guest = self._get_xmlobj_to_define()
is_spice = (newval == virtinst.VirtualGraphics.TYPE_SPICE)
is_spice = (newval == "spice")
if is_spice:
dev = virtinst.VirtualChannelDevice(guest.conn)
dev = VirtualChannelDevice(guest.conn)
dev.type = dev.TYPE_SPICEVMC
guest.add_device(dev)
else:
@ -774,12 +808,12 @@ class vmmDomain(vmmLibvirtObject):
guest = self._get_xmlobj_to_define()
ctrls = guest.get_devices("controller")
ctrls = [x for x in ctrls if (x.type ==
virtinst.VirtualController.TYPE_USB)]
VirtualController.TYPE_USB)]
for dev in ctrls:
guest.remove_device(dev)
if newmodel == "ich9-ehci1":
for dev in virtinst.VirtualController.get_usb2_controllers(
for dev in VirtualController.get_usb2_controllers(
guest.conn):
guest.add_device(dev)
@ -1495,29 +1529,6 @@ class vmmDomain(vmmLibvirtObject):
self._startup_vcpus = None
self.vcpu_max_count()
def run_status(self):
status = self.status()
if status == libvirt.VIR_DOMAIN_RUNNING:
return _("Running")
elif status == libvirt.VIR_DOMAIN_PAUSED:
return _("Paused")
elif status == libvirt.VIR_DOMAIN_SHUTDOWN:
return _("Shutting Down")
elif status == libvirt.VIR_DOMAIN_SHUTOFF:
if self.hasSavedImage():
return _("Saved")
else:
return _("Shutoff")
elif status == libvirt.VIR_DOMAIN_CRASHED:
return _("Crashed")
elif (hasattr(libvirt, "VIR_DOMAIN_PMSUSPENDED") and
status == libvirt.VIR_DOMAIN_PMSUSPENDED):
return _("Suspended")
logging.debug("Unknown status %d, returning 'Unknown'")
return _("Unknown")
def _normalize_status(self, status):
if status == libvirt.VIR_DOMAIN_NOSTATE:
return libvirt.VIR_DOMAIN_RUNNING
@ -1547,12 +1558,13 @@ class vmmDomain(vmmLibvirtObject):
def is_paused(self):
return self.status() in [libvirt.VIR_DOMAIN_PAUSED]
def run_status(self):
return self.pretty_run_status(self.status(), self.hasSavedImage())
def run_status_icon_name(self):
status = self.status()
if status not in uihelpers.vm_status_icons:
logging.debug("Unknown status %d, using NOSTATE")
logging.debug("Unknown status %d, using NOSTATE", status)
status = libvirt.VIR_DOMAIN_NOSTATE
return uihelpers.vm_status_icons[status]
def force_update_status(self):

View File

@ -26,8 +26,6 @@ from gi.repository import Gdk
from gi.repository import Gtk
# pylint: enable=E0611
import libvirt
from virtinst import DomainSnapshot
from virtinst import util
@ -36,23 +34,6 @@ from virtManager.baseclass import vmmGObjectUI
from virtManager.asyncjob import vmmAsyncJob
def _snapshot_state_icon_name(state):
statemap = {
"nostate": libvirt.VIR_DOMAIN_NOSTATE,
"running": libvirt.VIR_DOMAIN_RUNNING,
"blocked": libvirt.VIR_DOMAIN_BLOCKED,
"paused": libvirt.VIR_DOMAIN_PAUSED,
"shutdown": libvirt.VIR_DOMAIN_SHUTDOWN,
"shutoff": libvirt.VIR_DOMAIN_SHUTOFF,
"crashed": libvirt.VIR_DOMAIN_CRASHED,
"pmsuspended": 7,
}
if state == "disk-snapshot" or state not in statemap:
state = "shutoff"
return uihelpers.vm_status_icons[statemap[state]]
class vmmSnapshotPage(vmmGObjectUI):
def __init__(self, vm, builder, topwin):
vmmGObjectUI.__init__(self, "snapshots.ui",
@ -188,7 +169,8 @@ class vmmSnapshotPage(vmmGObjectUI):
xmlobj = snap and snap.get_xmlobj() or None
name = snap and xmlobj.name or ""
desc = snap and xmlobj.description or ""
state = snap and xmlobj.state or "shutoff"
state = snap and snap.run_status() or ""
icon = snap and snap.run_status_icon_name() or None
timestamp = ""
if snap:
timestamp = str(datetime.datetime.fromtimestamp(
@ -203,9 +185,9 @@ class vmmSnapshotPage(vmmGObjectUI):
self.widget("snapshot-description").get_buffer().set_text(desc)
self.widget("snapshot-status-text").set_text(state)
self.widget("snapshot-status-icon").set_from_icon_name(
_snapshot_state_icon_name(state),
Gtk.IconSize.MENU)
if icon:
self.widget("snapshot-status-icon").set_from_icon_name(
icon, Gtk.IconSize.MENU)
self.widget("snapshot-add").set_sensitive(True)
self.widget("snapshot-delete").set_sensitive(bool(snap))

View File

@ -17,6 +17,8 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301 USA.
import libvirt
from virtinst import util
from virtinst.xmlbuilder import XMLBuilder, XMLProperty
@ -28,6 +30,24 @@ class DomainSnapshot(XMLBuilder):
sep="", start_num=1, force_num=True,
collidelist=collidelist)
@staticmethod
def state_str_to_int(state):
statemap = {
"nostate": libvirt.VIR_DOMAIN_NOSTATE,
"running": libvirt.VIR_DOMAIN_RUNNING,
"blocked": libvirt.VIR_DOMAIN_BLOCKED,
"paused": libvirt.VIR_DOMAIN_PAUSED,
"shutdown": libvirt.VIR_DOMAIN_SHUTDOWN,
"shutoff": libvirt.VIR_DOMAIN_SHUTOFF,
"crashed": libvirt.VIR_DOMAIN_CRASHED,
"pmsuspended": 7,
}
if state == "disk-snapshot" or state not in statemap:
state = "shutoff"
return statemap.get(state, libvirt.VIR_DOMAIN_NOSTATE)
_XML_ROOT_NAME = "domainsnapshot"
_XML_PROP_ORDER = ["name", "description", "creationTime"]