Add --catalog to service show

Shows endpoints from the service catalog rather than the system services.

Change-Id: I842916af9f7c0a76c4d3e27e419bf0fec059ec78
This commit is contained in:
Dean Troyer 2013-01-17 14:16:32 -06:00
parent 6cb58fa16b
commit bbb71e7ce2

View File

@ -1,4 +1,4 @@
# Copyright 2012-2013 OpenStack, LLC. # Copyright 2012-2013 OpenStack Foundation
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may # Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain # not use this file except in compliance with the License. You may obtain
@ -110,7 +110,7 @@ class ListService(lister.Lister):
class ShowService(show.ShowOne): class ShowService(show.ShowOne):
"""Show service command""" """Show cloud service information"""
log = logging.getLogger(__name__ + '.ShowService') log = logging.getLogger(__name__ + '.ShowService')
@ -119,16 +119,39 @@ class ShowService(show.ShowOne):
parser.add_argument( parser.add_argument(
'service', 'service',
metavar='<service>', metavar='<service>',
help='Type, name or ID of service to display') help='Type, name or ID of service to display',
)
parser.add_argument(
'--catalog',
action='store_true',
default=False,
help='Show service catalog information',
)
return parser return parser
def take_action(self, parsed_args): def take_action(self, parsed_args):
self.log.debug('take_action(%s)' % parsed_args) self.log.debug('take_action(%s)' % parsed_args)
identity_client = self.app.client_manager.identity identity_client = self.app.client_manager.identity
if parsed_args.catalog:
endpoints = identity_client.service_catalog.get_endpoints(
service_type=parsed_args.service)
for (service, service_endpoints) in endpoints.iteritems():
if service_endpoints:
info = {"type": service}
info.update(service_endpoints[0])
return zip(*sorted(info.iteritems()))
msg = ("No service catalog with a type, name or ID of '%s' "
"exists." % (parsed_args.service))
raise exceptions.CommandError(msg)
else:
try: try:
# search for the usual ID or name # search for the usual ID or name
service = utils.find_resource(identity_client.services, service = utils.find_resource(
parsed_args.service) identity_client.services,
parsed_args.service,
)
except exceptions.CommandError: except exceptions.CommandError:
try: try:
# search for service type # search for service type
@ -137,10 +160,8 @@ class ShowService(show.ShowOne):
# FIXME(dtroyer): This exception should eventually come from # FIXME(dtroyer): This exception should eventually come from
# common client exceptions # common client exceptions
except identity_exc.NotFound: except identity_exc.NotFound:
msg = "No service with exists." msg = ("No service with a type, name or ID of '%s' exists."
# TODO(mordred): Where does name_or_id come from? % parsed_args.service)
# msg = ("No service with a type, name or ID of '%s' exists." %
# name_or_id)
raise exceptions.CommandError(msg) raise exceptions.CommandError(msg)
info = {} info = {}