Skip to content

Commit f067f22

Browse files
committed
q-dev: patching up qvm-device info
1 parent 46626fb commit f067f22

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

qubesadmin/tools/qvm_device.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -416,9 +416,10 @@ class DeviceAction(qubesadmin.tools.QubesAction):
416416
""" # pylint: disable=too-few-public-methods
417417

418418
def __init__(self, help='A backend, port & device id combination',
419-
required=True, allow_unknown=False, **kwargs):
419+
required=True, allow_unknown=False, only_port=False, **kwargs):
420420
# pylint: disable=redefined-builtin
421421
self.allow_unknown = allow_unknown
422+
self.only_port = only_port
422423
super().__init__(help=help, required=required, **kwargs)
423424

424425
def __call__(self, parser, namespace, values, option_string=None):
@@ -445,6 +446,12 @@ def parse_qubes_app(self, parser, namespace):
445446
_dev = dev.backend_domain.devices[devclass][dev.port_id]
446447
if not dev.is_device_id_set or dev.device_id == _dev.device_id:
447448
dev = _dev
449+
elif self.only_port:
450+
parser.error_runtime(
451+
"this option works only for explicitly given port ID "
452+
"and does not support device ID")
453+
else:
454+
dev = UnknownDevice.from_device(dev)
448455
if not self.allow_unknown and isinstance(dev, UnknownDevice):
449456
raise KeyError(dev.port_id)
450457
except KeyError:
@@ -524,7 +531,7 @@ def get_parser(device_class=None):
524531
info_parser.add_argument(metavar='BACKEND:DEVICE_ID',
525532
dest='device',
526533
nargs=argparse.OPTIONAL,
527-
action=DeviceAction, allow_unknown=True)
534+
action=DeviceAction, only_port=True)
528535

529536
option = (('--option', '-o',),
530537
{'action': 'append',

0 commit comments

Comments
 (0)