From dbed97a24df2fb74e4989fb15c912252f8a8bb07 Mon Sep 17 00:00:00 2001 From: Huanxuan Ao Date: Tue, 28 Jun 2016 14:39:00 +0800 Subject: Add "--property" option to "flavor create" command Add "--property" option to "flavor create" command to support adding properties to a new falvor. Change-Id: I4f06b364375d5a81584fe41122d48e9568fa712a Closes-Bug: #1596798 --- openstackclient/compute/v2/flavor.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'openstackclient/compute') diff --git a/openstackclient/compute/v2/flavor.py b/openstackclient/compute/v2/flavor.py index 01d7da75..000df598 100644 --- a/openstackclient/compute/v2/flavor.py +++ b/openstackclient/compute/v2/flavor.py @@ -121,6 +121,13 @@ class CreateFlavor(command.ShowOne): action="store_false", help=_("Flavor is not available to other projects") ) + parser.add_argument( + "--property", + metavar="", + action=parseractions.KeyValueAction, + help=_("Property to add for this flavor " + "(repeat option to set multiple properties)") + ) parser.add_argument( '--project', metavar='', @@ -150,8 +157,7 @@ class CreateFlavor(command.ShowOne): parsed_args.public ) - flavor = compute_client.flavors.create(*args)._info.copy() - flavor.pop("links") + flavor = compute_client.flavors.create(*args) if parsed_args.project: try: @@ -166,8 +172,17 @@ class CreateFlavor(command.ShowOne): msg = _("Failed to add project %(project)s access to " "flavor: %(e)s") LOG.error(msg % {'project': parsed_args.project, 'e': e}) + if parsed_args.property: + try: + flavor.set_keys(parsed_args.property) + except Exception as e: + LOG.error(_("Failed to set flavor property: %s"), e) - return zip(*sorted(six.iteritems(flavor))) + flavor_info = flavor._info.copy() + flavor_info.pop("links") + flavor_info['properties'] = utils.format_dict(flavor.get_keys()) + + return zip(*sorted(six.iteritems(flavor_info))) class DeleteFlavor(command.Command): -- cgit v1.2.1