Update make_rest_client to work with version discovery
Using make_rest_client on clouds that put unversioned endpoints in the catalog results in incorrectly set up adapters. Add the plumbing to get_session_client to pass version args to keystoneauth. Then use that from make_rest_client. Change-Id: I69ad746f672ef0b12680e9db3c7b0c691c9f87e4
This commit is contained in:
parent
3bb4c37c88
commit
bae63fca37
@ -40,7 +40,7 @@ def get_config(
|
|||||||
|
|
||||||
def make_rest_client(
|
def make_rest_client(
|
||||||
service_key, options=None,
|
service_key, options=None,
|
||||||
app_name=None, app_version=None,
|
app_name=None, app_version=None, version=None,
|
||||||
**kwargs):
|
**kwargs):
|
||||||
"""Simple wrapper function. It has almost no features.
|
"""Simple wrapper function. It has almost no features.
|
||||||
|
|
||||||
@ -58,7 +58,7 @@ def make_rest_client(
|
|||||||
service_key=service_key, options=options,
|
service_key=service_key, options=options,
|
||||||
app_name=app_name, app_version=app_version,
|
app_name=app_name, app_version=app_version,
|
||||||
**kwargs)
|
**kwargs)
|
||||||
return cloud.get_session_client(service_key)
|
return cloud.get_session_client(service_key, version=version)
|
||||||
# Backwards compat - simple_client was a terrible name
|
# Backwards compat - simple_client was a terrible name
|
||||||
simple_client = make_rest_client
|
simple_client = make_rest_client
|
||||||
# Backwards compat - session_client was a terrible name
|
# Backwards compat - session_client was a terrible name
|
||||||
|
@ -237,7 +237,27 @@ class CloudConfig(object):
|
|||||||
"""Helper method to grab the service catalog."""
|
"""Helper method to grab the service catalog."""
|
||||||
return self._auth.get_access(self.get_session()).service_catalog
|
return self._auth.get_access(self.get_session()).service_catalog
|
||||||
|
|
||||||
def get_session_client(self, service_key):
|
def _get_version_args(self, service_key, version):
|
||||||
|
"""Translate OCC version args to those needed by ksa adapter.
|
||||||
|
|
||||||
|
If no version is requested explicitly and we have a configured version,
|
||||||
|
set the version parameter and let ksa deal with expanding that to
|
||||||
|
min=ver.0, max=ver.latest.
|
||||||
|
|
||||||
|
If version is set, pass it through.
|
||||||
|
|
||||||
|
If version is not set and we don't have a configured version, default
|
||||||
|
to latest.
|
||||||
|
"""
|
||||||
|
if version == 'latest':
|
||||||
|
return None, None, 'latest'
|
||||||
|
if not version:
|
||||||
|
version = self.get_api_version(service_key)
|
||||||
|
if not version:
|
||||||
|
return None, None, 'latest'
|
||||||
|
return version, None, None
|
||||||
|
|
||||||
|
def get_session_client(self, service_key, version=None):
|
||||||
"""Return a prepped requests adapter for a given service.
|
"""Return a prepped requests adapter for a given service.
|
||||||
|
|
||||||
This is useful for making direct requests calls against a
|
This is useful for making direct requests calls against a
|
||||||
@ -251,13 +271,18 @@ class CloudConfig(object):
|
|||||||
|
|
||||||
and it will work like you think.
|
and it will work like you think.
|
||||||
"""
|
"""
|
||||||
|
(version, min_version, max_version) = self._get_version_args(
|
||||||
|
service_key, version)
|
||||||
|
|
||||||
return adapter.Adapter(
|
return adapter.Adapter(
|
||||||
session=self.get_session(),
|
session=self.get_session(),
|
||||||
service_type=self.get_service_type(service_key),
|
service_type=self.get_service_type(service_key),
|
||||||
service_name=self.get_service_name(service_key),
|
service_name=self.get_service_name(service_key),
|
||||||
interface=self.get_interface(service_key),
|
interface=self.get_interface(service_key),
|
||||||
region_name=self.get_region_name(service_key))
|
region_name=self.get_region_name(service_key),
|
||||||
|
version=version,
|
||||||
|
min_version=min_version,
|
||||||
|
max_version=max_version)
|
||||||
|
|
||||||
def _get_highest_endpoint(self, service_types, kwargs):
|
def _get_highest_endpoint(self, service_types, kwargs):
|
||||||
session = self.get_session()
|
session = self.get_session()
|
||||||
|
@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
features:
|
||||||
|
- Add version argument to make_rest_client and plumb
|
||||||
|
version discovery through get_session_client so that
|
||||||
|
versioned endpoints are properly found if unversioned
|
||||||
|
are in the catalog.
|
Loading…
Reference in New Issue
Block a user