Skip to content

Commit

Permalink
q-dev: development of auto-attach and required flags
Browse files Browse the repository at this point in the history
mic cannot be auto-attached since we have to wait to pulseaudio client to start first
make auto-attach and required as immutable properties
unassign non-required device from running vm
  • Loading branch information
piotrbartman committed Jun 12, 2024
1 parent 2b033d4 commit 33bb3f2
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions qubes/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,10 +738,6 @@ def required(self) -> bool:
"""
return self.__required

@required.setter
def required(self, required: bool):
self.__required = required

@property
def attach_automatically(self) -> bool:
"""
Expand All @@ -750,10 +746,6 @@ def attach_automatically(self) -> bool:
"""
return self.__attach_automatically

@attach_automatically.setter
def attach_automatically(self, attach_automatically: bool):
self.__attach_automatically = attach_automatically

@property
def options(self) -> Dict[str, Any]:
""" Device options (same as in the legacy API). """
Expand Down Expand Up @@ -1009,11 +1001,12 @@ async def assign(self, assignment: DeviceAssignment):
if (assignment.devclass not in ('pci', 'testclass')
and assignment.required):
raise qubes.exc.QubesValueError(
"Only pci devices can be set as required.")
if (assignment.devclass not in ('pci', 'testclass', 'mic', 'usb')
"Only pci devices can be assigned as required.")
if (assignment.devclass not in ('pci', 'testclass', 'usb')
and assignment.attach_automatically):
raise qubes.exc.QubesValueError(
"Only pci, mic and usb devices can be automatically attached.")
"Only pci and usb devices can be assigned "
"to be automatically attached.")

await self._vm.fire_event_async(
'device-pre-assign:' + self._bus,
Expand Down Expand Up @@ -1113,10 +1106,11 @@ async def unassign(self, device_assignment: DeviceAssignment):
f'device {device_assignment.ident!s} of class {self._bus} not '
f'assigned to {self._vm!s}')

if not self._vm.is_halted():
if not self._vm.is_halted() and assignment.required:
raise qubes.exc.QubesVMNotHaltedError(
self._vm,
"Can not remove an assignment from a non halted qube.")
"Can not remove an required assignment from "
"a non halted qube.")

device = device_assignment.device
await self._vm.fire_event_async(
Expand Down

0 comments on commit 33bb3f2

Please sign in to comment.