Merge "Add identity v3 catalog show"
This commit is contained in:
commit
706c51bf96
@ -2,7 +2,7 @@
|
||||
catalog
|
||||
=======
|
||||
|
||||
Identity v2
|
||||
Identity v2, v3
|
||||
|
||||
catalog list
|
||||
------------
|
||||
|
@ -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)))
|
||||
|
@ -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)
|
||||
|
@ -186,6 +186,7 @@ openstack.identity.v3 =
|
||||
access_token_create = openstackclient.identity.v3.token:CreateAccessToken
|
||||
|
||||
catalog_list = openstackclient.identity.v3.catalog:ListCatalog
|
||||
catalog_show = openstackclient.identity.v3.catalog:ShowCatalog
|
||||
|
||||
consumer_create = openstackclient.identity.v3.consumer:CreateConsumer
|
||||
consumer_delete = openstackclient.identity.v3.consumer:DeleteConsumer
|
||||
|
Loading…
Reference in New Issue
Block a user