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

View File

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

View File

@ -446,3 +446,14 @@ class VMProperty(qubes.property):
return untrusted_vmname return untrusted_vmname
validate_name(None, self, untrusted_vmname) validate_name(None, self, untrusted_vmname)
return 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 libvirt
import qubes import qubes
import qubes.exc import qubes.exc
import qubes.vm.qubesvm import qubes.vm
class AdminVM(qubes.vm.qubesvm.QubesVM): class AdminVM(qubes.vm.BaseVM):
'''Dom0''' '''Dom0'''
dir_path = None dir_path = None
netvm = qubes.property('netvm', setter=qubes.property.forbidden, name = qubes.property('name',
default=None, default='dom0', setter=qubes.property.forbidden)
doc='Dom0 cannot have netvm')
kernel = qubes.property('netvm', setter=qubes.property.forbidden, label = qubes.property('label',
default=None, setter=qubes.vm.setter_label,
doc='There are other ways to set kernel for Dom0.') 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, qid = qubes.property('qid',
default=lambda self: self.get_mem(), default=0, setter=qubes.property.forbidden)
doc='Memory currently assigned to dom0.')
maxmem = qubes.property('maxmem', setter=qubes.property.forbidden, uuid = qubes.property('uuid',
default=lambda self: self.get_mem_static_max(), default='00000000-0000-0000-0000-000000000000',
doc='Maximum dom0 memory size, modify using xen boot options.') setter=qubes.property.forbidden)
@property @property
def attached_volumes(self): def attached_volumes(self):
@ -71,7 +71,8 @@ class AdminVM(qubes.vm.qubesvm.QubesVM):
''' '''
return None return None
def is_running(self): @staticmethod
def is_running():
'''Always :py:obj:`True`. '''Always :py:obj:`True`.
.. seealso: .. seealso:
@ -79,7 +80,8 @@ class AdminVM(qubes.vm.qubesvm.QubesVM):
''' '''
return True return True
def get_power_state(self): @staticmethod
def get_power_state():
'''Always ``'Running'``. '''Always ``'Running'``.
.. seealso: .. seealso:
@ -87,7 +89,8 @@ class AdminVM(qubes.vm.qubesvm.QubesVM):
''' '''
return 'Running' return 'Running'
def get_mem(self): @staticmethod
def get_mem():
'''Get current memory usage of Dom0. '''Get current memory usage of Dom0.
Unit is KiB. Unit is KiB.

View File

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

View File

@ -118,16 +118,6 @@ def _setter_kernel(self, prop, value):
return 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): def _setter_positive_int(self, prop, value):
''' Helper for setting a positive int. Checks that the int is >= 0 ''' ''' Helper for setting a positive int. Checks that the int is >= 0 '''
# pylint: disable=unused-argument # pylint: disable=unused-argument
@ -376,7 +366,7 @@ class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM):
# #
label = qubes.property('label', label = qubes.property('label',
setter=_setter_label, setter=qubes.vm.setter_label,
saver=(lambda self, prop, value: 'label-{}'.format(value.index)), saver=(lambda self, prop, value: 'label-{}'.format(value.index)),
doc='''Colourful label assigned to VM. This is where the colour of the doc='''Colourful label assigned to VM. This is where the colour of the
padlock is set.''') padlock is set.''')