From 4f98c8b23d82ea15151ef0ffb49f39987eb088b0 Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Fri, 10 Feb 2017 09:43:18 -0600 Subject: [PATCH] Add accessor method to pull URLs from the catalog It's handy sometimes and the specifics of how to do so is complex. Change-Id: I90d5c8c2709cf9d8bd76c3dbcbe171c7d75572a8 --- .../endpoint-from-catalog-bad36cb0409a4e6a.yaml | 4 ++++ shade/openstackcloud.py | 12 ++++++++++-- shade/tests/unit/base.py | 7 ++----- 3 files changed, 16 insertions(+), 7 deletions(-) create mode 100644 releasenotes/notes/endpoint-from-catalog-bad36cb0409a4e6a.yaml diff --git a/releasenotes/notes/endpoint-from-catalog-bad36cb0409a4e6a.yaml b/releasenotes/notes/endpoint-from-catalog-bad36cb0409a4e6a.yaml new file mode 100644 index 000000000..2db7bc947 --- /dev/null +++ b/releasenotes/notes/endpoint-from-catalog-bad36cb0409a4e6a.yaml @@ -0,0 +1,4 @@ +--- +features: + - Add new method, 'endpoint_for' which will return the + raw endpoint for a given service from the current catalog. diff --git a/shade/openstackcloud.py b/shade/openstackcloud.py index 19714c476..78124749f 100644 --- a/shade/openstackcloud.py +++ b/shade/openstackcloud.py @@ -566,9 +566,17 @@ class OpenStackCloud(_normalize.Normalizer): return self._keystone_client @property - def service_catalog(self): + def _keystone_catalog(self): return self.keystone_session.auth.get_access( - self.keystone_session).service_catalog.catalog + self.keystone_session).service_catalog + + @property + def service_catalog(self): + return self._keystone_catalog.catalog + + def endpoint_for(self, service_type, interface='public'): + return self._keystone_catalog.url_for( + service_type=service_type, interface=interface) @property def auth_token(self): diff --git a/shade/tests/unit/base.py b/shade/tests/unit/base.py index 788bb4b4e..1557d90eb 100644 --- a/shade/tests/unit/base.py +++ b/shade/tests/unit/base.py @@ -122,11 +122,8 @@ class RequestsMockTestCase(BaseTestCase): def get_mock_url(self, service_type, interface, resource=None, append=None, base_url_append=None): - service_catalog = self.cloud.keystone_session.auth.get_access( - self.cloud.keystone_session).service_catalog - endpoint_url = service_catalog.url_for( - service_type=service_type, - interface=interface) + endpoint_url = self.cloud.endpoint_for( + service_type=service_type, interface=interface) to_join = [endpoint_url] if base_url_append: to_join.append(base_url_append)