From 26d50be79a401322f4e74b94c066257ddf0f287c Mon Sep 17 00:00:00 2001 From: "zhiyong.dai" Date: Mon, 2 Jan 2017 17:55:32 +0800 Subject: Support "--no-property" option in volume snapshot set Supporting "--no-property" option will apply user a convenient way to clean all properties of volume snapshot in a short command, and this kind of behavior is the recommended way to devref. The patch adds "--no-property" option in "volume snapshot set" command, and update related test cases and devref document. Change-Id: I5f10cc2b5814553699920c4343995b2e11416e4e Implements: blueprint allow-overwrite-set-options --- openstackclient/volume/v2/volume_snapshot.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'openstackclient/volume/v2') diff --git a/openstackclient/volume/v2/volume_snapshot.py b/openstackclient/volume/v2/volume_snapshot.py index af29b777..3c06fa5a 100644 --- a/openstackclient/volume/v2/volume_snapshot.py +++ b/openstackclient/volume/v2/volume_snapshot.py @@ -285,6 +285,15 @@ class SetVolumeSnapshot(command.Command): metavar='', help=_('New snapshot description') ) + parser.add_argument( + "--no-property", + dest="no_property", + action="store_true", + help=_("Remove all properties from " + "(specify both --no-property and --property to " + "remove the current properties before setting " + "new properties.)"), + ) parser.add_argument( '--property', metavar='', @@ -311,6 +320,17 @@ class SetVolumeSnapshot(command.Command): parsed_args.snapshot) result = 0 + if parsed_args.no_property: + try: + key_list = snapshot.metadata.keys() + volume_client.volume_snapshots.delete_metadata( + snapshot.id, + list(key_list), + ) + except Exception as e: + LOG.error(_("Failed to clean snapshot properties: %s"), e) + result += 1 + if parsed_args.property: try: volume_client.volume_snapshots.set_metadata( -- cgit v1.2.1