diff --git a/qubesadmin/devices.py b/qubesadmin/devices.py index a4d254a5..d9fc4d84 100644 --- a/qubesadmin/devices.py +++ b/qubesadmin/devices.py @@ -43,8 +43,10 @@ class is implemented by an extension. UnknownDevice, DeviceAssignment, VirtualDevice, - AssignmentMode, DeviceInterface, + AssignmentMode, + DeviceInterface, ) + if TYPE_CHECKING: from qubesadmin.vm import QubesVM @@ -103,7 +105,7 @@ def assign(self, assignment: DeviceAssignment) -> None: :param DeviceAssignment assignment: device object """ if ( - assignment.devclass not in ("pci", "testclass", "block") + assignment.devclass not in self._vm.app.list_deviceclass() and assignment.required ): raise qubesadmin.exc.QubesValueError( @@ -114,8 +116,7 @@ def assign(self, assignment: DeviceAssignment) -> None: "PCI devices cannot be assigned as not required." ) if ( - assignment.devclass - not in ("testclass", "usb", "block", "mic", "pci") + assignment.devclass not in self._vm.app.list_deviceclass() and assignment.attach_automatically ): raise qubesadmin.exc.QubesValueError( @@ -271,7 +272,7 @@ def get_exposed_devices(self) -> Iterable[DeviceInfo]: ) def update_assignment( - self, device: VirtualDevice, required: AssignmentMode + self, device: VirtualDevice, required: AssignmentMode ) -> None: """ Update assignment of already attached device. @@ -342,8 +343,7 @@ def __missing__(self, key: str) -> DeviceCollection: def __iter__(self) -> Iterator[str]: return iter(self._vm.app.list_deviceclass()) - - def keys(self) -> list[str]: # type: ignore[override] + def keys(self) -> list[str]: # type: ignore[override] return self._vm.app.list_deviceclass() def deny(self, *interfaces: Iterable[DeviceInterface]) -> None: @@ -354,7 +354,7 @@ def deny(self, *interfaces: Iterable[DeviceInterface]) -> None: None, "admin.vm.device.denied.Add", None, - "".join(repr(ifc) for ifc in interfaces).encode('ascii'), + "".join(repr(ifc) for ifc in interfaces).encode("ascii"), ) def allow(self, *interfaces: Iterable[DeviceInterface]) -> None: @@ -365,7 +365,7 @@ def allow(self, *interfaces: Iterable[DeviceInterface]) -> None: None, "admin.vm.device.denied.Remove", None, - "".join(repr(ifc) for ifc in interfaces).encode('ascii'), + "".join(repr(ifc) for ifc in interfaces).encode("ascii"), ) def clear_cache(self) -> None: