diff --git a/qubesadmin/exc.py b/qubesadmin/exc.py index 169caa7..9fd024e 100644 --- a/qubesadmin/exc.py +++ b/qubesadmin/exc.py @@ -85,6 +85,10 @@ class QubesNoTemplateError(QubesVMError): '''Cannot start domain, because there is no template''' +class QubesVMInUseError(QubesVMError): + '''VM is in use, cannot remove.''' + + class QubesValueError(QubesException, ValueError): '''Cannot set some value, because it is invalid, out of bounds, etc.''' pass diff --git a/qubesadmin/tools/qvm_remove.py b/qubesadmin/tools/qvm_remove.py index ee08c55..b60f66c 100644 --- a/qubesadmin/tools/qvm_remove.py +++ b/qubesadmin/tools/qvm_remove.py @@ -25,6 +25,7 @@ import sys import qubesadmin.exc from qubesadmin.tools import QubesArgumentParser +import qubesadmin.utils parser = QubesArgumentParser(description=__doc__, want_app=True, @@ -47,6 +48,15 @@ def main(args=None, app=None): # pylint: disable=missing-docstring for vm in args.domains: try: del args.app.domains[vm.name] + except qubesadmin.exc.QubesVMInUseError: + dependencies = qubesadmin.utils.vm_dependencies(vm.app, vm) + print("VM {} cannot be removed. It is in use as:".format( + vm.name)) + for (holder, prop) in dependencies: + if holder: + print(" - {} for {}".format(prop, holder.name)) + else: + print(" - global property {}".format(prop)) except qubesadmin.exc.QubesException as e: parser.error_runtime(e) retcode = 0