Skip to content

Commit

Permalink
Make OpenStack client region-aware (#91)
Browse files Browse the repository at this point in the history
* Make OpenStack client region-aware

* Fix formatting
  • Loading branch information
mkjpryor authored Dec 5, 2024
1 parent bc8f4b7 commit 39d18a3
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions azimuth_schedule_operator/openstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = {}
Expand All @@ -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
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 39d18a3

Please sign in to comment.