diff options
| author | Huanxuan Ao <huanxuan.ao@easystack.cn> | 2016-07-12 15:53:58 +0800 |
|---|---|---|
| committer | Huanxuan Ao <huanxuan.ao@easystack.cn> | 2016-07-14 17:49:26 +0800 |
| commit | 9b51127ecc85e9814b6256180ef612c857156559 (patch) | |
| tree | 7417dfafa902457fa3f3f4de25e2e020a0088703 /openstackclient/volume/v2/backup.py | |
| parent | 63a6789addff3ccc9cb97f1fde63eb6233624319 (diff) | |
| download | python-openstackclient-9b51127ecc85e9814b6256180ef612c857156559.tar.gz | |
Support error handling for delete commands in volumev2
Some delete conmmands in volumev2 did not support
error handling, this patch add them and also add
the unit tests for bulk deletion
Change-Id: I56ade6f9c7396c78fb989547476c4d94ccd76eae
Diffstat (limited to 'openstackclient/volume/v2/backup.py')
| -rw-r--r-- | openstackclient/volume/v2/backup.py | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/openstackclient/volume/v2/backup.py b/openstackclient/volume/v2/backup.py index 49226bcc..3d27c121 100644 --- a/openstackclient/volume/v2/backup.py +++ b/openstackclient/volume/v2/backup.py @@ -15,14 +15,19 @@ """Volume v2 Backup action implementations""" import copy +import logging from osc_lib.command import command +from osc_lib import exceptions from osc_lib import utils import six from openstackclient.i18n import _ +LOG = logging.getLogger(__name__) + + class CreateBackup(command.ShowOne): """Create new backup""" @@ -109,10 +114,24 @@ class DeleteBackup(command.Command): def take_action(self, parsed_args): volume_client = self.app.client_manager.volume - for backup in parsed_args.backups: - backup_id = utils.find_resource( - volume_client.backups, backup).id - volume_client.backups.delete(backup_id, parsed_args.force) + result = 0 + + for i in parsed_args.backups: + try: + backup_id = utils.find_resource( + volume_client.backups, i).id + volume_client.backups.delete(backup_id, parsed_args.force) + except Exception as e: + result += 1 + LOG.error(_("Failed to delete backup with " + "name or ID '%(backup)s': %(e)s") + % {'backup': i, 'e': e}) + + if result > 0: + total = len(parsed_args.backups) + msg = (_("%(result)s of %(total)s backups failed " + "to delete.") % {'result': result, 'total': total}) + raise exceptions.CommandError(msg) class ListBackup(command.Lister): |
