Better information on error in qvm-remove

If qvm-remove fails because the VM is in use, it will display
information about where it is used.

fixes QubesOS/qubes-issues#3193
This commit is contained in:
Marta Marczykowska-Górecka 2018-07-20 00:21:47 +02:00
parent ca848ca7bd
commit ad2a6e3408
No known key found for this signature in database
GPG Key ID: 9A752C30B26FD04B
2 changed files with 14 additions and 0 deletions

View File

@ -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

View File

@ -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