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

Commit

Permalink
Fix startup/shutdown support
Browse files Browse the repository at this point in the history
  • Loading branch information
kalkin committed Oct 3, 2016
1 parent 505732b commit d1bd30b
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 17 deletions.
25 changes: 22 additions & 3 deletions qubesdbus/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

''' D-Bus Domain object '''

import dbus.service
import qubes

import qubesdbus.service

Expand All @@ -38,12 +38,14 @@ class Domain(qubesdbus.service.PropertiesObject):
''' `Domain` is managed by `DomainManager1` and represents a domain. Its D-Bus
object path is `/org/qubes/DomainManager1/domains/QID`
'''

def __init__(self, bus, bus_name, bus_path, data):
# type: (SessionBus, BusName , str, Dict[Union[str,dbus.String], Any]) -> None
self.properties = data
bus_path = '/'.join([bus_path, 'domains', str(data['qid'])])
name = data['name']
super(Domain, self).__init__(name, 'org.qubes.Domain1', data, bus=bus, bus_name=bus_name,
self.name = data['name']
super(Domain, self).__init__(self.name, 'org.qubes.Domain1', data,
bus=bus, bus_name=bus_name,
bus_path=bus_path)

@dbus.service.signal(
Expand All @@ -57,3 +59,20 @@ def StateSignal(self, name):
signature='s')
def StartingSignal(self, name):
self.properties['state'] = name

@dbus.service.method("org.qubes.Domain", out_signature="b")
def Shutdown(self):
app = qubes.Qubes()
name = str(self.name)
vm = app.domains[name]
vm.shutdown(wait=True)
self.properties['state'] = 'halted'
return True

@dbus.service.method("org.qubes.Domain", out_signature="b")
def Start(self):
app = qubes.Qubes()
name = str(self.name)
vm = app.domains[name]
vm.start()
return True
9 changes: 9 additions & 0 deletions qubesdbus/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@ def forward_vm_event(self, vm, event, *args, **kwargs):
log.error('Could not add vm via to dbus DomainManager')
log.info('Added VM %s', data)
self.new_vm.remove(vm)
elif event == 'domain-start':
proxy = vm_proxy(vm.qid)
if kwargs['start_guid'] == True:
property_set(proxy, 'state', 'qrexec_running')
else:
property_set(proxy, 'state', 'running')
elif event == 'domain-shutdown':
proxy = vm_proxy(vm.qid)
property_set(proxy, 'state', 'halted')
else:
log.warn('Unknown %s from %s %s %s', event, vm, args, kwargs)

Expand Down
27 changes: 13 additions & 14 deletions qubesdbus/serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

''' Collection of serialization helpers '''

import dbus
Expand Down Expand Up @@ -110,20 +109,20 @@ def domain_data(vm):
result = dbus.Dictionary({'state': 'halted'}, signature='ss')
for name in DOMAIN_PROPERTIES:
if name in DOMAIN_STATE_PROPERTIES:
key = 'state'
elif name.startswith("is_"):
_, key = name.split("_", 1)
if getattr(vm, name)() is True:
_, value = name.split("_", 1)
name = 'state'
else:
continue
else:
key = name

key = dbus.String(key)
try:

value = serialize_val(getattr(vm, name))

result[key] = value
except (AttributeError, libvirtError):
result[key] = dbus.String('')
try:
value = serialize_val(getattr(vm, name))
except (AttributeError, libvirtError):
value = dbus.String('')
if name.startswith("is_"):
_, name = name.split("_", 1)

result[name] = value
return result


Expand Down

0 comments on commit d1bd30b

Please sign in to comment.