Skip to content

Commit

Permalink
q-dev: @marmarek comments
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrbartman committed May 26, 2024
1 parent de0e882 commit 2e31a4b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 26 deletions.
14 changes: 0 additions & 14 deletions qubesadmin/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,6 @@ class is implemented by an extension.
from typing import Optional, Dict, Any, List, Type, Iterable


# TODO:
# Proposed device events:
# sometimes event can be fired twice, we can ignore it
# e.g. if device is plugged out and in in short time we can have doubled
# detaching and attaching...
# - device-list-changed: device-added -> device-added{devclass}
# - device-list-changed: device-remove -> device-removed{devclass}
# - device-property-changed: property_name: TODO?
# - device-assignment-changed: created -> device-assign:{devclass}
# - device-assignment-changed: removed -> device-unassign:{devclass}
# - device-assignment-changed: attached -> device-attach:{devclass}
# - device-assignment-changed: detached -> device-detach:{devclass}
# - device-assignment-changed: property-set -> device-assignment-changed:{devclass}

class UnexpectedDeviceProperty(qubesadmin.exc.QubesException, ValueError):
"""
Device has unexpected property such as backend_domain, devclass etc.
Expand Down
27 changes: 15 additions & 12 deletions qubesadmin/tools/qvm_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,10 @@ def assign_device(args):
options['identity'] = 'any'
assignment.options = options
vm.devices[args.devclass].assign(assignment)
if vm.is_running() and not assignment.attached:
print("Assigned. Now you can manually attach device or restart domain.")
if vm.is_running() and not assignment.attached and not args.quiet:
print("Assigned. To attach you can now restart domain or run: \n"
f"\tqvm-{assignment.devclass} attach {vm} "
f"{assignment.backend_domain}:{assignment.ident}")


def unassign_device(args):
Expand All @@ -194,17 +196,18 @@ def unassign_device(args):
device = args.device
assignment = qubesadmin.devices.DeviceAssignment.from_device(
device, frontend_domain=vm)
vm.devices[args.devclass].unassign(assignment)
if assignment.attached:
print("Unassigned. Now you can manually detach device "
"or restart domain.")
_unassign_and_show_message(assignment, vm, args)
else:
for device_assignment in (
vm.devices[args.devclass].get_assigned_devices()):
vm.devices[args.devclass].unassign(device_assignment)
if device_assignment.attached:
print("Unassigned. Now you can manually detach device "
"or restart domain.")
for assignment in vm.devices[args.devclass].get_assigned_devices():
_unassign_and_show_message(assignment, vm, args)


def _unassign_and_show_message(assignment, vm, args):
vm.devices[args.devclass].unassign(assignment)
if assignment.attached and not args.quiet:
print("Unassigned. To detach you can now restart domain or run: \n"
f"\tqvm-{assignment.devclass} detach {vm} "
f"{assignment.backend_domain}:{assignment.ident}")


def info_device(args):
Expand Down

0 comments on commit 2e31a4b

Please sign in to comment.