Skip to content

Commit

Permalink
q-dev: more elaborated assignment listing
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrbartman committed Oct 14, 2024
1 parent 5210963 commit 082a47f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
10 changes: 6 additions & 4 deletions qubesadmin/tests/tools/qvm_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,10 @@ def test_001_list_assigned_required(self):
self.assertEqual(
buf.getvalue(),
'test-vm1:dev1 any device '
'test-vm2 (option=other option, extra_opt=yes), '
'test-vm3 (option=test option)\n'
'test-vm3:dev3 ?******: evil inc. test-device-3 test-vm2\n'
'test-vm2 (required: option=other option, extra_opt=yes), '
'test-vm3 (required: option=test option)\n'
'test-vm3:dev3 ?******: evil inc. test-device-3 '
'test-vm2 (required)\n'
)

def test_002_list_attach(self):
Expand Down Expand Up @@ -149,7 +150,8 @@ def test_002_list_attach(self):
['testclass', 'list', 'test-vm3'], app=self.app)
self.assertEqual(
buf.getvalue(),
'test-vm1:dev1 ?******: itl test-device test-vm3\n'
'test-vm1:dev1 ?******: itl test-device '
'test-vm3 (required)\n'
)

def test_003_list_device_classes(self):
Expand Down
14 changes: 9 additions & 5 deletions qubesadmin/tools/qvm_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,13 @@ def prepare_table(dev_list):
return header + sorted(output)


class Line(object):
class Line:
"""Helper class to hold single device info for listing"""

# pylint: disable=too-few-public-methods
def __init__(self, device: DeviceInfo, attached_to=None):
self.ident = "{!s}:{!s}".format(device.backend_domain, device.port_id) # TODO!
self.ident = "{!s}:{!s}".format(
device.backend_domain, device.port_id)
self.description = device.description
self.attached_to = attached_to if attached_to else ""
self.frontends = []
Expand Down Expand Up @@ -151,11 +152,14 @@ def _frontend_desc(vm, assignment):
"""
Generate description of frontend vm with optional device connection options.
"""
mode = assignment.mode.value
if mode == 'manual':
mode = 'attached'
if assignment.options:
return '{!s} ({})'.format(
vm, ', '.join('{}={}'.format(key, value)
return '{!s} ({}: {})'.format(
vm, mode, ', '.join('{}={}'.format(key, value)
for key, value in assignment.options.items()))
return str(vm)
return f'{vm} ({mode})'


def attach_device(args):
Expand Down

0 comments on commit 082a47f

Please sign in to comment.