Merge "Update make_rest_client to work with version discovery"

This commit is contained in:
Zuul 2017-10-21 15:19:51 +00:00 committed by Gerrit Code Review
commit da432d4a51
3 changed files with 34 additions and 3 deletions

View File

@ -45,7 +45,7 @@ def get_config(
def make_rest_client(
service_key, options=None,
app_name=None, app_version=None,
app_name=None, app_version=None, version=None,
**kwargs):
"""Simple wrapper function. It has almost no features.
@ -63,7 +63,7 @@ def make_rest_client(
service_key=service_key, options=options,
app_name=app_name, app_version=app_version,
**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
simple_client = make_rest_client
# Backwards compat - session_client was a terrible name

View File

@ -235,7 +235,27 @@ class CloudConfig(object):
"""Helper method to grab the 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.
This is useful for making direct requests calls against a
@ -249,12 +269,17 @@ class CloudConfig(object):
and it will work like you think.
"""
(version, min_version, max_version) = self._get_version_args(
service_key, version)
return adapter.Adapter(
session=self.get_session(),
service_type=self.get_service_type(service_key),
service_name=self.get_service_name(service_key),
interface=self.get_interface(service_key),
version=version,
min_version=min_version,
max_version=max_version,
region_name=self.region)
def _get_highest_endpoint(self, service_types, kwargs):

View File

@ -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.