Skip to content

Commit cefa571

Browse files
committed
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 <sfinucan@redhat.com>
1 parent ea27ebb commit cefa571

1 file changed

Lines changed: 1 addition & 31 deletions

File tree

openstackclient/compute/v2/server.py

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -201,36 +201,6 @@ def _prep_server_detail(compute_client, image_client, server, refresh=True):
201201
return info
202202

203203

204-
# TODO(stephenfin): Migrate this to osc-lib
205-
class KeyValueAppendAction(argparse.Action):
206-
"""A custom action to parse arguments as key=value pairs
207-
208-
Ensures that ``dest`` is a dict and values are lists of strings.
209-
"""
210-
211-
def __call__(self, parser, namespace, values, option_string=None):
212-
# Make sure we have an empty dict rather than None
213-
if getattr(namespace, self.dest, None) is None:
214-
setattr(namespace, self.dest, {})
215-
216-
# Add value if an assignment else remove it
217-
if '=' in values:
218-
key, value = values.split('=', 1)
219-
# NOTE(qtang): Prevent null key setting in property
220-
if '' == key:
221-
msg = _("Property key must be specified: %s")
222-
raise argparse.ArgumentTypeError(msg % str(values))
223-
224-
dest = getattr(namespace, self.dest)
225-
if key in dest:
226-
dest[key].append(value)
227-
else:
228-
dest[key] = [value]
229-
else:
230-
msg = _("Expected 'key=value' type, but got: %s")
231-
raise argparse.ArgumentTypeError(msg % str(values))
232-
233-
234204
class AddFixedIP(command.Command):
235205
_description = _("Add fixed IP address to server")
236206

@@ -719,7 +689,7 @@ def get_parser(self, prog_name):
719689
parser.add_argument(
720690
'--hint',
721691
metavar='<key=value>',
722-
action=KeyValueAppendAction,
692+
action=parseractions.KeyValueAppendAction,
723693
default={},
724694
help=_('Hints for the scheduler (optional extension)'),
725695
)

0 commit comments

Comments
 (0)