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

Commit

Permalink
Port org.qubes.DomainManager1 to new model API
Browse files Browse the repository at this point in the history
- Add constants for SERVICE_NAME & SERVICE_PATH
- Fix initialization.
- Fix ME: Couldn't get MRO right, copy/pasted GetManagedObjects
  • Loading branch information
kalkin committed Jun 27, 2017
1 parent ae3eac0 commit 99f8fb3
Showing 1 changed file with 32 additions and 11 deletions.
43 changes: 32 additions & 11 deletions qubesdbus/domain_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import qubesadmin
import qubesdbus.serialize
from qubesdbus.models import Domain
from qubesdbus.service import ObjectManager, PropertiesObject
from qubesdbus.service import PropertiesObject

import gi # isort:skip
gi.require_version('Gtk', '3.0') # isort:skip
Expand All @@ -45,9 +45,12 @@
DBusString = Union[str, dbus.String]
DBusProperties = Dict[DBusString, Any]

SERVICE_NAME = 'org.qubes.DomainManager1'
SERVICE_PATH = '/org/qubes/DomainManager1'
INTERFACE = 'org.qubes.DomainManager1'

class DomainManager(PropertiesObject, ObjectManager):

class DomainManager(PropertiesObject):
''' The `DomainManager` is the equivalent to the `qubes.Qubes` object for
managing domains. Implements:
* `org.freedesktop.DBus.ObjectManager` interface for acquiring all the
Expand All @@ -57,22 +60,40 @@ class DomainManager(PropertiesObject, ObjectManager):
'''

def __init__(self, qubes_data: DBusProperties, domains: List[DBusProperties]) -> None:
super(DomainManager, self).__init__('DomainManager1', INTERFACE, qubes_data)
bus = dbus.SessionBus()
bus_name = dbus.service.BusName(SERVICE_NAME, bus=bus,
allow_replacement=True,
replace_existing=True)
super().__init__(bus_name, SERVICE_PATH, INTERFACE, qubes_data)
self.bus_name = bus_name
self.bus = bus
self.managed_objects = [self._proxify_domain(vm) for vm in domains]
self.state_signals = {
'Starting': self.Starting,
'Started' : self.Started,
'Failed' : self.Failed,
'Halting' : self.Halting,
'Halted' : self.Halted,
'Unknown' : lambda _, __: None,
'Started': self.Started,
'Failed': self.Failed,
'Halting': self.Halting,
'Halted': self.Halted,
'Unknown': lambda _, __: None,
}
self.signal_matches = {} # type: Dict[dbus.ObjectPath, List[DBusSignalMatch]]
self.signal_matches = {
} # type: Dict[dbus.ObjectPath, List[DBusSignalMatch]]

for domain in self.managed_objects:
obj_path = domain._object_path # pylint: disable=protected-access
obj_path = domain._object_path # pylint: disable=protected-access
self._setup_signals(obj_path)

@dbus.service.method(dbus_interface="org.freedesktop.DBus.ObjectManager",
out_signature="a{oa{sa{sv}}}")
def GetManagedObjects(self):
''' Returns the domain objects paths and their supported interfaces and
properties.
''' # pylint: disable=protected-access
return {
o._object_path: o.properties_iface()
for o in self.managed_objects
}

def _setup_signals(self, obj_path: dbus.ObjectPath):
def emit_state_signal(dbus_interface,
changed_properties: DBusProperties,
Expand Down Expand Up @@ -186,7 +207,7 @@ def RemoveDomain(self, vm_dbus_path, execute=False):

def _proxify_domain(self, vm):
# type: (Dict[Union[str,DBusString], Any]) -> Domain
return Domain(self.bus, self.bus_name, self.bus_path, vm)
return Domain(self.bus_name, SERVICE_PATH, vm)


def main(args=None): # pylint: disable=unused-argument
Expand Down

0 comments on commit 99f8fb3

Please sign in to comment.