diff --git a/qubes/app.py b/qubes/app.py index 805a64f4..c87c073c 100644 --- a/qubes/app.py +++ b/qubes/app.py @@ -437,14 +437,17 @@ class VMCollection(object): raise KeyError(key) - def __delitem__(self, key): vm = self[key] + if not vm.is_halted(): + msg = "Can't remove, vm {!s}, beacuse it's in state {!s}." + msg = msg.format(vm, vm.get_power_state()) + raise qubes.exc.QubesVMNotHaltedError(msg) self.app.fire_event_pre('domain-pre-delete', vm) + vm.libvirt_domain.undefine() del self._dict[vm.qid] self.app.fire_event('domain-delete', vm) - def __contains__(self, key): return any((key == vm or key == vm.qid or key == vm.name) for vm in self) diff --git a/qubes/tools/qvm_remove.py b/qubes/tools/qvm_remove.py index e2a813a1..b20bcbaf 100644 --- a/qubes/tools/qvm_remove.py +++ b/qubes/tools/qvm_remove.py @@ -40,12 +40,8 @@ parser.add_argument('--just-db', def main(args=None): # pylint: disable=missing-docstring args = parser.parse_args(args) for vm in args.domains: - if not vm.is_halted(): - parser.print_error('VM {!s} not halted'.format(vm)) - return 1 del args.app.domains[vm.qid] args.app.save() - vm.libvirt_domain.undefine() if not args.just_db: vm.remove_from_disk() diff --git a/qubes/vm/qubesvm.py b/qubes/vm/qubesvm.py index afe1a21e..0db875eb 100644 --- a/qubes/vm/qubesvm.py +++ b/qubes/vm/qubesvm.py @@ -1089,6 +1089,11 @@ class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM): def remove_from_disk(self): '''Remove domain remnants from disk.''' + if not self.is_halted(): + msg = "Can't remove, vm {!s}, beacuse it's in state {!s}." + msg = msg.format(self, self.get_power_state()) + raise qubes.exc.QubesVMNotHaltedError(msg) + self.fire_event('domain-remove-from-disk') self.storage.remove() shutil.rmtree(self.dir_path)