From d44f863c2d65efa34eca637b6f73614baf967b51 Mon Sep 17 00:00:00 2001 From: Cole Robinson Date: Mon, 30 Sep 2013 20:33:42 -0400 Subject: [PATCH] details: Disable snapshot buttons if conn or guest doesn't have support --- tests/testdriver.xml | 1 + ui/details.ui | 3 +-- virtManager/details.py | 11 +++++++-- virtManager/domain.py | 52 +++++++++++++++++++++++++++++----------- virtManager/snapshots.py | 5 ---- 5 files changed, 49 insertions(+), 23 deletions(-) diff --git a/tests/testdriver.xml b/tests/testdriver.xml index e68ee4219..444001e2e 100644 --- a/tests/testdriver.xml +++ b/tests/testdriver.xml @@ -356,6 +356,7 @@ test-many-devices, like an alternate RNG. + diff --git a/ui/details.ui b/ui/details.ui index 9336ff089..3817e296f 100644 --- a/ui/details.ui +++ b/ui/details.ui @@ -1,5 +1,5 @@ - + @@ -391,7 +391,6 @@ True False - Manage VM snapshots Snapshots vm_clone_wizard control-vm-console diff --git a/virtManager/details.py b/virtManager/details.py index 32b8299dd..1b3f6fd52 100644 --- a/virtManager/details.py +++ b/virtManager/details.py @@ -1335,10 +1335,17 @@ class vmmDetails(vmmGObjectUI): details = self.widget("details-pages") self.page_refresh(details.get_current_page()) - - # This is safe to refresh, and is dependent on domain state self._refresh_runtime_pinning() + errmsg = self.vm.snapshots_supported() + cansnap = not bool(errmsg) + self.widget("control-snapshots").set_sensitive(cansnap) + self.widget("details-menu-view-snapshots").set_sensitive(cansnap) + tooltip = _("Manage VM snapshots") + if not cansnap: + tooltip += "\n" + errmsg + self.widget("control-snapshots").set_tooltip_text(tooltip) + ############################# # External action listeners # diff --git a/virtManager/domain.py b/virtManager/domain.py index 70fd3e144..043d08753 100644 --- a/virtManager/domain.py +++ b/virtManager/domain.py @@ -242,7 +242,6 @@ class vmmDomain(vmmLibvirtObject): self.managedsave_supported = False self.remote_console_supported = False - self.snapshots_supported = False self.title_supported = False self._enable_net_poll = False @@ -265,16 +264,6 @@ class vmmDomain(vmmLibvirtObject): snap.cleanup() self._snapshot_list = None - def _get_getvcpus_supported(self): - return self.conn.check_domain_support(self._backend, - self.conn.SUPPORT_DOMAIN_GETVCPUS) - getvcpus_supported = property(_get_getvcpus_supported) - - def _get_getjobinfo_supported(self): - return self.conn.check_domain_support(self._backend, - self.conn.SUPPORT_DOMAIN_JOB_INFO) - getjobinfo_supported = property(_get_getjobinfo_supported) - def _libvirt_init(self): """ Initialization to do if backed by a libvirt virDomain @@ -285,9 +274,6 @@ class vmmDomain(vmmLibvirtObject): self.remote_console_supported = self.conn.check_domain_support( self._backend, self.conn.SUPPORT_DOMAIN_CONSOLE_STREAM) - self.snapshots_supported = self.conn.check_domain_support( - self._backend, - self.conn.SUPPORT_DOMAIN_LIST_SNAPSHOTS) self.title_supported = self.conn.check_domain_support( self._backend, self.conn.SUPPORT_DOMAIN_GET_METADATA) @@ -405,6 +391,44 @@ class vmmDomain(vmmLibvirtObject): return "-" return str(i) + ################## + # Support checks # + ################## + + def _get_getvcpus_supported(self): + return self.conn.check_domain_support(self._backend, + self.conn.SUPPORT_DOMAIN_GETVCPUS) + getvcpus_supported = property(_get_getvcpus_supported) + + def _get_getjobinfo_supported(self): + return self.conn.check_domain_support(self._backend, + self.conn.SUPPORT_DOMAIN_JOB_INFO) + getjobinfo_supported = property(_get_getjobinfo_supported) + + def snapshots_supported(self): + if not self.conn.check_domain_support( + self._backend, self.conn.SUPPORT_DOMAIN_LIST_SNAPSHOTS): + return _("Libvirt connection does not support snapshots.") + + if self.list_snapshots(): + return + + # Check if our disks are all qcow2 + seen_qcow2 = False + for disk in self.get_disk_devices(refresh_if_nec=False): + if disk.read_only: + continue + if not disk.path: + continue + if disk.driver_type == "qcow2": + seen_qcow2 = True + continue + return _("Snapshots are only supported if all writeable disks " + "images allocated to the guest are qcow2 format.") + if not seen_qcow2: + return _("Snapshots require at least one writeable qcow2 disk " + "image allocated to the guest.") + ############################# # Internal XML handling API # diff --git a/virtManager/snapshots.py b/virtManager/snapshots.py index 0f98ba8b9..458003eb6 100644 --- a/virtManager/snapshots.py +++ b/virtManager/snapshots.py @@ -155,11 +155,6 @@ class vmmSnapshotPage(vmmGObjectUI): model = self.widget("snapshot-list").get_model() model.clear() - if not self.vm.snapshots_supported: - self._set_error_page(_("Libvirt connection does not support " - "snapshots.")) - return - try: snapshots = self.vm.list_snapshots() except Exception, e: