summaryrefslogtreecommitdiff
path: root/novaclient/client.py
diff options
context:
space:
mode:
Diffstat (limited to 'novaclient/client.py')
-rw-r--r--novaclient/client.py37
1 files changed, 26 insertions, 11 deletions
diff --git a/novaclient/client.py b/novaclient/client.py
index 85d618d..d7656da 100644
--- a/novaclient/client.py
+++ b/novaclient/client.py
@@ -24,8 +24,10 @@ import copy
24import functools 24import functools
25import hashlib 25import hashlib
26import logging 26import logging
27import pkgutil
27import re 28import re
28import socket 29import socket
30import warnings
29 31
30from keystoneclient import adapter 32from keystoneclient import adapter
31from oslo_utils import importutils 33from oslo_utils import importutils
@@ -41,11 +43,15 @@ except ImportError:
41from six.moves.urllib import parse 43from six.moves.urllib import parse
42 44
43from novaclient import exceptions 45from novaclient import exceptions
44from novaclient.i18n import _ 46from novaclient.i18n import _, _LW
45from novaclient import service_catalog 47from novaclient import service_catalog
46from novaclient import utils 48from novaclient import utils
47 49
48 50
51# key is a deprecated version and value is an alternative version.
52DEPRECATED_VERSIONS = {"1.1": "2"}
53
54
49class TCPKeepAliveAdapter(adapters.HTTPAdapter): 55class TCPKeepAliveAdapter(adapters.HTTPAdapter):
50 """The custom adapter used to set TCP Keep-Alive on all connections.""" 56 """The custom adapter used to set TCP Keep-Alive on all connections."""
51 def init_poolmanager(self, *args, **kwargs): 57 def init_poolmanager(self, *args, **kwargs):
@@ -712,21 +718,30 @@ def _construct_http_client(username=None, password=None, project_id=None,
712 718
713 719
714def get_client_class(version): 720def get_client_class(version):
715 version_map = { 721 version = str(version)
716 '1.1': 'novaclient.v2.client.Client', 722 if version in DEPRECATED_VERSIONS:
717 '2': 'novaclient.v2.client.Client', 723 warnings.warn(_LW(
718 '3': 'novaclient.v2.client.Client', 724 "Version %(deprecated_version)s is deprecated, using "
719 } 725 "alternative version %(alternative)s instead.") %
726 {"deprecated_version": version,
727 "alternative": DEPRECATED_VERSIONS[version]})
728 version = DEPRECATED_VERSIONS[version]
720 try: 729 try:
721 client_path = version_map[str(version)] 730 return importutils.import_class(
722 except (KeyError, ValueError): 731 "novaclient.v%s.client.Client" % version)
732 except ImportError:
733 # NOTE(andreykurilin): available clients version should not be
734 # hardcoded, so let's discover them.
735 matcher = re.compile(r"v[0-9_]*$")
736 submodules = pkgutil.iter_modules(['novaclient'])
737 available_versions = [
738 name[1:].replace("_", ".") for loader, name, ispkg in submodules
739 if matcher.search(name)]
723 msg = _("Invalid client version '%(version)s'. must be one of: " 740 msg = _("Invalid client version '%(version)s'. must be one of: "
724 "%(keys)s") % {'version': version, 741 "%(keys)s") % {'version': version,
725 'keys': ', '.join(version_map.keys())} 742 'keys': ', '.join(available_versions)}
726 raise exceptions.UnsupportedVersion(msg) 743 raise exceptions.UnsupportedVersion(msg)
727 744
728 return importutils.import_class(client_path)
729
730 745
731def Client(version, *args, **kwargs): 746def Client(version, *args, **kwargs):
732 client_class = get_client_class(version) 747 client_class = get_client_class(version)