Skip to content

Commit

Permalink
q-dev: fixes of devices assignment fronted
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrbartman committed Oct 14, 2024
1 parent fe4f02b commit 7ec56ae
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
5 changes: 3 additions & 2 deletions qubesadmin/device_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -1187,8 +1187,9 @@ def device_id(self) -> str:
def devices(self) -> List[DeviceInfo]:
"""Get DeviceInfo objects corresponding to this DeviceAssignment"""
if self.port_id != '*':
# could return UnknownDevice
return [self.backend_domain.devices[self.devclass][self.port_id]]
dv = self.backend_domain.devices[self.devclass][self.port_id]
if isinstance(dv, UnknownDevice) or dv.device_id == self.device_id:
return [dv]
result = []
if self.device_id == "0000:0000::?******":
return result
Expand Down
21 changes: 19 additions & 2 deletions qubesadmin/tools/qvm_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,25 @@ def assign_device(args):
print("Warning: The assigned device is on the denied list: "
f"{DEVICE_DENY_LIST}\n Auto-attach will work, "
f"but make sure that the assignment is correct.")
if (vm.is_running() and not assignment.attached
and assignment.port_id != '*' and not args.quiet):
if vm.is_running() and not args.quiet:
_print_attach_hint(assignment, vm)


def _print_attach_hint(assignment, vm):
if assignment.port_id == '*':
return

try:
plugged = assignment.backend_domain.devices[
assignment.devclass][assignment.port_id]
except KeyError:
return

if isinstance(plugged, UnknownDevice):
return

attached = vm.devices[assignment.devclass].get_attached_devices()
if assignment.matches(plugged) and plugged not in attached:
print("Assigned. To attach you can now restart domain or run: \n"
f"\tqvm-{assignment.devclass} attach {vm} "
f"{assignment.backend_domain}:{assignment.port_id}")
Expand Down

0 comments on commit 7ec56ae

Please sign in to comment.