Skip to content

Commit

Permalink
q-dev: refactor device_protocol.py
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrbartman committed Oct 14, 2024
1 parent cbf3e74 commit 8772108
Show file tree
Hide file tree
Showing 13 changed files with 711 additions and 539 deletions.
4 changes: 2 additions & 2 deletions qubesadmin/backup/core2.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,10 +336,10 @@ def import_core2_vm(self, element):
if pcidevs:
pcidevs = ast.literal_eval(pcidevs)
for pcidev in pcidevs:
ident = pcidev.replace(':', '_')
port_id = pcidev.replace(':', '_')
options = {'no-strict-reset': True} if not pci_strictreset else {}
options['required'] = True
vm.devices['pci'][('dom0', ident)] = options
vm.devices['pci'][('dom0', port_id)] = options

def load(self):
with open(self.store, encoding='utf-8') as fh:
Expand Down
4 changes: 2 additions & 2 deletions qubesadmin/backup/core3.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,14 @@ def import_core3_vm(self, element):
assert bus_name is not None
for node in bus_node.findall('./device'):
backend_domain = node.get('backend-domain')
ident = node.get('id')
port_id = node.get('id')
options = {}
for opt_node in node.findall('./option'):
opt_name = opt_node.get('name')
options[opt_name] = opt_node.text
options['required'] = device_protocol.qbool(
node.get('required', 'yes'))
vm.devices[bus_name][(backend_domain, ident)] = options
vm.devices[bus_name][(backend_domain, port_id)] = options

# extract base properties
if vm.klass == 'AdminVM':
Expand Down
14 changes: 7 additions & 7 deletions qubesadmin/backup/restore.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
from qubesadmin.backup import BackupVM
from qubesadmin.backup.core2 import Core2Qubes
from qubesadmin.backup.core3 import Core3Qubes
from qubesadmin.device_protocol import DeviceAssignment, Port
from qubesadmin.device_protocol import DeviceAssignment, Port, Device
from qubesadmin.exc import QubesException
from qubesadmin.utils import size_to_human

Expand Down Expand Up @@ -2086,19 +2086,19 @@ def _restore_vms_metadata(self, restore_info):
tag, vm.name, err)

for bus in vm.devices:
for backend_domain, ident in vm.devices[bus]:
options = vm.devices[bus][(backend_domain, ident)]
for backend_domain, port_id in vm.devices[bus]:
options = vm.devices[bus][(backend_domain, port_id)]
if 'required' in options:
required = options['required']
del options['required']
else:
required = False
assignment = DeviceAssignment(
Port(
Device(Port(
backend_domain=self.app.domains[backend_domain],
ident=ident,
port_id=port_id,
devclass=bus,
),
)),
options=options,
mode='required' if required else 'auto-attach',
)
Expand All @@ -2107,7 +2107,7 @@ def _restore_vms_metadata(self, restore_info):
new_vm.devices[bus].assign(assignment)
except Exception as err: # pylint: disable=broad-except
self.log.error('Error assigning device %s:%s to %s: %s',
bus, ident, vm.name, err)
bus, port_id, vm.name, err)

# Set VM dependencies - only non-default setting
for vm in vms.values():
Expand Down
Loading

0 comments on commit 8772108

Please sign in to comment.