From d46bf2aa8e512c9cca396e936f42f89c75fce212 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marta=20Marczykowska-G=C3=B3recka?= Date: Wed, 18 Jul 2018 23:51:37 +0200 Subject: [PATCH] Improved communication on Remove VM in Qube Manager When a user tries to remove a VM that's used by other VMs or Global Settings from Qube Manager, they get information about where the VM is used. Depends on https://github.com/QubesOS/qubes-core-admin-client/pull/73 --- qubesmanager/qube_manager.py | 41 +++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/qubesmanager/qube_manager.py b/qubesmanager/qube_manager.py index 5d6d88f..afc59ce 100644 --- a/qubesmanager/qube_manager.py +++ b/qubesmanager/qube_manager.py @@ -35,6 +35,7 @@ from pydbus import SessionBus from qubesadmin import Qubes from qubesadmin import exc +from qubesadmin import utils from PyQt4 import QtGui # pylint: disable=import-error from PyQt4 import QtCore # pylint: disable=import-error @@ -685,21 +686,31 @@ class VmManagerWindow(ui_qubemanager.Ui_VmManagerWindow, QtGui.QMainWindow): vm = self.get_selected_vm() - if vm.klass == 'TemplateVM': - dependent_vms = 0 - for single_vm in self.qubes_app.domains: - if getattr(single_vm, 'template', None) == vm: - dependent_vms += 1 - if dependent_vms > 0: - QtGui.QMessageBox.warning( - None, self.tr("Warning!"), - self.tr("This Template Qube cannot be removed, " - "because there is at least one Qube that is based " - "on it.
If you want to remove this " - "Template Qube and all the Qubes based on it, you " - "should first remove each individual Qube that " - "uses this template.")) - return + dependencies = utils.vm_usage(self.qubes_app, vm) + + if dependencies: + list_text = "
" + for (holder, prop) in dependencies: + if holder is None: + list_text += "- Global property {}
".format(prop) + else: + list_text += "- {} for qube {}
".format( + prop, holder.name) + list_text += "
" + + info_dialog = QtGui.QMessageBox(self) + info_dialog.setWindowTitle(self.tr("Warning!")) + info_dialog.setText( + self.tr("This qube cannot be removed. It is used as:" + "
" + list_text + "If you want to " + " remove this qube, you should remove or change " + " settings of each qube or setting that uses" + " it.")) + info_dialog.setModal(False) + info_dialog.show() + self.qt_app.processEvents() + + return (requested_name, ok) = QtGui.QInputDialog.getText( None, self.tr("Qube Removal Confirmation"),