module_utils: implement deprecation warning for params (#20884)
* module_utils: implement deprecation warning for params * rename deprecated_version to removed_in_version * fix pep8 E121
This commit is contained in:
parent
e401b4e424
commit
541a51ddf7
2 changed files with 15 additions and 7 deletions
|
@ -718,6 +718,12 @@ class AnsibleModule(object):
|
||||||
if no_log_object:
|
if no_log_object:
|
||||||
self.no_log_values.update(return_values(no_log_object))
|
self.no_log_values.update(return_values(no_log_object))
|
||||||
|
|
||||||
|
if arg_opts.get('removed_in_version') is not None and arg_name in self.params:
|
||||||
|
self._deprecations.append({
|
||||||
|
'msg': "Param '%s' is deprecated. See the module docs for more information" % arg_name,
|
||||||
|
'version': arg_opts.get('removed_in_version')
|
||||||
|
})
|
||||||
|
|
||||||
# check the locale as set by the current environment, and reset to
|
# check the locale as set by the current environment, and reset to
|
||||||
# a known valid (LANG=C) if it's an invalid/unavailable locale
|
# a known valid (LANG=C) if it's an invalid/unavailable locale
|
||||||
self._check_locale()
|
self._check_locale()
|
||||||
|
@ -768,13 +774,15 @@ class AnsibleModule(object):
|
||||||
else:
|
else:
|
||||||
raise TypeError("warn requires a string not a %s" % type(warning))
|
raise TypeError("warn requires a string not a %s" % type(warning))
|
||||||
|
|
||||||
def deprecate(self, deprecate):
|
def deprecate(self, msg, version=None):
|
||||||
|
if isinstance(msg, string_types):
|
||||||
if isinstance(deprecate, string_types):
|
self._deprecations.append({
|
||||||
self._deprecations.append(deprecate)
|
'msg': msg,
|
||||||
self.log('[DEPRECATION WARNING] %s' % deprecate)
|
'version': version
|
||||||
|
})
|
||||||
|
self.log('[DEPRECATION WARNING] %s %s' % (msg, version))
|
||||||
else:
|
else:
|
||||||
raise TypeError("deprecate requires a string not a %s" % type(deprecate))
|
raise TypeError("deprecate requires a string not a %s" % type(msg))
|
||||||
|
|
||||||
def load_file_common_arguments(self, params):
|
def load_file_common_arguments(self, params):
|
||||||
'''
|
'''
|
||||||
|
|
|
@ -105,7 +105,7 @@ class CallbackBase:
|
||||||
self._display.warning(warning)
|
self._display.warning(warning)
|
||||||
if 'deprecations' in res and res['deprecations']:
|
if 'deprecations' in res and res['deprecations']:
|
||||||
for warning in res['deprecations']:
|
for warning in res['deprecations']:
|
||||||
self._display.deprecated(warning)
|
self._display.deprecated(**warning)
|
||||||
|
|
||||||
def _get_diff(self, difflist):
|
def _get_diff(self, difflist):
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue