summaryrefslogtreecommitdiff
path: root/openstackclient
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2015-03-10 04:52:14 +0000
committerGerrit Code Review <review@openstack.org>2015-03-10 04:52:14 +0000
commit706c51bf962c17282f0c246c809f8f158e080cbc (patch)
treec06c6502c3c57aec3c0ef53f8e1b26d46a94428c /openstackclient
parent3da6e47e5e8455f8b42392a94b44574c36828e1e (diff)
parentfa5f02eb2280b7f713d2b7f6e5eafe191bb40d0c (diff)
downloadpython-openstackclient-706c51bf962c17282f0c246c809f8f158e080cbc.tar.gz
Merge "Add identity v3 catalog show"
Diffstat (limited to 'openstackclient')
-rw-r--r--openstackclient/identity/v3/catalog.py44
-rw-r--r--openstackclient/tests/identity/v3/test_catalog.py34
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)