|
16 | 16 | import logging |
17 | 17 |
|
18 | 18 | from cliff import lister |
| 19 | +from cliff import show |
| 20 | +import six |
19 | 21 |
|
20 | 22 | from openstackclient.common import utils |
| 23 | +from openstackclient.i18n import _ # noqa |
21 | 24 |
|
22 | 25 |
|
23 | 26 | def _format_endpoints(eps=None): |
@@ -54,3 +57,44 @@ def take_action(self, parsed_args): |
54 | 57 | 'Endpoints': _format_endpoints, |
55 | 58 | }, |
56 | 59 | ) for s in data)) |
| 60 | + |
| 61 | + |
| 62 | +class ShowCatalog(show.ShowOne): |
| 63 | + """Display service catalog details""" |
| 64 | + |
| 65 | + log = logging.getLogger(__name__ + '.ShowCatalog') |
| 66 | + |
| 67 | + def get_parser(self, prog_name): |
| 68 | + parser = super(ShowCatalog, self).get_parser(prog_name) |
| 69 | + parser.add_argument( |
| 70 | + 'service', |
| 71 | + metavar='<service>', |
| 72 | + help=_('Service to display (type or name)'), |
| 73 | + ) |
| 74 | + return parser |
| 75 | + |
| 76 | + def take_action(self, parsed_args): |
| 77 | + self.log.debug('take_action(%s)', parsed_args) |
| 78 | + |
| 79 | + # This is ugly because if auth hasn't happened yet we need |
| 80 | + # to trigger it here. |
| 81 | + sc = self.app.client_manager.session.auth.get_auth_ref( |
| 82 | + self.app.client_manager.session, |
| 83 | + ).service_catalog |
| 84 | + |
| 85 | + data = None |
| 86 | + for service in sc.get_data(): |
| 87 | + if (service.get('name') == parsed_args.service or |
| 88 | + service.get('type') == parsed_args.service): |
| 89 | + data = dict(service) |
| 90 | + data['endpoints'] = _format_endpoints(data['endpoints']) |
| 91 | + if 'links' in data: |
| 92 | + data.pop('links') |
| 93 | + break |
| 94 | + |
| 95 | + if not data: |
| 96 | + self.app.log.error('service %s not found\n' % |
| 97 | + parsed_args.service) |
| 98 | + return ([], []) |
| 99 | + |
| 100 | + return zip(*sorted(six.iteritems(data))) |
0 commit comments