diff options
author | Andrey Kurilin <akurilin@mirantis.com> | 2016-12-02 19:07:03 +0200 |
---|---|---|
committer | Andrey Kurilin <andr.kurilin@gmail.com> | 2016-12-15 19:49:03 +0200 |
commit | bf09ad844e7ccfc724ff502b34389e832a7ab7a2 (patch) | |
tree | 3b522e13a6de1f050f4145a0c6c46b890211cfd8 /novaclient/client.py | |
parent | 330516543b052b29c9663139086d635c7a27b301 (diff) | |
download | python-novaclient-bf09ad844e7ccfc724ff502b34389e832a7ab7a2.tar.gz |
Introduce helper for checking args deprecation
This patch introduces `_check_arguments` methods for processing deprecation
workflow of novaclient.client.Client entry-point.
Also, this patch adds a proper warning messages for 'auth_plugin',
'auth_system' arguments, which were removed previously
Change-Id: I7ee210c08f4126b267572c5428511451aeb17260
Diffstat (limited to 'novaclient/client.py')
-rw-r--r-- | novaclient/client.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/novaclient/client.py b/novaclient/client.py index 3d95f57b..44111418 100644 --- a/novaclient/client.py +++ b/novaclient/client.py @@ -825,6 +825,32 @@ def get_client_class(version): return client_class +def _check_arguments(kwargs, release, deprecated_name, right_name=None): + """Process deprecation of arguments. + + Checks presence of deprecated argument in kwargs, prints proper warning + message, renames key to right one it needed. + """ + if deprecated_name in kwargs: + msg = _LW("The '%(old)s' argument is deprecated in %(release)s and " + "its use may result in errors in future releases.") % { + "old": deprecated_name, "release": release} + if right_name: + if right_name in kwargs: + msg += _LW(" As '%(new)s' is provided, the '%(old)s' argument " + "will be ignored.") % {"old": deprecated_name, + "new": right_name} + kwargs.pop(deprecated_name) + else: + msg += _LW(" Use '%s' instead.") % right_name + kwargs[right_name] = kwargs.pop(deprecated_name) + else: + # just ignore it + kwargs.pop(deprecated_name) + + warnings.warn(msg) + + def Client(version, username=None, api_key=None, project_id=None, auth_url=None, **kwargs): """Initialize client object based on given version. @@ -847,6 +873,10 @@ def Client(version, username=None, api_key=None, project_id=None, session API. See "The novaclient Python API" page at python-novaclient's doc. """ + + _check_arguments(kwargs, "Ocata", "auth_plugin") + _check_arguments(kwargs, "Ocata", "auth_system") + api_version, client_class = _get_client_class_and_version(version) kwargs.pop("direct_use", None) return client_class(username=username, api_key=api_key, |