Skip to content

Commit

Permalink
vm: add/fix lifecycle-related methods
Browse files Browse the repository at this point in the history
  • Loading branch information
marmarek committed Apr 28, 2017
1 parent e066656 commit 914c2d7
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion qubesmgmt/vm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,38 @@ def get_power_state(self):
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'''
Expand Down

0 comments on commit 914c2d7

Please sign in to comment.