qvm-device: handle 'list-device-classes' and 'list-classes'

QubesOS/qubes-issues#5213
This commit is contained in:
Frédéric Pierret (fepitre) 2019-08-10 22:10:31 +02:00
parent 3dce4e9742
commit 41c6fbed72
No known key found for this signature in database
GPG Key ID: 484010B5CDC576E2
2 changed files with 16 additions and 0 deletions

1
qubesadmin/qubesadmin Symbolic link
View File

@ -0,0 +1 @@
/home/user/qubes-builder/qubes-src/core-admin-client/qubesadmin

View File

@ -263,6 +263,9 @@ def get_parser(device_class=None):
attach_parser.set_defaults(func=attach_device) attach_parser.set_defaults(func=attach_device)
detach_parser.set_defaults(func=detach_device) detach_parser.set_defaults(func=detach_device)
parser.add_argument('--list-device-classes', action='store_true',
default=False)
return parser return parser
@ -272,7 +275,13 @@ def main(args=None, app=None):
devclass = None devclass = None
if basename.startswith('qvm-') and basename != 'qvm-device': if basename.startswith('qvm-') and basename != 'qvm-device':
devclass = basename[4:] devclass = basename[4:]
args = get_parser(devclass).parse_args(args, app=app) args = get_parser(devclass).parse_args(args, app=app)
if args.list_device_classes:
print('\n'.join(qubesadmin.Qubes().list_deviceclass()))
return 0
try: try:
args.func(args) args.func(args)
except qubesadmin.exc.QubesException as e: except qubesadmin.exc.QubesException as e:
@ -282,4 +291,10 @@ def main(args=None, app=None):
if __name__ == '__main__': if __name__ == '__main__':
# Special treatment for '--list-device-classes' (alias --list-classes)
curr_action = sys.argv[1:]
if set(curr_action).intersection(
{'--list-device-classes', '--list-classes'}):
sys.exit(main(args=['', '--list-device-classes']))
sys.exit(main()) sys.exit(main())