diff options
| author | Rui Chen <chenrui.momo@gmail.com> | 2016-04-26 19:34:13 +0800 |
|---|---|---|
| committer | Rui Chen <chenrui.momo@gmail.com> | 2016-09-24 15:59:13 +0800 |
| commit | 63715569160785ffeac05e34b604136440a9f865 (patch) | |
| tree | 1e7521dd17ce5e9dd0a0159704d39b4a609e377e /openstackclient/compute | |
| parent | 2731fc3912aa8392179ca2d870e9daa76e1410e4 (diff) | |
| download | python-openstackclient-63715569160785ffeac05e34b604136440a9f865.tar.gz | |
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
Diffstat (limited to 'openstackclient/compute')
| -rw-r--r-- | openstackclient/compute/v2/aggregate.py | 33 |
1 files changed, 28 insertions, 5 deletions
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 <aggregate> " "(repeat option to set multiple properties)") ) + parser.add_argument( + "--no-property", + dest="no_property", + action="store_true", + help=_("Remove all properties from <aggregate> " + "(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="<key>", 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) |
