From 247dca6141ef61944bbbfd7cf6aad9da12bd293f Mon Sep 17 00:00:00 2001 From: Piotr Bartman-Szwarc Date: Wed, 14 Aug 2024 22:15:27 +0200 Subject: [PATCH] q-dev: implement device_id --- qubes_config/tests/test_usb_devices.py | 24 +++++++++--------------- qui/decorators.py | 2 +- qui/devices/backend.py | 12 +++++++++--- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/qubes_config/tests/test_usb_devices.py b/qubes_config/tests/test_usb_devices.py index c766200c..b1905fe4 100644 --- a/qubes_config/tests/test_usb_devices.py +++ b/qubes_config/tests/test_usb_devices.py @@ -845,15 +845,13 @@ def test_u2f_handler_add_without_service(test_qapp, def test_devices_handler_unsaved(test_qapp, test_policy_manager, real_builder): test_qapp.expected_calls[('sys-usb', "admin.vm.device.pci.Attached", None, None)] = \ - b"0\x00dom0+00_0d.0 ident='00_0d.0' devclass='pci' " \ + b"0\x00dom0+00_0d.0 device_id='*' port_id='00_0d.0' devclass='pci' " \ b"backend_domain='dom0' required='yes' attach_automatically='yes' " \ b"_no-strict-reset='yes'\n" test_qapp.expected_calls[('dom0', "admin.vm.device.pci.Available", None, None)] = \ - b"0\x0000_0d.0 ident='00_0d.0' devclass='pci' backend_domain='dom0' " \ - b"serial='unknown' manufacturer='unknown' " \ - b"self_identity='0000:0000::p0c0300' vendor='unknown' " \ - b"product='unknown' name='unknown' interfaces='p0c0300' " \ + b"0\x0000_0d.0 device_id='0000:0000::p0c0300' port_id='00_0d.0' " \ + b"devclass='pci' backend_domain='dom0' interfaces='p0c0300' " \ b"_function='0' _bus='00' _libvirt_name='pci_0000_00_0d_0' " \ b"_device='0d'\n" @@ -878,26 +876,22 @@ def test_devices_handler_detect_usbvms(test_qapp, test_policy_manager, real_builder): test_qapp.expected_calls[('sys-usb', "admin.vm.device.pci.Attached", None, None)] = \ - b"0\x00dom0+00_0d.0 ident='00_0d.0' devclass='pci' " \ + b"0\x00dom0+00_0d.0 device_id='*' port_id='00_0d.0' devclass='pci' " \ b"backend_domain='dom0' required='yes' attach_automatically='yes' " \ b"_no-strict-reset='yes'\n" test_qapp.expected_calls[('test-standalone', "admin.vm.device.pci.Attached", None, None)] = \ - b"0\x00dom0+00_0f.0 ident='00_0f.0' devclass='pci' " \ + b"0\x00dom0+00_0f.0 device_id='*' port_id='00_0f.0' devclass='pci' " \ b"backend_domain='dom0' required='yes' attach_automatically='yes' " \ b"_no-strict-reset='yes'\n" test_qapp.expected_calls[('dom0', "admin.vm.device.pci.Available", None, None)] = \ - b"0\x0000_0f.0 ident='00_0f.0' devclass='pci' backend_domain='dom0' " \ - b"serial='unknown' manufacturer='unknown' " \ - b"self_identity='0000:0000::p0c0300' vendor='unknown' " \ - b"product='unknown' name='unknown' interfaces='p0c0300' " \ + b"0\x0000_0f.0 device_id='0000:0000::p0c0300' port_id='00_0f.0' " \ + b"devclass='pci' backend_domain='dom0' interfaces='p0c0300' " \ b"_function='0' _bus='00' _libvirt_name='pci_0000_00_0f_0' " \ b"_device='0f'\n" \ - b"00_0d.0 ident='00_0d.0' devclass='pci' backend_domain='dom0' " \ - b"serial='unknown' manufacturer='unknown' " \ - b"self_identity='0000:0000::p0c0300' vendor='unknown' " \ - b"product='unknown' name='unknown' interfaces='p0c0300' " \ + b"00_0d.0 device_id='0000:0000::p0c0300' port_id='00_0d.0' " \ + b"devclass='pci' backend_domain='dom0' interfaces='p0c0300' " \ b"_function='0' _bus='00' _libvirt_name='pci_0000_00_0d_0' " \ b"_device='0d'\n" diff --git a/qui/decorators.py b/qui/decorators.py index 41b46491..8a76fb6a 100644 --- a/qui/decorators.py +++ b/qui/decorators.py @@ -247,7 +247,7 @@ def device_hbox(device) -> Gtk.Box: dev_icon = create_icon(icon) name_label = Gtk.Label(xalign=0) - name = f"{device.backend_domain}:{device.ident} - {device.description}" + name = f"{device.backend_domain}:{device.port_id} - {device.description}" if device.attachments: dev_list = ", ".join(list(device.attachments)) name_label.set_markup(f'{name} ({dev_list})') diff --git a/qui/devices/backend.py b/qui/devices/backend.py index 449f7d21..58b3b8d7 100644 --- a/qui/devices/backend.py +++ b/qui/devices/backend.py @@ -107,7 +107,7 @@ def __init__(self, dev: qubesadmin.devices.DeviceInfo, if dev.devclass == 'block' and 'size' in dev.data: self._dev_name += " (" + size_to_human(int(dev.data['size'])) + ")" - self._ident: str = getattr(dev, 'ident', 'unknown') + self._ident: str = getattr(dev, 'port_id', 'unknown') self._description: str = getattr(dev, 'description', 'unknown') self._devclass: str = getattr(dev, 'devclass', 'unknown') self._data: Dict = getattr(dev, 'data', {}) @@ -232,7 +232,10 @@ def attach_to_vm(self, vm: VM): """ try: assignment = qubesadmin.device_protocol.DeviceAssignment( - self.backend_domain, self.id_string) + qubesadmin.device_protocol.Device( + qubesadmin.device_protocol.Port( + self.backend_domain, self.id_string, self.device_class) + )) vm.vm_object.devices[self.device_class].attach(assignment) self.gtk_app.emit_notification( @@ -263,7 +266,10 @@ def detach_from_vm(self, vm: VM): notification_id=self.notification_id) try: assignment = qubesadmin.device_protocol.DeviceAssignment( - self.backend_domain, self._ident) + qubesadmin.device_protocol.Device( + qubesadmin.device_protocol.Port( + self.backend_domain, self._ident, self.device_class) + )) vm.vm_object.devices[self.device_class].detach(assignment) except qubesadmin.exc.QubesException as ex: self.gtk_app.emit_notification(