Dumb down qvm-remove
- Move `vm.is_halted()` check in to VMCollection.__delitem__() - `vm.remove_from_disk()` will raise exception if is called on a running vm
This commit is contained in:
parent
63a1edc274
commit
de5487bf14
@ -437,14 +437,17 @@ class VMCollection(object):
|
|||||||
|
|
||||||
raise KeyError(key)
|
raise KeyError(key)
|
||||||
|
|
||||||
|
|
||||||
def __delitem__(self, key):
|
def __delitem__(self, key):
|
||||||
vm = 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)
|
self.app.fire_event_pre('domain-pre-delete', vm)
|
||||||
|
vm.libvirt_domain.undefine()
|
||||||
del self._dict[vm.qid]
|
del self._dict[vm.qid]
|
||||||
self.app.fire_event('domain-delete', vm)
|
self.app.fire_event('domain-delete', vm)
|
||||||
|
|
||||||
|
|
||||||
def __contains__(self, key):
|
def __contains__(self, key):
|
||||||
return any((key == vm or key == vm.qid or key == vm.name)
|
return any((key == vm or key == vm.qid or key == vm.name)
|
||||||
for vm in self)
|
for vm in self)
|
||||||
|
@ -40,12 +40,8 @@ parser.add_argument('--just-db',
|
|||||||
def main(args=None): # pylint: disable=missing-docstring
|
def main(args=None): # pylint: disable=missing-docstring
|
||||||
args = parser.parse_args(args)
|
args = parser.parse_args(args)
|
||||||
for vm in args.domains:
|
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]
|
del args.app.domains[vm.qid]
|
||||||
args.app.save()
|
args.app.save()
|
||||||
vm.libvirt_domain.undefine()
|
|
||||||
if not args.just_db:
|
if not args.just_db:
|
||||||
vm.remove_from_disk()
|
vm.remove_from_disk()
|
||||||
|
|
||||||
|
@ -1089,6 +1089,11 @@ class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM):
|
|||||||
|
|
||||||
def remove_from_disk(self):
|
def remove_from_disk(self):
|
||||||
'''Remove domain remnants from disk.'''
|
'''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.fire_event('domain-remove-from-disk')
|
||||||
self.storage.remove()
|
self.storage.remove()
|
||||||
shutil.rmtree(self.dir_path)
|
shutil.rmtree(self.dir_path)
|
||||||
|
Loading…
Reference in New Issue
Block a user