Skip to content

Commit

Permalink
q-dev: patching up qvm-device info
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrbartman committed Oct 14, 2024
1 parent 46626fb commit f067f22
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions qubesadmin/tools/qvm_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,9 +416,10 @@ class DeviceAction(qubesadmin.tools.QubesAction):
""" # pylint: disable=too-few-public-methods

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

def __call__(self, parser, namespace, values, option_string=None):
Expand All @@ -445,6 +446,12 @@ def parse_qubes_app(self, parser, namespace):
_dev = dev.backend_domain.devices[devclass][dev.port_id]
if not dev.is_device_id_set or dev.device_id == _dev.device_id:
dev = _dev
elif self.only_port:
parser.error_runtime(
"this option works only for explicitly given port ID "
"and does not support device ID")
else:
dev = UnknownDevice.from_device(dev)
if not self.allow_unknown and isinstance(dev, UnknownDevice):
raise KeyError(dev.port_id)
except KeyError:
Expand Down Expand Up @@ -524,7 +531,7 @@ def get_parser(device_class=None):
info_parser.add_argument(metavar='BACKEND:DEVICE_ID',
dest='device',
nargs=argparse.OPTIONAL,
action=DeviceAction, allow_unknown=True)
action=DeviceAction, only_port=True)

option = (('--option', '-o',),
{'action': 'append',
Expand Down

0 comments on commit f067f22

Please sign in to comment.