diff options
| author | Huanxuan Ao <huanxuan.ao@easystack.cn> | 2016-08-15 19:03:50 +0800 |
|---|---|---|
| committer | Huanxuan Ao <huanxuan.ao@easystack.cn> | 2016-09-11 11:41:05 +0800 |
| commit | 10e665a148efec0cf75bd5dd07decf23a36a52e0 (patch) | |
| tree | 595d092e5e03ce2ebaeb5973c0bdffba38a76920 /openstackclient/volume/v1 | |
| parent | 676a0e9696ba7550132e4501bdbf3160608faed6 (diff) | |
| download | python-openstackclient-10e665a148efec0cf75bd5dd07decf23a36a52e0.tar.gz | |
Error handling of multi REST API calls for "snapshot set" command
Support multi REST API calls error handling for
"snapshot set" command follow the rule in
doc/source/command-errors.rst. Also add a unit
test for testing the error handling
Change-Id: I0c6214271bc54a25b051c0a62438c3344c8b51d7
Diffstat (limited to 'openstackclient/volume/v1')
| -rw-r--r-- | openstackclient/volume/v1/snapshot.py | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/openstackclient/volume/v1/snapshot.py b/openstackclient/volume/v1/snapshot.py index bb3a1fc3..f8fa7c95 100644 --- a/openstackclient/volume/v1/snapshot.py +++ b/openstackclient/volume/v1/snapshot.py @@ -16,15 +16,20 @@ """Volume v1 Snapshot action implementations""" import copy +import logging from osc_lib.cli import parseractions 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 CreateSnapshot(command.ShowOne): """Create new snapshot""" @@ -199,17 +204,31 @@ class SetSnapshot(command.Command): snapshot = utils.find_resource(volume_client.volume_snapshots, parsed_args.snapshot) + result = 0 if parsed_args.property: - volume_client.volume_snapshots.set_metadata(snapshot.id, - parsed_args.property) + try: + volume_client.volume_snapshots.set_metadata( + snapshot.id, parsed_args.property) + except Exception as e: + LOG.error(_("Failed to set snapshot property: %s"), e) + result += 1 kwargs = {} if parsed_args.name: kwargs['display_name'] = parsed_args.name if parsed_args.description: kwargs['display_description'] = parsed_args.description - - snapshot.update(**kwargs) + if kwargs: + try: + snapshot.update(**kwargs) + except Exception as e: + LOG.error(_("Failed to update snapshot display name " + "or display description: %s"), e) + result += 1 + + if result > 0: + raise exceptions.CommandError(_("One or more of the " + "set operations failed")) class ShowSnapshot(command.ShowOne): |
