[virt-tools-list] [virt-manager PATCH] virtManager: disable 'Clone' in VMActionMenu if VM can't be cloned

Chen Hanxiao chen_han_xiao at 126.com
Wed Sep 21 03:59:45 UTC 2016


From: Chen Hanxiao <chenhanxiao at gmail.com>

We can't clone a VM in some scenarios,
such as a VM is active.

This patch will disable 'Clone' label in VMActionMenu
if we can't clone a VM,
as same as we did for 'Clone' button in clone ui page.

Signed-off-by: Chen Hanxiao <chenhanxiao at gmail.com>
---
 virtManager/domain.py | 4 ++++
 virtManager/vmmenu.py | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/virtManager/domain.py b/virtManager/domain.py
index a707f25..582de64 100644
--- a/virtManager/domain.py
+++ b/virtManager/domain.py
@@ -1655,6 +1655,10 @@ class vmmDomain(vmmLibvirtObject):
         return self.status() in [libvirt.VIR_DOMAIN_PAUSED]
     def is_paused(self):
         return self.status() in [libvirt.VIR_DOMAIN_PAUSED]
+    def is_clonable(self):
+        return self.status() in [libvirt.VIR_DOMAIN_SHUTOFF,
+                                 libvirt.VIR_DOMAIN_PAUSED,
+                                 libvirt.VIR_DOMAIN_PMSUSPENDED]
 
     def run_status(self):
         return self.pretty_run_status(self.status(), self.has_managed_save())
diff --git a/virtManager/vmmenu.py b/virtManager/vmmenu.py
index a1ae375..bb23360 100644
--- a/virtManager/vmmenu.py
+++ b/virtManager/vmmenu.py
@@ -128,7 +128,7 @@ class VMActionMenu(_VMMenu):
             "suspend": bool(vm and vm.is_stoppable()),
             "resume": bool(vm and vm.is_paused()),
             "migrate": bool(vm and vm.is_stoppable()),
-            "clone": True,
+            "clone": bool(vm and vm.is_clonable()),
         }
         vismap = {
             "suspend": bool(vm and not vm.is_paused()),
-- 
1.8.3.1





More information about the virt-tools-list mailing list