[Refactor code] Backward compatibility.
Define method _check_argument to backward compatibility. Change-Id: I913d4f8b9ed5b40cb013b9549398c44db4cd993b
This commit is contained in:
parent
5e35360ba4
commit
6c49f94b2f
@ -12,6 +12,8 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import warnings
|
||||
|
||||
from oslo_utils import importutils
|
||||
|
||||
from zunclient import api_versions
|
||||
@ -31,8 +33,54 @@ def _get_client_class_and_version(version):
|
||||
'zunclient.v%s.client.Client' % version.ver_major)
|
||||
|
||||
|
||||
def _check_arguments(kwargs, release, deprecated_name, right_name=None):
|
||||
"""Process deprecation of arguments.
|
||||
|
||||
Check presence of deprecated argument in kwargs, prints proper warning
|
||||
message, renames key to right one it needed.
|
||||
"""
|
||||
if deprecated_name in kwargs:
|
||||
if right_name:
|
||||
if right_name in kwargs:
|
||||
msg = ('The %(old)s argument is deprecated in %(release)s'
|
||||
'and its use may result in errors in future releases.'
|
||||
'As %(new)s is provided, the %(old)s argument will '
|
||||
'be ignored.') % {'old': deprecated_name,
|
||||
'release': release,
|
||||
'new': right_name}
|
||||
kwargs.pop(deprecated_name)
|
||||
else:
|
||||
msg = ('The %(old)s argument is deprecated in %(release)s '
|
||||
'and its use may result in errors in future releases. '
|
||||
'Use %(new)s instead.') % {'old': deprecated_name,
|
||||
'release': release,
|
||||
'new': right_name}
|
||||
kwargs[right_name] = kwargs.pop(deprecated_name)
|
||||
else:
|
||||
msg = ('The %(old)s argument is deprecated in %(release)s '
|
||||
'and its use may result in errors in future '
|
||||
'releases') % {'old': deprecated_name,
|
||||
'release': release}
|
||||
# NOTE(kiennt): just ignore it
|
||||
kwargs.pop(deprecated_name)
|
||||
warnings.warn(msg)
|
||||
|
||||
|
||||
def Client(version='1', username=None, auth_url=None, **kwargs):
|
||||
"""Initialize client objects based on given version"""
|
||||
_check_arguments(kwargs, 'Queens', 'api_key', right_name='password')
|
||||
# NOTE: OpenStack projects use 2 vars with one meaning: `endpoint_type`
|
||||
# and `interface`. `endpoint_type` is an old name which was used by
|
||||
# most OpenStack clients. Later it was replaced by `interface` in
|
||||
# keystone and later some other clients switched to new var name too.
|
||||
_check_arguments(kwargs, 'Queens', 'endpoint_type',
|
||||
right_name='interface')
|
||||
_check_arguments(kwargs, 'Queens', 'zun_url',
|
||||
right_name='endpoint_override')
|
||||
_check_arguments(kwargs, 'Queens', 'tenant_name',
|
||||
right_name='project_name')
|
||||
_check_arguments(kwargs, 'Queens', 'tenant_id', right_name='project_id')
|
||||
|
||||
api_version, client_class = _get_client_class_and_version(version)
|
||||
return client_class(api_version=api_version,
|
||||
auth_url=auth_url,
|
||||
|
@ -38,15 +38,6 @@ class Client(object):
|
||||
project_domain_id=None, project_domain_name=None,
|
||||
api_version=None, **kwargs):
|
||||
|
||||
# We have to keep the api_key are for backwards compat, but let's
|
||||
# remove it from the rest of our code since it's not a keystone
|
||||
# concept
|
||||
if not password:
|
||||
password = api_key
|
||||
# Backwards compat for people assing in endpoint_type
|
||||
if endpoint_type:
|
||||
interface = endpoint_type
|
||||
|
||||
# fix (yolanda): os-cloud-config is using endpoint_override
|
||||
# instead of zun_url
|
||||
if endpoint_override and not zun_url:
|
||||
|
Loading…
Reference in New Issue
Block a user