From cefa571d4b3162ab1da194573f85cce8bbdacc14 Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Fri, 27 Sep 2019 12:59:48 +0100 Subject: Use 'KeyValueAppendAction' from osc-lib Does what it says on the tin. This action was added to osc-lib in change If73cab759fa09bddf1ff519923c5972c3b2052b1. Change-Id: I51efaa096bb26e297d99634c5d9cca34c0919074 Signed-off-by: Stephen Finucane --- openstackclient/compute/v2/server.py | 32 +------------------------------- 1 file changed, 1 insertion(+), 31 deletions(-) (limited to 'openstackclient') diff --git a/openstackclient/compute/v2/server.py b/openstackclient/compute/v2/server.py index a4cca661..5cc73284 100644 --- a/openstackclient/compute/v2/server.py +++ b/openstackclient/compute/v2/server.py @@ -201,36 +201,6 @@ def _prep_server_detail(compute_client, image_client, server, refresh=True): return info -# TODO(stephenfin): Migrate this to osc-lib -class KeyValueAppendAction(argparse.Action): - """A custom action to parse arguments as key=value pairs - - Ensures that ``dest`` is a dict and values are lists of strings. - """ - - def __call__(self, parser, namespace, values, option_string=None): - # Make sure we have an empty dict rather than None - if getattr(namespace, self.dest, None) is None: - setattr(namespace, self.dest, {}) - - # Add value if an assignment else remove it - if '=' in values: - key, value = values.split('=', 1) - # NOTE(qtang): Prevent null key setting in property - if '' == key: - msg = _("Property key must be specified: %s") - raise argparse.ArgumentTypeError(msg % str(values)) - - dest = getattr(namespace, self.dest) - if key in dest: - dest[key].append(value) - else: - dest[key] = [value] - else: - msg = _("Expected 'key=value' type, but got: %s") - raise argparse.ArgumentTypeError(msg % str(values)) - - class AddFixedIP(command.Command): _description = _("Add fixed IP address to server") @@ -719,7 +689,7 @@ class CreateServer(command.ShowOne): parser.add_argument( '--hint', metavar='', - action=KeyValueAppendAction, + action=parseractions.KeyValueAppendAction, default={}, help=_('Hints for the scheduler (optional extension)'), ) -- cgit v1.2.1