Skip to content

Commit 7ec56ae

Browse files
committed
q-dev: fixes of devices assignment fronted
1 parent fe4f02b commit 7ec56ae

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

qubesadmin/device_protocol.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1187,8 +1187,9 @@ def device_id(self) -> str:
11871187
def devices(self) -> List[DeviceInfo]:
11881188
"""Get DeviceInfo objects corresponding to this DeviceAssignment"""
11891189
if self.port_id != '*':
1190-
# could return UnknownDevice
1191-
return [self.backend_domain.devices[self.devclass][self.port_id]]
1190+
dv = self.backend_domain.devices[self.devclass][self.port_id]
1191+
if isinstance(dv, UnknownDevice) or dv.device_id == self.device_id:
1192+
return [dv]
11921193
result = []
11931194
if self.device_id == "0000:0000::?******":
11941195
return result

qubesadmin/tools/qvm_device.py

+19-2
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,25 @@ def assign_device(args):
287287
print("Warning: The assigned device is on the denied list: "
288288
f"{DEVICE_DENY_LIST}\n Auto-attach will work, "
289289
f"but make sure that the assignment is correct.")
290-
if (vm.is_running() and not assignment.attached
291-
and assignment.port_id != '*' and not args.quiet):
290+
if vm.is_running() and not args.quiet:
291+
_print_attach_hint(assignment, vm)
292+
293+
294+
def _print_attach_hint(assignment, vm):
295+
if assignment.port_id == '*':
296+
return
297+
298+
try:
299+
plugged = assignment.backend_domain.devices[
300+
assignment.devclass][assignment.port_id]
301+
except KeyError:
302+
return
303+
304+
if isinstance(plugged, UnknownDevice):
305+
return
306+
307+
attached = vm.devices[assignment.devclass].get_attached_devices()
308+
if assignment.matches(plugged) and plugged not in attached:
292309
print("Assigned. To attach you can now restart domain or run: \n"
293310
f"\tqvm-{assignment.devclass} attach {vm} "
294311
f"{assignment.backend_domain}:{assignment.port_id}")

0 commit comments

Comments
 (0)