diff options
| author | TerryHowe <terrylhowe@gmail.com> | 2015-03-06 11:14:42 -0700 |
|---|---|---|
| committer | Steve Martinelli <stevemar@ca.ibm.com> | 2015-03-09 23:08:15 -0400 |
| commit | fa5f02eb2280b7f713d2b7f6e5eafe191bb40d0c (patch) | |
| tree | 28c42c92ac59fd18e3ef7be69a46cb41dfc7af11 /openstackclient | |
| parent | a2167466273fd7cdd50c67cb82fdbfa333b30102 (diff) | |
| download | python-openstackclient-fa5f02eb2280b7f713d2b7f6e5eafe191bb40d0c.tar.gz | |
Add identity v3 catalog show
Change-Id: Ia6b6c25eded43b899b3aa026227ad2859f1c67dd
Diffstat (limited to 'openstackclient')
| -rw-r--r-- | openstackclient/identity/v3/catalog.py | 44 | ||||
| -rw-r--r-- | openstackclient/tests/identity/v3/test_catalog.py | 34 |
2 files changed, 78 insertions, 0 deletions
diff --git a/openstackclient/identity/v3/catalog.py b/openstackclient/identity/v3/catalog.py index 09713661..1899f25e 100644 --- a/openstackclient/identity/v3/catalog.py +++ b/openstackclient/identity/v3/catalog.py @@ -16,8 +16,11 @@ import logging from cliff import lister +from cliff import show +import six from openstackclient.common import utils +from openstackclient.i18n import _ # noqa def _format_endpoints(eps=None): @@ -54,3 +57,44 @@ class ListCatalog(lister.Lister): 'Endpoints': _format_endpoints, }, ) for s in data)) + + +class ShowCatalog(show.ShowOne): + """Display service catalog details""" + + log = logging.getLogger(__name__ + '.ShowCatalog') + + def get_parser(self, prog_name): + parser = super(ShowCatalog, self).get_parser(prog_name) + parser.add_argument( + 'service', + metavar='<service>', + help=_('Service to display (type or name)'), + ) + return parser + + def take_action(self, parsed_args): + self.log.debug('take_action(%s)', parsed_args) + + # This is ugly because if auth hasn't happened yet we need + # to trigger it here. + sc = self.app.client_manager.session.auth.get_auth_ref( + self.app.client_manager.session, + ).service_catalog + + data = None + for service in sc.get_data(): + if (service.get('name') == parsed_args.service or + service.get('type') == parsed_args.service): + data = dict(service) + data['endpoints'] = _format_endpoints(data['endpoints']) + if 'links' in data: + data.pop('links') + break + + if not data: + self.app.log.error('service %s not found\n' % + parsed_args.service) + return ([], []) + + return zip(*sorted(six.iteritems(data))) diff --git a/openstackclient/tests/identity/v3/test_catalog.py b/openstackclient/tests/identity/v3/test_catalog.py index 9adda863..6bb962de 100644 --- a/openstackclient/tests/identity/v3/test_catalog.py +++ b/openstackclient/tests/identity/v3/test_catalog.py @@ -82,3 +82,37 @@ class TestCatalogList(TestCatalog): '<none>\n internal: https://internal.example.com\n', ), ) self.assertEqual(datalist, tuple(data)) + + +class TestCatalogShow(TestCatalog): + + def setUp(self): + super(TestCatalogShow, self).setUp() + + # Get the command object to test + self.cmd = catalog.ShowCatalog(self.app, None) + + def test_catalog_show(self): + arglist = [ + 'compute', + ] + verifylist = [ + ('service', 'compute'), + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + # DisplayCommandBase.take_action() returns two tuples + columns, data = self.cmd.take_action(parsed_args) + self.sc_mock.service_catalog.get_data.assert_called_with() + + collist = ('endpoints', 'id', 'name', 'type') + self.assertEqual(collist, columns) + datalist = ( + 'onlyone\n public: https://public.example.com\nonlyone\n' + ' admin: https://admin.example.com\n' + '<none>\n internal: https://internal.example.com\n', + 'qwertyuiop', + 'supernova', + 'compute', + ) + self.assertEqual(datalist, data) |
