|
26 | 26 | from osc_lib.cli import format_columns |
27 | 27 | from osc_lib.cli import parseractions |
28 | 28 | from osc_lib.command import command |
| 29 | +from osc_lib import exceptions |
29 | 30 | from osc_lib import utils |
30 | 31 |
|
31 | 32 | from openstackclient.i18n import _ |
@@ -372,10 +373,30 @@ def get_parser(self, prog_name): |
372 | 373 | return parser |
373 | 374 |
|
374 | 375 | def take_action(self, parsed_args): |
| 376 | + result = 0 |
375 | 377 | image_client = self.app.client_manager.image |
376 | 378 | for image in parsed_args.images: |
377 | | - image_obj = image_client.find_image(image) |
378 | | - image_client.delete_image(image_obj.id) |
| 379 | + try: |
| 380 | + image_obj = image_client.find_image( |
| 381 | + image, |
| 382 | + ignore_missing=False, |
| 383 | + ) |
| 384 | + image_client.delete_image(image_obj.id) |
| 385 | + except Exception as e: |
| 386 | + result += 1 |
| 387 | + msg = _( |
| 388 | + "Failed to delete image with name or " |
| 389 | + "ID '%(image)s': %(e)s" |
| 390 | + ) |
| 391 | + LOG.error(msg, {'image': image, 'e': e}) |
| 392 | + |
| 393 | + total = len(parsed_args.images) |
| 394 | + if result > 0: |
| 395 | + msg = _("Failed to delete %(result)s of %(total)s images.") % { |
| 396 | + 'result': result, |
| 397 | + 'total': total, |
| 398 | + } |
| 399 | + raise exceptions.CommandError(msg) |
379 | 400 |
|
380 | 401 |
|
381 | 402 | class ListImage(command.Lister): |
@@ -528,7 +549,9 @@ def get_parser(self, prog_name): |
528 | 549 |
|
529 | 550 | def take_action(self, parsed_args): |
530 | 551 | image_client = self.app.client_manager.image |
531 | | - image = image_client.find_image(parsed_args.image) |
| 552 | + image = image_client.find_image( |
| 553 | + parsed_args.image, ignore_missing=False |
| 554 | + ) |
532 | 555 |
|
533 | 556 | output_file = parsed_args.file |
534 | 557 | if output_file is None: |
@@ -719,7 +742,9 @@ def take_action(self, parsed_args): |
719 | 742 |
|
720 | 743 | # Wrap the call to catch exceptions in order to close files |
721 | 744 | try: |
722 | | - image = image_client.find_image(parsed_args.image) |
| 745 | + image = image_client.find_image( |
| 746 | + parsed_args.image, ignore_missing=False |
| 747 | + ) |
723 | 748 |
|
724 | 749 | if not parsed_args.location and not parsed_args.copy_from: |
725 | 750 | if parsed_args.volume: |
@@ -800,7 +825,9 @@ def get_parser(self, prog_name): |
800 | 825 |
|
801 | 826 | def take_action(self, parsed_args): |
802 | 827 | image_client = self.app.client_manager.image |
803 | | - image = image_client.find_image(parsed_args.image) |
| 828 | + image = image_client.find_image( |
| 829 | + parsed_args.image, ignore_missing=False |
| 830 | + ) |
804 | 831 |
|
805 | 832 | if parsed_args.human_readable: |
806 | 833 | _formatters['size'] = HumanReadableSizeColumn |
|
0 commit comments