diff options
| author | Stephen Finucane <sfinucan@redhat.com> | 2019-09-27 12:59:48 +0100 |
|---|---|---|
| committer | Stephen Finucane <sfinucan@redhat.com> | 2020-02-03 15:25:40 +0000 |
| commit | cefa571d4b3162ab1da194573f85cce8bbdacc14 (patch) | |
| tree | 3766e3a12b541a6c400a0c5a938aad6c6530ad09 /openstackclient/compute/v2 | |
| parent | ea27ebb0f918db9eab2f5751a1b065818faa0e6d (diff) | |
| download | python-openstackclient-cefa571d4b3162ab1da194573f85cce8bbdacc14.tar.gz | |
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>
Diffstat (limited to 'openstackclient/compute/v2')
| -rw-r--r-- | openstackclient/compute/v2/server.py | 32 |
1 files changed, 1 insertions, 31 deletions
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='<key=value>', - action=KeyValueAppendAction, + action=parseractions.KeyValueAppendAction, default={}, help=_('Hints for the scheduler (optional extension)'), ) |
