diff --git a/qubesadmin/tests/tools/qvm_device.py b/qubesadmin/tests/tools/qvm_device.py index a59c7b44..a7ffacd6 100644 --- a/qubesadmin/tests/tools/qvm_device.py +++ b/qubesadmin/tests/tools/qvm_device.py @@ -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): @@ -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): diff --git a/qubesadmin/tools/qvm_device.py b/qubesadmin/tools/qvm_device.py index 0c3a834d..b1d3a0b4 100644 --- a/qubesadmin/tools/qvm_device.py +++ b/qubesadmin/tools/qvm_device.py @@ -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 = [] @@ -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):