From 9132690eef07c38ccdb29f2237b51e3c07d600a4 Mon Sep 17 00:00:00 2001 From: Bahtiar `kalkin-` Gadimov Date: Thu, 16 Jun 2016 21:06:20 +0200 Subject: [PATCH] Add QubesVM.is_halted() --- qubes/vm/qubesvm.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/qubes/vm/qubesvm.py b/qubes/vm/qubesvm.py index 4fc9af7f..af8d3c66 100644 --- a/qubes/vm/qubesvm.py +++ b/qubes/vm/qubesvm.py @@ -769,7 +769,7 @@ class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM): when domain is already shut down. ''' - if not self.is_running(): # TODO not self.is_halted() + if self.is_halted(): raise qubes.exc.QubesVMNotStartedError(self) self.fire_event_pre('domain-pre-shutdown', force=force) @@ -1188,7 +1188,7 @@ class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM): :param qubes.vm.qubesvm.QubesVM src: source VM ''' - if src.is_running(): # XXX what about paused? + if not self.is_halted(): raise qubes.exc.QubesVMNotHaltedError( self, 'Cannot clone a running domain {!r}'.format(self.name)) @@ -1359,6 +1359,13 @@ class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM): assert False + def is_halted(self): + ''' Check whether this domain's state is 'Halted' + :returns: :py:obj:`True` if this domain is halted, \ + :py:obj:`False` otherwise. + :rtype: bool + ''' + return self.get_power_state() == 'Halted' def is_running(self): '''Check whether this domain is running.