From 914c2d7e5ef90dd6d7807b31271d3397bc2f36f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Sat, 15 Apr 2017 14:22:30 +0200 Subject: [PATCH] vm: add/fix lifecycle-related methods --- qubesmgmt/vm/__init__.py | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/qubesmgmt/vm/__init__.py b/qubesmgmt/vm/__init__.py index 522fb8a..03a7119 100644 --- a/qubesmgmt/vm/__init__.py +++ b/qubesmgmt/vm/__init__.py @@ -167,9 +167,38 @@ class QubesVM(qubesmgmt.base.PropertyHolder): vm_list_info = self.qubesd_call( self._method_dest, 'mgmt.vm.List', None, None).decode('ascii') # name class=... state=... other=... - vm_state = vm_list_info.partition('state=')[2].split(' ')[0] + vm_state = vm_list_info.strip().partition('state=')[2].split(' ')[0] return vm_state + + 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_paused(self): + '''Check whether this domain is paused. + + :returns: :py:obj:`True` if this domain is paused, \ + :py:obj:`False` otherwise. + :rtype: bool + ''' + + return self.get_power_state() == 'Paused' + + def is_running(self): + '''Check whether this domain is running. + + :returns: :py:obj:`True` if this domain is started, \ + :py:obj:`False` otherwise. + :rtype: bool + ''' + + return self.get_power_state() != 'Halted' + @property def volumes(self): '''VM disk volumes'''