qubes/vm: move misc XML tags loading to separate method
This commit is contained in:
parent
a5e575618c
commit
0293c1c7ef
@ -439,6 +439,16 @@ class PropertyHolder(qubes.events.Emitter):
|
|||||||
for key, value in propvalues.items():
|
for key, value in propvalues.items():
|
||||||
setattr(self, key, value)
|
setattr(self, key, value)
|
||||||
|
|
||||||
|
if self.xml is not None:
|
||||||
|
# check if properties are appropriate
|
||||||
|
all_names = set(prop.__name__ for prop in self.property_list())
|
||||||
|
|
||||||
|
for node in self.xml.xpath('./properties/property'):
|
||||||
|
name = node.get('name')
|
||||||
|
if name not in all_names:
|
||||||
|
raise TypeError(
|
||||||
|
'property {!r} not applicable to {!r}'.format(
|
||||||
|
name, self.__class__.__name__))
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def property_list(cls, load_stage=None):
|
def property_list(cls, load_stage=None):
|
||||||
|
@ -700,6 +700,7 @@ class Qubes(qubes.PropertyHolder):
|
|||||||
# stage 4: fill all remaining VM properties
|
# stage 4: fill all remaining VM properties
|
||||||
for vm in self.domains:
|
for vm in self.domains:
|
||||||
vm.load_properties(load_stage=4)
|
vm.load_properties(load_stage=4)
|
||||||
|
vm.load_extras()
|
||||||
|
|
||||||
# stage 5: misc fixups
|
# stage 5: misc fixups
|
||||||
|
|
||||||
|
@ -83,6 +83,7 @@ class TC_10_BaseVM(qubes.tests.QubesTestCase):
|
|||||||
node = self.xml.xpath('//domain')[0]
|
node = self.xml.xpath('//domain')[0]
|
||||||
vm = TestVM(None, node)
|
vm = TestVM(None, node)
|
||||||
vm.load_properties(load_stage=None)
|
vm.load_properties(load_stage=None)
|
||||||
|
vm.load_extras()
|
||||||
|
|
||||||
self.assertEqual(vm.qid, 1)
|
self.assertEqual(vm.qid, 1)
|
||||||
self.assertEqual(vm.testprop, 'testvalue')
|
self.assertEqual(vm.testprop, 'testvalue')
|
||||||
|
@ -183,39 +183,29 @@ class BaseVM(qubes.PropertyHolder):
|
|||||||
#: user-specified tags
|
#: user-specified tags
|
||||||
self.tags = tags or {}
|
self.tags = tags or {}
|
||||||
|
|
||||||
if self.xml is not None:
|
|
||||||
# features
|
|
||||||
for node in xml.xpath('./features/feature'):
|
|
||||||
self.features[node.get('name')] = node.text
|
|
||||||
|
|
||||||
# devices (pci, usb, ...)
|
|
||||||
for parent in xml.xpath('./devices'):
|
|
||||||
devclass = parent.get('class')
|
|
||||||
for node in parent.xpath('./device'):
|
|
||||||
self.devices[devclass].attach(node.text)
|
|
||||||
|
|
||||||
# tags
|
|
||||||
for node in xml.xpath('./tags/tag'):
|
|
||||||
self.tags[node.get('name')] = node.text
|
|
||||||
|
|
||||||
# SEE:1815 firewall, policy.
|
|
||||||
|
|
||||||
# check if properties are appropriate
|
|
||||||
all_names = set(prop.__name__ for prop in self.property_list())
|
|
||||||
|
|
||||||
for node in self.xml.xpath('./properties/property'):
|
|
||||||
name = node.get('name')
|
|
||||||
if name not in all_names:
|
|
||||||
raise TypeError(
|
|
||||||
'property {!r} not applicable to {!r}'.format(
|
|
||||||
name, self.__class__.__name__))
|
|
||||||
|
|
||||||
#: logger instance for logging messages related to this VM
|
#: logger instance for logging messages related to this VM
|
||||||
self.log = None
|
self.log = None
|
||||||
|
|
||||||
if hasattr(self, 'name'):
|
if hasattr(self, 'name'):
|
||||||
self.init_log()
|
self.init_log()
|
||||||
|
|
||||||
|
def load_extras(self):
|
||||||
|
# features
|
||||||
|
for node in self.xml.xpath('./features/feature'):
|
||||||
|
self.features[node.get('name')] = node.text
|
||||||
|
|
||||||
|
# devices (pci, usb, ...)
|
||||||
|
for parent in self.xml.xpath('./devices'):
|
||||||
|
devclass = parent.get('class')
|
||||||
|
for node in parent.xpath('./device'):
|
||||||
|
self.devices[devclass].attach(node.text)
|
||||||
|
|
||||||
|
# tags
|
||||||
|
for node in self.xml.xpath('./tags/tag'):
|
||||||
|
self.tags[node.get('name')] = node.text
|
||||||
|
|
||||||
|
# SEE:1815 firewall, policy.
|
||||||
|
|
||||||
def init_log(self):
|
def init_log(self):
|
||||||
'''Initialise logger for this domain.'''
|
'''Initialise logger for this domain.'''
|
||||||
self.log = qubes.log.get_vm_logger(self.name)
|
self.log = qubes.log.get_vm_logger(self.name)
|
||||||
|
Loading…
Reference in New Issue
Block a user