Handle GuiVM properties

This commit is contained in:
Frédéric Pierret (fepitre) 2019-10-20 12:44:27 +02:00
parent a52cb6bb91
commit 27aad9bd38
No known key found for this signature in database
GPG Key ID: 484010B5CDC576E2
3 changed files with 29 additions and 0 deletions

View File

@ -716,6 +716,9 @@ class Qubes(qubes.PropertyHolder):
Methods and attributes:
"""
default_guivm = qubes.VMProperty('default_guivm', load_stage=3,
default=None, allow_none=True,
doc='Default GuiVM for VMs.')
default_netvm = qubes.VMProperty('default_netvm', load_stage=3,
default=None, allow_none=True,
@ -963,6 +966,7 @@ class Qubes(qubes.PropertyHolder):
# stage 5: misc fixups
self.property_require('default_guivm', allow_none=True)
self.property_require('default_netvm', allow_none=True)
self.property_require('default_template', allow_none=True)
self.property_require('clockvm', allow_none=True)
@ -1420,6 +1424,7 @@ class Qubes(qubes.PropertyHolder):
def on_domain_deleted(self, event, vm):
# pylint: disable=unused-argument
for propname in (
'default_guivm'
'default_netvm',
'default_fw_netvm',
'clockvm',

View File

@ -34,6 +34,18 @@ class GUI(qubes.ext.Extension):
if vm.features.get('gui-seamless', False)
else 'FULLSCREEN'))
@qubes.ext.handler('property-set:guivm')
def on_property_set(self, subject, event, name, newvalue, oldvalue=None):
# Clean other 'guivm-XXX' tags.
# gui-daemon can connect to only one domain
tags_list = list(subject.tags)
for tag in tags_list:
if 'guivm-' in tag:
subject.tags.remove(tag)
guivm = 'guivm-' + newvalue.name
subject.tags.add(guivm)
@qubes.ext.handler('domain-qdb-create')
def on_domain_qdb_create(self, vm, event):
# pylint: disable=unused-argument,no-self-use
@ -45,3 +57,12 @@ class GUI(qubes.ext.Extension):
feature))
except KeyError:
pass
# Add GuiVM Xen ID for gui-daemon
try:
if vm.guivm is not None:
if str(vm.name) != str(vm.guivm.name):
vm.untrusted_qdb.write('/qubes-gui-domain-xid',
str(vm.guivm.xid))
except AttributeError:
vm.untrusted_qdb.write('/qubes-gui-domain-xid', '')

View File

@ -518,6 +518,9 @@ class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM):
#
# properties loaded from XML
#
guivm = qubes.VMProperty('guivm', load_stage=4, allow_none=True,
default=(lambda self: self.app.default_guivm),
doc='VM used for Gui')
virt_mode = qubes.property(
'virt_mode',