From 40ec7a9c96f4ce4071e47e5bf0c249aa77b5b2ee Mon Sep 17 00:00:00 2001 From: "zhiyong.dai" Date: Thu, 1 Dec 2016 02:20:23 +0800 Subject: Support --no-property in "volume set" command Add "--no-property" option to "volume set" command in v1 and v2 and update the test cases. Change-Id: Id5660f23b3b2d9aa72f4c16b19ce83f3f7ed2fa4 --- openstackclient/volume/v1/volume.py | 18 ++++++++++++++++++ openstackclient/volume/v2/volume.py | 19 ++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) (limited to 'openstackclient/volume') diff --git a/openstackclient/volume/v1/volume.py b/openstackclient/volume/v1/volume.py index 739484df..8e1097f5 100644 --- a/openstackclient/volume/v1/volume.py +++ b/openstackclient/volume/v1/volume.py @@ -439,6 +439,15 @@ class SetVolume(command.Command): type=int, help=_('Extend volume size in GB'), ) + 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='', @@ -489,6 +498,15 @@ class SetVolume(command.Command): except Exception as e: LOG.error(_("Failed to set volume size: %s"), e) result += 1 + + if parsed_args.no_property: + try: + volume_client.volumes.delete_metadata( + volume.id, volume.metadata.keys()) + except Exception as e: + LOG.error(_("Failed to clean volume properties: %s"), e) + result += 1 + if parsed_args.property: try: volume_client.volumes.set_metadata( diff --git a/openstackclient/volume/v2/volume.py b/openstackclient/volume/v2/volume.py index 78db261b..c361d700 100644 --- a/openstackclient/volume/v2/volume.py +++ b/openstackclient/volume/v2/volume.py @@ -523,6 +523,15 @@ class SetVolume(command.Command): metavar='', help=_('New volume 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='', @@ -561,7 +570,7 @@ class SetVolume(command.Command): choices=['never', 'on-demand'], help=_('Migration policy while re-typing volume ' '("never" or "on-demand", default is "never" ) ' - '(available only when "--type" option is specified)'), + '(available only when --type option is specified)'), ) bootable_group = parser.add_mutually_exclusive_group() bootable_group.add_argument( @@ -607,6 +616,14 @@ class SetVolume(command.Command): LOG.error(_("Failed to set volume size: %s"), e) result += 1 + if parsed_args.no_property: + try: + volume_client.volumes.delete_metadata( + volume.id, volume.metadata.keys()) + except Exception as e: + LOG.error(_("Failed to clean volume properties: %s"), e) + result += 1 + if parsed_args.property: try: volume_client.volumes.set_metadata( -- cgit v1.2.1