Skip to content
This repository has been archived by the owner on Apr 26, 2020. It is now read-only.

Commit

Permalink
Fix serialization of domain states
Browse files Browse the repository at this point in the history
  • Loading branch information
kalkin committed Jun 17, 2017
1 parent 19c6170 commit 7ffe3a6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
3 changes: 2 additions & 1 deletion qubesdbus/domain_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,11 @@ def __init__(self, qubes_data: DBusProperties, domains: List[DBusProperties]) ->
self.managed_objects = [self._proxify_domain(vm) for vm in domains]
self.state_signals = {
'Starting': self.Starting,
'Running' : self.Started,
'Started' : self.Started,
'Failed' : self.Failed,
'Halting' : self.Halting,
'Halted' : self.Halted,
'Unknown' : lambda _, __: None,
}
self.signal_matches = {} # type: Dict[dbus.ObjectPath, List[DBusSignalMatch]]

Expand Down
17 changes: 16 additions & 1 deletion qubesdbus/serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,21 @@ def qubes_data(app):
return result


def serialize_state(state):
state = state.lower()
if state == 'crashed':
return 'Failed'
elif state in ['transient', 'na']:
return 'Unknown'
elif state == 'halted':
return 'Halted'
elif state == 'transient':
return 'Starting'
elif state == 'running':
return 'Started'
else:
return '=>%s<=' % state

def domain_data(vm):
''' Serializes a `qubes.vm.qubesvm.QubesVM` to a dictionary '''
# type: (QubesVM) -> Dict[dbus.String, Any]
Expand All @@ -68,7 +83,7 @@ def domain_data(vm):
result[name] = value

# Additional data
result['state'] = serialize_val(vm.get_power_state())
result['state'] = serialize_state(vm.get_power_state())
result['networked'] = serialize_val(vm.is_networked())
return result

Expand Down

0 comments on commit 7ffe3a6

Please sign in to comment.