qubes/core2migration: rework load order

To successfully load all the data, proceed in order:
- set app.default_kernel
- load all templates
- set app.default_template
- load other VMs
- update network dependencies between VMs
- set other global properties
This commit is contained in:
Marek Marczykowski-Górecki 2016-05-21 03:36:17 +02:00 committed by Wojtek Porczyk
parent 554a99610f
commit 574834ac68

View File

@ -60,11 +60,12 @@ class Core2Qubes(qubes.Qubes):
raise ValueError("store path required")
super(Core2Qubes, self).__init__(store, load, **kwargs)
def load_globals(self, element):
def load_default_template(self, element):
default_template = element.get("default_template")
self.default_template = int(default_template) \
if default_template.lower() != "none" else None
def load_globals(self, element):
default_netvm = element.get("default_netvm")
if default_netvm is not None:
self.default_netvm = int(default_netvm) \
@ -85,7 +86,6 @@ class Core2Qubes(qubes.Qubes):
self.clockvm = int(clockvm) \
if clockvm != "None" else None
self.default_kernel = element.get("default_kernel")
def set_netvm_dependency(self, element):
kwargs = {}
@ -110,28 +110,8 @@ class Core2Qubes(qubes.Qubes):
# TODO: dispvm_netvm
def load(self):
qubes_store_file = open(self._store, 'r')
try:
qubes_store_file.seek(0)
tree = lxml.etree.parse(qubes_store_file)
except (EnvironmentError,
xml.parsers.expat.ExpatError) as err:
self.log.error(err)
return False
self.load_initial_values()
vm_classes = ["TemplateVm", "TemplateHVm",
"AppVm", "HVm", "NetVm", "ProxyVm"]
for (vm_class_name) in vm_classes:
vms_of_class = tree.findall("Qubes" + vm_class_name)
# first non-template based, then template based
sorted_vms_of_class = sorted(vms_of_class,
key=lambda x: str(x.get('template_qid')).lower() != "none")
for element in sorted_vms_of_class:
def import_core2_vm(self, element):
vm_class_name = element.tag
try:
kwargs = {}
if vm_class_name in ["TemplateVm", "TemplateHVm"]:
@ -196,6 +176,41 @@ class Core2Qubes(qubes.Qubes):
if 'vm' in locals():
del self.domains[vm]
def load(self):
qubes_store_file = open(self._store, 'r')
try:
qubes_store_file.seek(0)
tree = lxml.etree.parse(qubes_store_file)
except (EnvironmentError,
xml.parsers.expat.ExpatError) as err:
self.log.error(err)
return False
self.load_initial_values()
self.default_kernel = tree.getroot().get("default_kernel")
vm_classes = ["TemplateVm", "TemplateHVm",
"AppVm", "HVm", "NetVm", "ProxyVm"]
# First load templates
for vm_class_name in ["TemplateVm", "TemplateHVm"]:
vms_of_class = tree.findall("Qubes" + vm_class_name)
for element in vms_of_class:
self.import_core2_vm(element)
# Then set default template ...
self.load_default_template(tree.getroot())
# ... and load other VMs
for vm_class_name in ["AppVm", "HVm", "NetVm", "ProxyVm"]:
vms_of_class = tree.findall("Qubes" + vm_class_name)
# first non-template based, then template based
sorted_vms_of_class = sorted(vms_of_class,
key=lambda x: str(x.get('template_qid')).lower() != "none")
for element in sorted_vms_of_class:
self.import_core2_vm(element)
# After importing all VMs, set netvm references, in the same order
for vm_class_name in vm_classes:
for element in tree.findall("Qubes" + vm_class_name):
@ -205,6 +220,7 @@ class Core2Qubes(qubes.Qubes):
self.log.error("VM {}: failed to set netvm dependency: {}".
format(element.get('name'), err))
# and load other defaults (default netvm, updatevm etc)
self.load_globals(tree.getroot())
def save(self):