diff options
| author | Jenkins <jenkins@review.openstack.org> | 2016-09-11 05:50:40 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2016-09-11 05:50:40 +0000 |
| commit | 30afdb9684789869ee42881cb14fa67683babce0 (patch) | |
| tree | 585a0f6fd22b1821f5af4e7a561a566bc0f35a10 /openstackclient/volume | |
| parent | cc5379b55cc74740b2451b9445bb752d6230862e (diff) | |
| parent | 10e665a148efec0cf75bd5dd07decf23a36a52e0 (diff) | |
| download | python-openstackclient-30afdb9684789869ee42881cb14fa67683babce0.tar.gz | |
Merge "Error handling of multi REST API calls for "snapshot set" command"
Diffstat (limited to 'openstackclient/volume')
| -rw-r--r-- | openstackclient/volume/v1/snapshot.py | 20 | ||||
| -rw-r--r-- | openstackclient/volume/v2/snapshot.py | 35 |
2 files changed, 45 insertions, 10 deletions
diff --git a/openstackclient/volume/v1/snapshot.py b/openstackclient/volume/v1/snapshot.py index e65475f0..c4d113a3 100644 --- a/openstackclient/volume/v1/snapshot.py +++ b/openstackclient/volume/v1/snapshot.py @@ -218,17 +218,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 + 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 - snapshot.update(**kwargs) + if result > 0: + raise exceptions.CommandError(_("One or more of the " + "set operations failed")) class ShowSnapshot(command.ShowOne): diff --git a/openstackclient/volume/v2/snapshot.py b/openstackclient/volume/v2/snapshot.py index 8304a5eb..0d826551 100644 --- a/openstackclient/volume/v2/snapshot.py +++ b/openstackclient/volume/v2/snapshot.py @@ -240,19 +240,40 @@ class SetSnapshot(command.Command): snapshot = utils.find_resource(volume_client.volume_snapshots, parsed_args.snapshot) + result = 0 + if 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 + + if parsed_args.state: + try: + volume_client.volume_snapshots.reset_state( + snapshot.id, parsed_args.state) + except Exception as e: + LOG.error(_("Failed to set snapshot state: %s"), e) + result += 1 + kwargs = {} if parsed_args.name: kwargs['name'] = parsed_args.name if parsed_args.description: kwargs['description'] = parsed_args.description + if kwargs: + try: + volume_client.volume_snapshots.update( + snapshot.id, **kwargs) + except Exception as e: + LOG.error(_("Failed to update snapshot name " + "or description: %s"), e) + result += 1 - if parsed_args.property: - volume_client.volume_snapshots.set_metadata(snapshot.id, - parsed_args.property) - if parsed_args.state: - volume_client.volume_snapshots.reset_state(snapshot.id, - parsed_args.state) - volume_client.volume_snapshots.update(snapshot.id, **kwargs) + if result > 0: + raise exceptions.CommandError(_("One or more of the " + "set operations failed")) class ShowSnapshot(command.ShowOne): |
