From 6a3c7c2a68dd2aeb8a0a05143de3b14e4beea99d Mon Sep 17 00:00:00 2001 From: Reedip Date: Wed, 28 Dec 2016 01:45:42 -0500 Subject: Overwrite/Clear Flavor property This patch adds support to overwrite/clear the flavor's property using the new ``--no-property`` option in the ``flavor set`` command. Change-Id: I873c96fcf223bbd638a19b908766d904a84e8431 Implements: blueprint allow-overwrite-set-options Co-Authored By: zhiyong.dai@easystack.cn --- openstackclient/compute/v2/flavor.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'openstackclient/compute/v2') diff --git a/openstackclient/compute/v2/flavor.py b/openstackclient/compute/v2/flavor.py index 7cd22ed7..7e213f73 100644 --- a/openstackclient/compute/v2/flavor.py +++ b/openstackclient/compute/v2/flavor.py @@ -312,6 +312,14 @@ class SetFlavor(command.Command): metavar="", help=_("Flavor to modify (name or ID)") ) + parser.add_argument( + "--no-property", + action="store_true", + help=_("Remove all properties from this flavor " + "(specify both --no-property and --property" + " to remove the current properties before setting" + " new properties.)"), + ) parser.add_argument( "--property", metavar="", @@ -336,6 +344,15 @@ class SetFlavor(command.Command): flavor = _find_flavor(compute_client, parsed_args.flavor) result = 0 + key_list = [] + if parsed_args.no_property: + try: + for key in flavor.get_keys().keys(): + key_list.append(key) + flavor.unset_keys(key_list) + except Exception as e: + LOG.error(_("Failed to clear flavor property: %s"), e) + result += 1 if parsed_args.property: try: flavor.set_keys(parsed_args.property) -- cgit v1.2.1