summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2017-02-13 18:19:26 +0000
committerGerrit Code Review <review@openstack.org>2017-02-13 18:19:26 +0000
commit655e73683a134c0c0f5acdc025b4532759f74202 (patch)
treea35e737d3cf136cf7662d9427f607cbcd2833879
parent10bd6a6267b6eca537dff638d762e8bcbe4c11ea (diff)
parent6a3c7c2a68dd2aeb8a0a05143de3b14e4beea99d (diff)
downloadpython-openstackclient-655e73683a134c0c0f5acdc025b4532759f74202.tar.gz
Merge "Overwrite/Clear Flavor property"
-rw-r--r--doc/source/command-objects/flavor.rst6
-rw-r--r--openstackclient/compute/v2/flavor.py17
-rw-r--r--openstackclient/tests/unit/compute/v2/test_flavor.py17
-rw-r--r--releasenotes/notes/add-no-property-f97e4b2f390cec06.yaml6
4 files changed, 46 insertions, 0 deletions
diff --git a/doc/source/command-objects/flavor.rst b/doc/source/command-objects/flavor.rst
index 971628d7..a9f8262e 100644
--- a/doc/source/command-objects/flavor.rst
+++ b/doc/source/command-objects/flavor.rst
@@ -144,6 +144,7 @@ Set flavor properties
.. code:: bash
openstack flavor set
+ [--no-property]
[--property <key=value> [...] ]
[--project <project>]
[--project-domain <project-domain>]
@@ -162,6 +163,11 @@ Set flavor properties
Domain the project belongs to (name or ID).
This can be used in case collisions between project names exist.
+.. option:: --no-property
+
+ Remove all properties from this flavor (specify both --no-property and --property
+ to remove the current properties before setting new properties.)
+
.. describe:: <flavor>
Flavor to modify (name or ID)
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
@@ -313,6 +313,14 @@ class SetFlavor(command.Command):
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="<key=value>",
action=parseractions.KeyValueAction,
@@ -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)
diff --git a/openstackclient/tests/unit/compute/v2/test_flavor.py b/openstackclient/tests/unit/compute/v2/test_flavor.py
index 632fcda1..4cdbb25b 100644
--- a/openstackclient/tests/unit/compute/v2/test_flavor.py
+++ b/openstackclient/tests/unit/compute/v2/test_flavor.py
@@ -528,6 +528,23 @@ class TestFlavorSet(TestFlavor):
self.flavor.set_keys.assert_called_with({'FOO': '"B A R"'})
self.assertIsNone(result)
+ def test_flavor_set_no_property(self):
+ arglist = [
+ '--no-property',
+ 'baremetal'
+ ]
+ verifylist = [
+ ('no_property', True),
+ ('flavor', 'baremetal')
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ result = self.cmd.take_action(parsed_args)
+ self.flavors_mock.find.assert_called_with(name=parsed_args.flavor,
+ is_public=None)
+ self.flavor.unset_keys.assert_called_with(['property'])
+ self.assertIsNone(result)
+
def test_flavor_set_project(self):
arglist = [
'--project', self.project.id,
diff --git a/releasenotes/notes/add-no-property-f97e4b2f390cec06.yaml b/releasenotes/notes/add-no-property-f97e4b2f390cec06.yaml
new file mode 100644
index 00000000..ab502549
--- /dev/null
+++ b/releasenotes/notes/add-no-property-f97e4b2f390cec06.yaml
@@ -0,0 +1,6 @@
+---
+features:
+ - |
+ Add support to clear/overwrite all flavor properties using
+ ``--no-property`` option with ``flavor set`` command.
+ [ Blueprint `allow-overwrite-set-options <https://blueprints.launchpad.net/python-openstackclient/+spec/allow-overwrite-set-options>` _]