Skip to content

Commit e63655e

Browse files
committed
Address review comments
1 parent 1c6f929 commit e63655e

File tree

1 file changed

+8
-21
lines changed

1 file changed

+8
-21
lines changed

capi_janitor/openstack/openstack.py

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,14 @@ async def __aenter__(self):
175175
else:
176176
raise
177177
self._endpoints = {
178-
entry["type"]: self._service_endpoint(entry)["url"]
178+
entry["type"]: next(
179+
ep["url"]
180+
for ep in entry["endpoints"]
181+
if (
182+
ep["interface"] == self._interface and
183+
(not self._region or ep["region"] == self._region)
184+
)
185+
)
179186
for entry in response.json()["catalog"]
180187
if len(entry["endpoints"]) > 0
181188
}
@@ -218,26 +225,6 @@ def api_client(self, name, prefix = None):
218225
)
219226
return self._clients[name]
220227

221-
def _service_endpoint(self, catalog_entry):
222-
"""
223-
Filters the target cloud's catalog endpoints to find the relevant entry.
224-
"""
225-
endpoints = catalog_entry["endpoints"]
226-
iface_endpoints = [ep for ep in endpoints if ep["interface"] == self._interface]
227-
# If there's no region_name field in the clouds.yaml we use the first endpoint which
228-
# matches the interface name for consistent behaviour with the OpenStack CLI.
229-
if not self._region:
230-
return iface_endpoints[0]
231-
# Otherwise, further filter by region name
232-
region_endpoints = [ep for ep in iface_endpoints if ep["region"] == self._region]
233-
if len(region_endpoints) != 1:
234-
raise Exception(
235-
"Failed to find a unique catalog endpoints for"
236-
f" interface {region_endpoints[0]['interface']}"
237-
f" and region {region_endpoints[0]['region']}"
238-
)
239-
return region_endpoints[0]
240-
241228
@classmethod
242229
def from_clouds(cls, clouds, cloud, cacert):
243230
config = clouds["clouds"][cloud]

0 commit comments

Comments
 (0)