diff --git a/qubes/api/admin.py b/qubes/api/admin.py index 03c2ba952..bc6dcd866 100644 --- a/qubes/api/admin.py +++ b/qubes/api/admin.py @@ -1912,9 +1912,12 @@ async def vm_device_list(self, endpoint): async def vm_device_attached(self, endpoint): devclass = endpoint try: - device_assignments = self.dest.devices[ - devclass - ].get_attached_devices() + if self.dest.klass == "RemoteVM": + device_assignments = [] + else: + device_assignments = self.dest.devices[ + devclass + ].get_attached_devices() except AttributeError as e: if e.name == "devices": # shutdown in progress, return specific error @@ -1984,6 +1987,9 @@ async def vm_device_assign(self, endpoint, untrusted_payload): options=assignment.options, ) + if not hasattr(self.dest, "devices"): + raise qubes.exc.QubesException("This qube doesn't support devices") + await self.dest.devices[devclass].assign(assignment) self.app.save() @@ -2026,6 +2032,9 @@ async def vm_device_unassign(self, endpoint): self.fire_event_for_permission(device=dev) + if not hasattr(self.dest, "devices"): + raise qubes.exc.QubesException("This qube doesn't support devices") + await self.dest.devices[devclass].unassign(assignment) self.app.save() @@ -2054,6 +2063,9 @@ async def vm_device_attach(self, endpoint, untrusted_payload): device=dev, mode=assignment.mode.value, options=assignment.options ) + if not hasattr(self.dest, "devices"): + raise qubes.exc.QubesException("This qube doesn't support devices") + await self.dest.devices[devclass].attach(assignment) # Attach/Detach action can modify only a volatile state of running VM. @@ -2076,6 +2088,9 @@ async def vm_device_detach(self, endpoint): self.fire_event_for_permission(device=dev) + if not hasattr(self.dest, "devices"): + raise qubes.exc.QubesException("This qube doesn't support devices") + assignment = qubes.device_protocol.DeviceAssignment(dev) await self.dest.devices[devclass].detach(assignment) diff --git a/qubes/ext/block.py b/qubes/ext/block.py index 37f024708..6e5756962 100644 --- a/qubes/ext/block.py +++ b/qubes/ext/block.py @@ -219,7 +219,7 @@ def attachment(self) -> Optional[QubesVM]: if not self.backend_domain or not self.backend_domain.is_running(): return None for vm in self.backend_domain.app.domains: - if not vm.is_running(): + if not vm.is_running() or not hasattr(vm, "libvirt_domain"): continue if self._is_attached_to(vm): return vm