Skip to content

Commit

Permalink
qvm-ls & qvm-device: Handle removal of VM during on_shutdown.
Browse files Browse the repository at this point in the history
  • Loading branch information
3hhh committed Apr 9, 2021
1 parent 1471a56 commit 7c977f9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 17 deletions.
35 changes: 21 additions & 14 deletions qubesadmin/tools/qvm_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,11 @@ def list_devices(args):

else:
for domain in app.domains:
for dev in domain.devices[args.devclass].available():
devices.add(dev)
try:
for dev in domain.devices[args.devclass].available():
devices.add(dev)
except qubesadmin.exc.QubesVMNotFoundError:
continue
except qubesadmin.exc.QubesDaemonAccessError:
raise qubesadmin.exc.QubesException(
"Failed to list '%s' devices, this device type either "
Expand All @@ -105,16 +108,19 @@ def list_devices(args):
if domain == dev.backend_domain:
continue

for assignment in domain.devices[args.devclass].assignments():
if dev != assignment:
continue
if assignment.options:
result[dev].frontends.append('{!s} ({})'.format(
domain, ', '.join('{}={}'.format(key, value)
for key, value in
assignment.options.items())))
else:
result[dev].frontends.append(str(domain))
try:
for assignment in domain.devices[args.devclass].assignments():
if dev != assignment:
continue
if assignment.options:
result[dev].frontends.append('{!s} ({})'.format(
domain, ', '.join('{}={}'.format(key, value)
for key, value in
assignment.options.items())))
else:
result[dev].frontends.append(str(domain))
except qubesadmin.exc.QubesVMNotFoundError:
continue

qubesadmin.tools.print_table(prepare_table(result.values()))

Expand Down Expand Up @@ -281,7 +287,8 @@ def main(args=None, app=None):
if basename.startswith('qvm-') and basename != 'qvm-device':
devclass = basename[4:]

args = get_parser(devclass).parse_args(args, app=app)
parser = get_parser(devclass)
args = parser.parse_args(args, app=app)

if args.list_device_classes:
print('\n'.join(qubesadmin.Qubes().list_deviceclass()))
Expand All @@ -290,7 +297,7 @@ def main(args=None, app=None):
try:
args.func(args)
except qubesadmin.exc.QubesException as e:
print(str(e), file=sys.stderr)
parser.print_error(str(e))
return 1
return 0

Expand Down
14 changes: 11 additions & 3 deletions qubesadmin/tools/qvm_ls.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,17 +467,25 @@ def write_table(self, stream=sys.stdout):
table_data.append(self.get_head())
self.spinner.update()
if self.tree_sorted:
#FIXME: handle qubesadmin.exc.QubesVMNotFoundError
# (see QubesOS/qubes-issues#5105)
insertion_vm_list = self.sort_to_tree(self.domains)
for insertion, vm in insertion_vm_list:
table_data.append(self.get_row(vm, insertion))
else:
for vm in sorted(self.domains):
table_data.append(self.get_row(vm))
try:
table_data.append(self.get_row(vm))
except qubesadmin.exc.QubesVMNotFoundError:
continue
self.spinner.hide()
qubesadmin.tools.print_table(table_data, stream=stream)
else:
for vm in sorted(self.domains):
stream.write('|'.join(self.get_row(vm)) + '\n')
try:
stream.write('|'.join(self.get_row(vm)) + '\n')
except qubesadmin.exc.QubesVMNotFoundError:
continue


#: Available formats. Feel free to plug your own one.
Expand Down Expand Up @@ -576,7 +584,7 @@ def get_parser():
parser = qubesadmin.tools.QubesArgumentParser(
vmname_nargs=argparse.ZERO_OR_MORE,
formatter_class=argparse.RawTextHelpFormatter,
description='List Qubes domains and their parametres.',
description='List Qubes domains and their parameters.',
epilog='available formats (see --help-formats):\n{}\n\n'
'available columns (see --help-columns):\n{}'.format(
wrapper.fill(', '.join(sorted(formats.keys()))),
Expand Down

0 comments on commit 7c977f9

Please sign in to comment.