vm/adminvm: don't base AdminVM on QubesVM

dom0 isn't real VM and most properties doesn't apply to it. Lets make it
more explicit.
This commit is contained in:
Marek Marczykowski-Górecki 2017-04-01 01:25:57 +02:00
parent 67fcda2cde
commit fa1da422d1
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724
6 changed files with 38 additions and 34 deletions

View File

@ -907,8 +907,7 @@ class Qubes(qubes.PropertyHolder):
self.pools[name] = self._get_pool(**config)
self.domains.add(
qubes.vm.adminvm.AdminVM(self, None, qid=0, name='dom0',
label='black'))
qubes.vm.adminvm.AdminVM(self, None, label='black'))
@classmethod
def create_empty_store(cls, *args, **kwargs):
@ -1122,7 +1121,7 @@ class Qubes(qubes.PropertyHolder):
oldvalue=None):
# pylint: disable=unused-argument
for vm in self.domains:
if vm.property_is_default('netvm'):
if hasattr(vm, 'netvm') and vm.property_is_default('netvm'):
# fire property-del:netvm as it is responsible for resetting
# netvm to it's default value
vm.fire_event('property-del:netvm',

View File

@ -30,6 +30,7 @@ import datetime
import qubes
import qubes.exc
import qubes.config
import qubes.vm
import qubes.vm.qubesvm
import qubes.tests
@ -131,12 +132,12 @@ class TC_00_setters(qubes.tests.QubesTestCase):
def test_030_setter_label_object(self):
label = TestApp.labels[1]
self.assertIs(label,
qubes.vm.qubesvm._setter_label(self.vm, self.prop, label))
qubes.vm.setter_label(self.vm, self.prop, label))
def test_031_setter_label_getitem(self):
label = TestApp.labels[1]
self.assertIs(label,
qubes.vm.qubesvm._setter_label(self.vm, self.prop, 'label-1'))
qubes.vm.setter_label(self.vm, self.prop, 'label-1'))
# there is no check for self.app.get_label()

View File

@ -446,3 +446,14 @@ class VMProperty(qubes.property):
return untrusted_vmname
validate_name(None, self, untrusted_vmname)
return untrusted_vmname
def setter_label(self, prop, value):
''' Helper for setting the domain label '''
# pylint: disable=unused-argument
if isinstance(value, qubes.Label):
return value
if isinstance(value, str) and value.startswith('label-'):
return self.app.labels[int(value.split('-', 1)[1])]
return self.app.get_label(value)

View File

@ -26,28 +26,28 @@
import libvirt
import qubes
import qubes.exc
import qubes.vm.qubesvm
import qubes.vm
class AdminVM(qubes.vm.qubesvm.QubesVM):
class AdminVM(qubes.vm.BaseVM):
'''Dom0'''
dir_path = None
netvm = qubes.property('netvm', setter=qubes.property.forbidden,
default=None,
doc='Dom0 cannot have netvm')
name = qubes.property('name',
default='dom0', setter=qubes.property.forbidden)
kernel = qubes.property('netvm', setter=qubes.property.forbidden,
default=None,
doc='There are other ways to set kernel for Dom0.')
label = qubes.property('label',
setter=qubes.vm.setter_label,
saver=(lambda self, prop, value: 'label-{}'.format(value.index)),
doc='''Colourful label assigned to VM. This is where the colour of the
padlock is set.''')
memory = qubes.property('memory', setter=qubes.property.forbidden,
default=lambda self: self.get_mem(),
doc='Memory currently assigned to dom0.')
qid = qubes.property('qid',
default=0, setter=qubes.property.forbidden)
maxmem = qubes.property('maxmem', setter=qubes.property.forbidden,
default=lambda self: self.get_mem_static_max(),
doc='Maximum dom0 memory size, modify using xen boot options.')
uuid = qubes.property('uuid',
default='00000000-0000-0000-0000-000000000000',
setter=qubes.property.forbidden)
@property
def attached_volumes(self):
@ -71,7 +71,8 @@ class AdminVM(qubes.vm.qubesvm.QubesVM):
'''
return None
def is_running(self):
@staticmethod
def is_running():
'''Always :py:obj:`True`.
.. seealso:
@ -79,7 +80,8 @@ class AdminVM(qubes.vm.qubesvm.QubesVM):
'''
return True
def get_power_state(self):
@staticmethod
def get_power_state():
'''Always ``'Running'``.
.. seealso:
@ -87,7 +89,8 @@ class AdminVM(qubes.vm.qubesvm.QubesVM):
'''
return 'Running'
def get_mem(self):
@staticmethod
def get_mem():
'''Get current memory usage of Dom0.
Unit is KiB.

View File

@ -166,7 +166,7 @@ class NetVMMixin(qubes.events.Emitter):
NetVM.
'''
for vm in self.app.domains:
if vm.netvm is self:
if getattr(vm, 'netvm', None) is self:
yield vm
#

View File

@ -118,16 +118,6 @@ def _setter_kernel(self, prop, value):
return value
def _setter_label(self, prop, value):
''' Helper for setting the domain label '''
# pylint: disable=unused-argument
if isinstance(value, qubes.Label):
return value
if isinstance(value, str) and value.startswith('label-'):
return self.app.labels[int(value.split('-', 1)[1])]
return self.app.get_label(value)
def _setter_positive_int(self, prop, value):
''' Helper for setting a positive int. Checks that the int is >= 0 '''
# pylint: disable=unused-argument
@ -376,7 +366,7 @@ class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM):
#
label = qubes.property('label',
setter=_setter_label,
setter=qubes.vm.setter_label,
saver=(lambda self, prop, value: 'label-{}'.format(value.index)),
doc='''Colourful label assigned to VM. This is where the colour of the
padlock is set.''')