Browse Source

Merge "horizon ignores region for identity service" into stable/icehouse

Jenkins 3 years ago
parent
commit
3f6e9b577a
1 changed files with 23 additions and 13 deletions
  1. 23
    13
      openstack_dashboard/api/base.py

+ 23
- 13
openstack_dashboard/api/base.py View File

@@ -231,19 +231,29 @@ ENDPOINT_TYPE_TO_INTERFACE = {
231 231
 
232 232
 def get_url_for_service(service, region, endpoint_type):
233 233
     identity_version = get_version_from_service(service)
234
-    for endpoint in service['endpoints']:
235
-        # ignore region for identity
236
-        if service['type'] == 'identity' or region == endpoint['region']:
237
-            try:
238
-                if identity_version < 3:
239
-                    return endpoint[endpoint_type]
240
-                else:
241
-                    interface = \
242
-                        ENDPOINT_TYPE_TO_INTERFACE.get(endpoint_type, '')
243
-                    if endpoint['interface'] == interface:
244
-                        return endpoint['url']
245
-            except (IndexError, KeyError):
246
-                return None
234
+    available_endpoints = [endpoint for endpoint in service['endpoints']
235
+                           if region == endpoint['region']]
236
+    """if we are dealing with the identity service and there is no endpoint
237
+    in the current region, it is okay to use the first endpoint for any
238
+    identity service endpoints and we can assume that it is global
239
+    """
240
+    if service['type'] == 'identity' and not available_endpoints:
241
+        available_endpoints = [endpoint for endpoint in service['endpoints']]
242
+
243
+    for endpoint in available_endpoints:
244
+        try:
245
+            if identity_version < 3:
246
+                return endpoint[endpoint_type]
247
+            else:
248
+                interface = \
249
+                    ENDPOINT_TYPE_TO_INTERFACE.get(endpoint_type, '')
250
+                if endpoint['interface'] == interface:
251
+                    return endpoint['url']
252
+        except (IndexError, KeyError):
253
+            """it could be that the current endpoint just doesn't match the
254
+            type, continue trying the next one
255
+            """
256
+            pass
247 257
     return None
248 258
 
249 259
 

Loading…
Cancel
Save