2222from cliff import lister
2323from cliff import show
2424
25- from keystoneclient import exceptions as identity_exc
26- from openstackclient .common import exceptions
2725from openstackclient .common import utils
26+ from openstackclient .identity import common
2827
2928
3029class CreateEndpoint (show .ShowOne ):
@@ -45,6 +44,7 @@ def get_parser(self, prog_name):
4544 parser .add_argument (
4645 '--publicurl' ,
4746 metavar = '<public-url>' ,
47+ required = True ,
4848 help = 'New endpoint public URL' )
4949 parser .add_argument (
5050 '--adminurl' ,
@@ -59,8 +59,7 @@ def get_parser(self, prog_name):
5959 def take_action (self , parsed_args ):
6060 self .log .debug ('take_action(%s)' % parsed_args )
6161 identity_client = self .app .client_manager .identity
62- service = utils .find_resource (identity_client .services ,
63- parsed_args .service )
62+ service = common .find_service (identity_client , parsed_args .service )
6463 endpoint = identity_client .endpoints .create (
6564 parsed_args .region ,
6665 service .id ,
@@ -120,8 +119,7 @@ def take_action(self, parsed_args):
120119 data = identity_client .endpoints .list ()
121120
122121 for ep in data :
123- service = utils .find_resource (
124- identity_client .services , ep .service_id )
122+ service = common .find_service (identity_client , ep .service_id )
125123 ep .service_name = service .name
126124 ep .service_type = service .type
127125 return (columns ,
@@ -139,77 +137,30 @@ class ShowEndpoint(show.ShowOne):
139137 def get_parser (self , prog_name ):
140138 parser = super (ShowEndpoint , self ).get_parser (prog_name )
141139 parser .add_argument (
142- 'service' ,
143- metavar = '<service>' ,
144- help = 'Name or ID of service endpoint to display' )
145- parser .add_argument (
146- '--type' ,
147- metavar = '<endpoint-type>' ,
148- default = 'publicURL' ,
149- help = 'Endpoint type: publicURL, internalURL, adminURL ' +
150- '(default publicURL)' )
151- parser .add_argument (
152- '--attr' ,
153- metavar = '<endpoint-attribute>' ,
154- help = 'Endpoint attribute to use for selection' )
155- parser .add_argument (
156- '--value' ,
157- metavar = '<endpoint-value>' ,
158- help = 'Value of endpoint attribute to use for selection' )
159- parser .add_argument (
160- '--all' ,
161- action = 'store_true' ,
162- default = False ,
163- help = 'Show all endpoints for this service' )
140+ 'endpoint_or_service' ,
141+ metavar = '<endpoint_or_service>' ,
142+ help = 'Endpoint ID or name, type or ID of service to display' )
164143 return parser
165144
166145 def take_action (self , parsed_args ):
167146 self .log .debug ('take_action(%s)' % parsed_args )
168147 identity_client = self .app .client_manager .identity
169-
170- if not parsed_args .all :
171- # Find endpoint filtered by a specific attribute or service type
172- kwargs = {
173- 'service_type' : parsed_args .service ,
174- 'endpoint_type' : parsed_args .type ,
175- }
176- if parsed_args .attr and parsed_args .value :
177- kwargs .update ({
178- 'attr' : parsed_args .attr ,
179- 'filter_value' : parsed_args .value ,
180- })
181- elif parsed_args .attr or parsed_args .value :
182- msg = 'Both --attr and --value required'
183- raise exceptions .CommandError (msg )
184-
185- url = identity_client .service_catalog .url_for (** kwargs )
186- info = {'%s.%s' % (parsed_args .service , parsed_args .type ): url }
187- return zip (* sorted (six .iteritems (info )))
188- else :
189- # The Identity 2.0 API doesn't support retrieving a single
190- # endpoint so we have to do this ourselves
191- try :
192- service = utils .find_resource (identity_client .services ,
193- parsed_args .service )
194- except exceptions .CommandError :
195- try :
196- # search for service type
197- service = identity_client .services .find (
198- type = parsed_args .service )
199- # FIXME(dtroyer): This exception should eventually come from
200- # common client exceptions
201- except identity_exc .NotFound :
202- msg = "No service with a type, name or ID of '%s' exists" \
203- % parsed_args .service
204- raise exceptions .CommandError (msg )
205-
206- data = identity_client .endpoints .list ()
148+ data = identity_client .endpoints .list ()
149+ match = None
150+ for ep in data :
151+ if ep .id == parsed_args .endpoint_or_service :
152+ match = ep
153+ service = common .find_service (identity_client , ep .service_id )
154+ if match is None :
155+ service = common .find_service (identity_client ,
156+ parsed_args .endpoint_or_service )
207157 for ep in data :
208158 if ep .service_id == service .id :
209- info = {}
210- info .update (ep ._info )
211- service = utils .find_resource (identity_client .services ,
212- ep .service_id )
213- info ['service_name' ] = service .name
214- info ['service_type' ] = service .type
215- return zip (* sorted (six .iteritems (info )))
159+ match = ep
160+ if match is None :
161+ return None
162+ info = {}
163+ info .update (match ._info )
164+ info ['service_name' ] = service .name
165+ info ['service_type' ] = service .type
166+ return zip (* sorted (six .iteritems (info )))
0 commit comments