diff options
| author | Jenkins <jenkins@review.openstack.org> | 2017-01-26 23:57:36 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2017-01-26 23:57:36 +0000 |
| commit | fc976390e25fa17ce381af8e7c20ff1d0f243b41 (patch) | |
| tree | b4fa7eea4e87a30577d8bd4a532d5a1e013f1638 /cinderclient/client.py | |
| parent | 4c61c6556b65af0347afc6e6a86c0f7fc06ffd6c (diff) | |
| parent | 4f22510ccf0628554de1b566e007a7af750d99cf (diff) | |
| download | python-cinderclient-fc976390e25fa17ce381af8e7c20ff1d0f243b41.tar.gz | |
Merge "static method to get_server_version"
Diffstat (limited to 'cinderclient/client.py')
| -rw-r--r-- | cinderclient/client.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/cinderclient/client.py b/cinderclient/client.py index 43157e6..298ec94 100644 --- a/cinderclient/client.py +++ b/cinderclient/client.py @@ -40,6 +40,7 @@ from cinderclient import api_versions from cinderclient import exceptions import cinderclient.extension from cinderclient._i18n import _ +from cinderclient._i18n import _LW from oslo_utils import encodeutils from oslo_utils import importutils from oslo_utils import strutils @@ -72,6 +73,30 @@ for svc in ('volume', 'volumev2', 'volumev3'): discover.add_catalog_discover_hack(svc, re.compile('/v[12]/\w+/?$'), '/') +def get_server_version(url): + """Queries the server via the naked endpoint and gets version info. + + :param url: url of the cinder endpoint + :returns: APIVersion object for min and max version supported by + the server + """ + + logger = logging.getLogger(__name__) + try: + scheme, netloc, path, query, frag = urlparse.urlsplit(url) + response = requests.get(scheme + '://' + netloc) + data = json.loads(response.text) + versions = data['versions'] + for version in versions: + if '3.' in version['version']: + return (api_versions.APIVersion(version['min_version']), + api_versions.APIVersion(version['version'])) + except exceptions.ClientException as e: + logger.warning(_LW("Error in server version query:%s\n" + "Returning APIVersion 2.0") % six.text_type(e.message)) + return api_versions.APIVersion("2.0"), api_versions.APIVersion("2.0") + + def get_volume_api_from_url(url): scheme, netloc, path, query, frag = urlparse.urlsplit(url) components = path.split("/") |
