From 629eb33c4dcb73d44d1a4c6105e40d28f6cebdfc Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Wed, 17 May 2023 12:27:45 +0100 Subject: volume: Add 'volume qos set --no-property' option Supporting "--no-property" option will apply user a convenient way to clean all properties of volume qos in a short command. The patch adds "--no-property" option in "volume qos set" command and update related test cases and docs. Change-Id: I1fb5b4f0a923bbf557a3af3f63809bde9e84ffd4 --- openstackclient/volume/v2/qos_specs.py | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'openstackclient/volume/v2/qos_specs.py') diff --git a/openstackclient/volume/v2/qos_specs.py b/openstackclient/volume/v2/qos_specs.py index 2c06ee34..0454ecae 100644 --- a/openstackclient/volume/v2/qos_specs.py +++ b/openstackclient/volume/v2/qos_specs.py @@ -257,6 +257,16 @@ class SetQos(command.Command): metavar='', help=_('QoS specification to modify (name or ID)'), ) + 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='', @@ -274,8 +284,29 @@ class SetQos(command.Command): volume_client.qos_specs, parsed_args.qos_spec ) + result = 0 + if parsed_args.no_property: + try: + key_list = list(qos_spec._info['specs'].keys()) + volume_client.qos_specs.unset_keys(qos_spec.id, key_list) + except Exception as e: + LOG.error(_("Failed to clean qos properties: %s"), e) + result += 1 + if parsed_args.property: - volume_client.qos_specs.set_keys(qos_spec.id, parsed_args.property) + try: + volume_client.qos_specs.set_keys( + qos_spec.id, + parsed_args.property, + ) + except Exception as e: + LOG.error(_("Failed to set qos property: %s"), e) + result += 1 + + if result > 0: + raise exceptions.CommandError( + _("One or more of the set operations failed") + ) class ShowQos(command.ShowOne): -- cgit v1.2.1