From 63715569160785ffeac05e34b604136440a9f865 Mon Sep 17 00:00:00 2001 From: Rui Chen Date: Tue, 26 Apr 2016 19:34:13 +0800 Subject: Support "--no" option in aggregate set Supporting "--no-property" option will apply user a convenience way to clean all properties of aggregate in a short command, and this kind of behavior is the recommended way to devref. The patch add "--no-property" option in "aggregate set" command, and update related test cases and devref document. Change-Id: I7614a23c0db05144562330dc600dbab7d003d5d8 Implements: blueprint support-no-property-in-aggregate --- openstackclient/compute/v2/aggregate.py | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) (limited to 'openstackclient/compute') diff --git a/openstackclient/compute/v2/aggregate.py b/openstackclient/compute/v2/aggregate.py index 2e2838c5..58d529e9 100644 --- a/openstackclient/compute/v2/aggregate.py +++ b/openstackclient/compute/v2/aggregate.py @@ -248,6 +248,14 @@ class SetAggregate(command.Command): help=_("Property to set on " "(repeat option to set multiple properties)") ) + parser.add_argument( + "--no-property", + dest="no_property", + action="store_true", + help=_("Remove all properties from " + "(specify both --property and --no-property to " + "overwrite the current properties)"), + ) return parser def take_action(self, parsed_args): @@ -269,10 +277,23 @@ class SetAggregate(command.Command): kwargs ) + set_property = {} + if parsed_args.no_property: + # NOTE(RuiChen): "availability_zone" is removed from response of + # aggregate show and create commands, don't see it + # anywhere, so pop it, avoid the unexpected server + # exception(can't unset the availability zone from + # aggregate metadata in nova). + set_property.update({key: None + for key in aggregate.metadata.keys() + if key != 'availability_zone'}) if parsed_args.property: + set_property.update(parsed_args.property) + + if set_property: compute_client.aggregates.set_metadata( aggregate, - parsed_args.property + set_property ) @@ -326,7 +347,6 @@ class UnsetAggregate(command.Command): "--property", metavar="", action='append', - required=True, help=_("Property to remove from aggregate " "(repeat option to remove multiple properties)") ) @@ -338,6 +358,9 @@ class UnsetAggregate(command.Command): compute_client.aggregates, parsed_args.aggregate) - unset_property = {key: None for key in parsed_args.property} - compute_client.aggregates.set_metadata(aggregate, - unset_property) + unset_property = {} + if parsed_args.property: + unset_property.update({key: None for key in parsed_args.property}) + if unset_property: + compute_client.aggregates.set_metadata(aggregate, + unset_property) -- cgit v1.2.1