Blob Blame History Raw
From d82576e5cfc66b93fd618a115077454030da6ad2 Mon Sep 17 00:00:00 2001
Message-Id: <d82576e5cfc66b93fd618a115077454030da6ad2@dist-git>
From: Pavel Hrdina <phrdina@redhat.com>
Date: Fri, 24 Nov 2017 17:26:59 +0100
Subject: [PATCH] delete: undefine only persistent domain

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1517119

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
(cherry picked from commit b9bc3b605a96920d3e225d472d549864205e92ce)
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
---
 virtManager/delete.py | 6 ++++--
 virtManager/domain.py | 3 +++
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/virtManager/delete.py b/virtManager/delete.py
index 98df413b..0ebfdeb5 100644
--- a/virtManager/delete.py
+++ b/virtManager/delete.py
@@ -162,6 +162,7 @@ class vmmDeleteDialog(vmmGObjectUI):
     def _async_delete(self, asyncjob, paths):
         storage_errors = []
         details = ""
+        undefine = self.vm.is_persistent()
 
         try:
             if self.vm.is_active():
@@ -181,8 +182,9 @@ class vmmDeleteDialog(vmmGObjectUI):
                                           "".join(traceback.format_exc())))
                 meter.end(0)
 
-            logging.debug("Removing VM '%s'", self.vm.get_name())
-            self.vm.delete()
+            if undefine:
+                logging.debug("Removing VM '%s'", self.vm.get_name())
+                self.vm.delete()
 
         except Exception as e:
             error = (_("Error deleting virtual machine '%s': %s") %
diff --git a/virtManager/domain.py b/virtManager/domain.py
index 724f83fd..b1e600c7 100644
--- a/virtManager/domain.py
+++ b/virtManager/domain.py
@@ -484,6 +484,9 @@ class vmmDomain(vmmLibvirtObject):
         return bool(self.get_xmlobj().os.loader_ro is True and
                     self.get_xmlobj().os.loader_type == "pflash")
 
+    def is_persistent(self):
+        return bool(self._backend.isPersistent())
+
     ##################
     # Support checks #
     ##################
-- 
2.14.3