@@ -309,24 +309,25 @@ async def detach(self, port: Port):
309
309
"""
310
310
Detach device from domain.
311
311
"""
312
- for assign in self .get_attached_devices ():
313
- if port .port_id == assign .port_id :
312
+ for attached in self .get_attached_devices ():
313
+ if port .port_id == attached .port_id :
314
314
# load all options
315
- assignment = assign
316
315
break
317
316
else :
318
317
raise DeviceNotAssigned (
319
318
f'{ self ._bus } device { port .port_id !s} not '
320
319
f'attached to { self ._vm !s} ' )
321
320
322
- if assignment .required and not self ._vm .is_halted ():
323
- raise qubes .exc .QubesVMNotHaltedError (
324
- self ._vm ,
325
- "Can not detach a required device from a non halted qube. "
326
- "You need to unassign device first." )
321
+ for assign in self .get_assigned_devices ():
322
+ if (assign .required and not self ._vm .is_halted ()
323
+ and assign .matches (attached .device )):
324
+ raise qubes .exc .QubesVMNotHaltedError (
325
+ self ._vm ,
326
+ "Can not detach a required device from a non halted qube. "
327
+ "You need to unassign device first." )
327
328
328
329
# use the local object, only one device can match
329
- port = assignment .device .port
330
+ port = attached .device .port
330
331
await self ._vm .fire_event_async (
331
332
'device-pre-detach:' + self ._bus , pre_event = True , port = port )
332
333
0 commit comments