diff options
| author | Akihiro Motoki <amotoki@gmail.com> | 2017-05-15 04:00:32 +0000 |
|---|---|---|
| committer | Dean Troyer <dtroyer@gmail.com> | 2019-06-22 16:18:26 +0000 |
| commit | fa5046a3dbf8cf398b9a05c68e6ee4badbb14ee7 (patch) | |
| tree | f6401632eb05db3d21f42e70695196976bc7408c /openstackclient/identity/v3 | |
| parent | c44f26eb7e41c28bb13ef9bd31c8ddda9e638862 (diff) | |
| download | python-openstackclient-fa5046a3dbf8cf398b9a05c68e6ee4badbb14ee7.tar.gz | |
Use cliff formattable columns in identity commands
Partial-Bug: #1687955
Partially implement blueprint osc-formattable-columns
Change-Id: Ia13314a012b3a7363ffb24a13c79c6ecdff1ed7b
Diffstat (limited to 'openstackclient/identity/v3')
| -rw-r--r-- | openstackclient/identity/v3/catalog.py | 24 | ||||
| -rw-r--r-- | openstackclient/identity/v3/identity_provider.py | 5 |
2 files changed, 16 insertions, 13 deletions
diff --git a/openstackclient/identity/v3/catalog.py b/openstackclient/identity/v3/catalog.py index 28f4fada..59430c4c 100644 --- a/openstackclient/identity/v3/catalog.py +++ b/openstackclient/identity/v3/catalog.py @@ -15,6 +15,7 @@ import logging +from cliff import columns as cliff_columns from osc_lib.command import command from osc_lib import exceptions from osc_lib import utils @@ -26,15 +27,16 @@ from openstackclient.i18n import _ LOG = logging.getLogger(__name__) -def _format_endpoints(eps=None): - if not eps: - return "" - ret = '' - for ep in eps: - region = ep.get('region_id') or ep.get('region') or '<none>' - ret += region + '\n' - ret += " %s: %s\n" % (ep['interface'], ep['url']) - return ret +class EndpointsColumn(cliff_columns.FormattableColumn): + def human_readable(self): + if not self._value: + return "" + ret = '' + for ep in self._value: + region = ep.get('region_id') or ep.get('region') or '<none>' + ret += region + '\n' + ret += " %s: %s\n" % (ep['interface'], ep['url']) + return ret class ListCatalog(command.Lister): @@ -55,7 +57,7 @@ class ListCatalog(command.Lister): (utils.get_dict_properties( s, columns, formatters={ - 'Endpoints': _format_endpoints, + 'Endpoints': EndpointsColumn, }, ) for s in data)) @@ -86,7 +88,7 @@ class ShowCatalog(command.ShowOne): if (service.get('name') == parsed_args.service or service.get('type') == parsed_args.service): data = dict(service) - data['endpoints'] = _format_endpoints(data['endpoints']) + data['endpoints'] = EndpointsColumn(data['endpoints']) if 'links' in data: data.pop('links') break diff --git a/openstackclient/identity/v3/identity_provider.py b/openstackclient/identity/v3/identity_provider.py index d8951d31..b3315182 100644 --- a/openstackclient/identity/v3/identity_provider.py +++ b/openstackclient/identity/v3/identity_provider.py @@ -15,6 +15,7 @@ import logging +from osc_lib.cli import format_columns from osc_lib.command import command from osc_lib import exceptions from osc_lib import utils @@ -103,7 +104,7 @@ class CreateIdentityProvider(command.ShowOne): enabled=parsed_args.enabled) idp._info.pop('links', None) - remote_ids = utils.format_list(idp._info.pop('remote_ids', [])) + remote_ids = format_columns.ListColumn(idp._info.pop('remote_ids', [])) idp._info['remote_ids'] = remote_ids return zip(*sorted(six.iteritems(idp._info))) @@ -245,6 +246,6 @@ class ShowIdentityProvider(command.ShowOne): id=parsed_args.identity_provider) idp._info.pop('links', None) - remote_ids = utils.format_list(idp._info.pop('remote_ids', [])) + remote_ids = format_columns.ListColumn(idp._info.pop('remote_ids', [])) idp._info['remote_ids'] = remote_ids return zip(*sorted(six.iteritems(idp._info))) |
