Skip to content

Commit 6a3c7c2

Browse files
reedipDean Troyer
authored andcommitted
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
1 parent 1e3dc48 commit 6a3c7c2

4 files changed

Lines changed: 46 additions & 0 deletions

File tree

doc/source/command-objects/flavor.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ Set flavor properties
144144
.. code:: bash
145145
146146
openstack flavor set
147+
[--no-property]
147148
[--property <key=value> [...] ]
148149
[--project <project>]
149150
[--project-domain <project-domain>]
@@ -162,6 +163,11 @@ Set flavor properties
162163
Domain the project belongs to (name or ID).
163164
This can be used in case collisions between project names exist.
164165

166+
.. option:: --no-property
167+
168+
Remove all properties from this flavor (specify both --no-property and --property
169+
to remove the current properties before setting new properties.)
170+
165171
.. describe:: <flavor>
166172

167173
Flavor to modify (name or ID)

openstackclient/compute/v2/flavor.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,14 @@ def get_parser(self, prog_name):
312312
metavar="<flavor>",
313313
help=_("Flavor to modify (name or ID)")
314314
)
315+
parser.add_argument(
316+
"--no-property",
317+
action="store_true",
318+
help=_("Remove all properties from this flavor "
319+
"(specify both --no-property and --property"
320+
" to remove the current properties before setting"
321+
" new properties.)"),
322+
)
315323
parser.add_argument(
316324
"--property",
317325
metavar="<key=value>",
@@ -336,6 +344,15 @@ def take_action(self, parsed_args):
336344
flavor = _find_flavor(compute_client, parsed_args.flavor)
337345

338346
result = 0
347+
key_list = []
348+
if parsed_args.no_property:
349+
try:
350+
for key in flavor.get_keys().keys():
351+
key_list.append(key)
352+
flavor.unset_keys(key_list)
353+
except Exception as e:
354+
LOG.error(_("Failed to clear flavor property: %s"), e)
355+
result += 1
339356
if parsed_args.property:
340357
try:
341358
flavor.set_keys(parsed_args.property)

openstackclient/tests/unit/compute/v2/test_flavor.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,23 @@ def test_flavor_set_property(self):
528528
self.flavor.set_keys.assert_called_with({'FOO': '"B A R"'})
529529
self.assertIsNone(result)
530530

531+
def test_flavor_set_no_property(self):
532+
arglist = [
533+
'--no-property',
534+
'baremetal'
535+
]
536+
verifylist = [
537+
('no_property', True),
538+
('flavor', 'baremetal')
539+
]
540+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
541+
542+
result = self.cmd.take_action(parsed_args)
543+
self.flavors_mock.find.assert_called_with(name=parsed_args.flavor,
544+
is_public=None)
545+
self.flavor.unset_keys.assert_called_with(['property'])
546+
self.assertIsNone(result)
547+
531548
def test_flavor_set_project(self):
532549
arglist = [
533550
'--project', self.project.id,
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
features:
3+
- |
4+
Add support to clear/overwrite all flavor properties using
5+
``--no-property`` option with ``flavor set`` command.
6+
[ Blueprint `allow-overwrite-set-options <https://blueprints.launchpad.net/python-openstackclient/+spec/allow-overwrite-set-options>` _]

0 commit comments

Comments
 (0)