From 39d18a36ce48a336eca5f5356a8950e1849d5dba Mon Sep 17 00:00:00 2001 From: Matt Pryor Date: Thu, 5 Dec 2024 18:09:20 +0000 Subject: [PATCH] Make OpenStack client region-aware (#91) * Make OpenStack client region-aware * Fix formatting --- azimuth_schedule_operator/openstack.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/azimuth_schedule_operator/openstack.py b/azimuth_schedule_operator/openstack.py index df18ed0..6dd2dfa 100644 --- a/azimuth_schedule_operator/openstack.py +++ b/azimuth_schedule_operator/openstack.py @@ -30,7 +30,7 @@ class Auth(httpx.Auth): def __init__( self, auth_url, application_credential_id, application_credential_secret ): - self.url = auth_url + self.url = auth_url.rstrip("/").removesuffix("/v3") self._application_credential_id = application_credential_id self._application_credential_secret = application_credential_secret self._token = None @@ -157,10 +157,11 @@ def resource(self, name, prefix=None, plural_name=None, singular_name=None): class Cloud: """Object for interacting with OpenStack clouds.""" - def __init__(self, auth, transport, interface): + def __init__(self, auth, transport, interface, region): self._auth = auth self._transport = transport self._interface = interface + self._region = region self._endpoints = {} # A map of api name to client self._clients = {} @@ -186,7 +187,10 @@ async def __aenter__(self): entry["type"]: next( ep["url"] for ep in entry["endpoints"] - if ep["interface"] == self._interface + if ( + ep["interface"] == self._interface + and (not self._region or ep["region"] == self._region) + ) ) for entry in response.json()["catalog"] if len(entry["endpoints"]) > 0 @@ -242,7 +246,9 @@ def from_clouds(clouds, cloud, cacert): if cacert is not None: context.load_verify_locations(cadata=cacert) transport = httpx.AsyncHTTPTransport(verify=context) - return Cloud(auth, transport, config.get("interface", "public")) + return Cloud( + auth, transport, config.get("interface", "public"), config.get("region_name") + ) def from_secret_data(secret_data):