1- # Copyright 2012-2013 OpenStack, LLC.
1+ # Copyright 2012-2013 OpenStack Foundation
22#
33# Licensed under the Apache License, Version 2.0 (the "License"); you may
44# not use this file except in compliance with the License. You may obtain
@@ -110,7 +110,7 @@ def take_action(self, parsed_args):
110110
111111
112112class ShowService (show .ShowOne ):
113- """Show service command """
113+ """Show cloud service information """
114114
115115 log = logging .getLogger (__name__ + '.ShowService' )
116116
@@ -119,30 +119,51 @@ def get_parser(self, prog_name):
119119 parser .add_argument (
120120 'service' ,
121121 metavar = '<service>' ,
122- help = 'Type, name or ID of service to display' )
122+ help = 'Type, name or ID of service to display' ,
123+ )
124+ parser .add_argument (
125+ '--catalog' ,
126+ action = 'store_true' ,
127+ default = False ,
128+ help = 'Show service catalog information' ,
129+ )
123130 return parser
124131
125132 def take_action (self , parsed_args ):
126133 self .log .debug ('take_action(%s)' % parsed_args )
127134 identity_client = self .app .client_manager .identity
128- try :
129- # search for the usual ID or name
130- service = utils .find_resource (identity_client .services ,
131- parsed_args .service )
132- except exceptions .CommandError :
133- try :
134- # search for service type
135- service = identity_client .services .find (
136- type = parsed_args .service )
137- # FIXME(dtroyer): This exception should eventually come from
138- # common client exceptions
139- except identity_exc .NotFound :
140- msg = "No service with exists."
141- # TODO(mordred): Where does name_or_id come from?
142- # msg = ("No service with a type, name or ID of '%s' exists." %
143- # name_or_id)
144- raise exceptions .CommandError (msg )
145135
146- info = {}
147- info .update (service ._info )
148- return zip (* sorted (info .iteritems ()))
136+ if parsed_args .catalog :
137+ endpoints = identity_client .service_catalog .get_endpoints (
138+ service_type = parsed_args .service )
139+ for (service , service_endpoints ) in endpoints .iteritems ():
140+ if service_endpoints :
141+ info = {"type" : service }
142+ info .update (service_endpoints [0 ])
143+ return zip (* sorted (info .iteritems ()))
144+
145+ msg = ("No service catalog with a type, name or ID of '%s' "
146+ "exists." % (parsed_args .service ))
147+ raise exceptions .CommandError (msg )
148+ else :
149+ try :
150+ # search for the usual ID or name
151+ service = utils .find_resource (
152+ identity_client .services ,
153+ parsed_args .service ,
154+ )
155+ except exceptions .CommandError :
156+ try :
157+ # search for service type
158+ service = identity_client .services .find (
159+ type = parsed_args .service )
160+ # FIXME(dtroyer): This exception should eventually come from
161+ # common client exceptions
162+ except identity_exc .NotFound :
163+ msg = ("No service with a type, name or ID of '%s' exists."
164+ % parsed_args .service )
165+ raise exceptions .CommandError (msg )
166+
167+ info = {}
168+ info .update (service ._info )
169+ return zip (* sorted (info .iteritems ()))
0 commit comments