diff options
| author | Huanxuan Ao <huanxuan.ao@easystack.cn> | 2016-12-30 13:22:07 +0800 |
|---|---|---|
| committer | Huanxuan Ao <huanxuan.ao@easystack.cn> | 2017-01-03 23:30:49 +0800 |
| commit | 96578cb8ab9a4b95144c33d0af38863fce8d8892 (patch) | |
| tree | 8fd9c537b48aae84b9b3eaac8aa17079adf251b0 /openstackclient/identity/v3/trust.py | |
| parent | f020a9ffd6d5602d18c899e7707baaa620ffdd54 (diff) | |
| download | python-openstackclient-96578cb8ab9a4b95144c33d0af38863fce8d8892.tar.gz | |
Error handling for delete commands in identity
Add missing multi deletion error handling for
identity delete commands.
All delete commands in identity support
error handling now.
Change-Id: I05626dcb5e516a423d610906347b02236ba7eeaf
Diffstat (limited to 'openstackclient/identity/v3/trust.py')
| -rw-r--r-- | openstackclient/identity/v3/trust.py | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/openstackclient/identity/v3/trust.py b/openstackclient/identity/v3/trust.py index 62d72ea1..04ee4dce 100644 --- a/openstackclient/identity/v3/trust.py +++ b/openstackclient/identity/v3/trust.py @@ -14,8 +14,10 @@ """Identity v3 Trust action implementations""" import datetime +import logging from osc_lib.command import command +from osc_lib import exceptions from osc_lib import utils import six @@ -23,6 +25,9 @@ from openstackclient.i18n import _ from openstackclient.identity import common +LOG = logging.getLogger(__name__) + + class CreateTrust(command.ShowOne): _description = _("Create new trust") @@ -145,9 +150,24 @@ class DeleteTrust(command.Command): def take_action(self, parsed_args): identity_client = self.app.client_manager.identity - for t in parsed_args.trust: - trust_obj = utils.find_resource(identity_client.trusts, t) - identity_client.trusts.delete(trust_obj.id) + + errors = 0 + for trust in parsed_args.trust: + try: + trust_obj = utils.find_resource(identity_client.trusts, + trust) + identity_client.trusts.delete(trust_obj.id) + except Exception as e: + errors += 1 + LOG.error(_("Failed to delete trust with " + "name or ID '%(trust)s': %(e)s"), + {'trust': trust, 'e': e}) + + if errors > 0: + total = len(parsed_args.trust) + msg = (_("%(errors)s of %(total)s trusts failed " + "to delete.") % {'errors': errors, 'total': total}) + raise exceptions.CommandError(msg) class ListTrust(command.Lister): |
