mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-10-24 13:04:00 -07:00
Bump version of main to 12.0.0; execute announced deprecations (#10883)
* Bump version to 12.0.0. * Remove deprecated modules and plugins. * state is now required. * Change default of prepend_hash from auto to never. * Remove support for force=''. * Always delegate 'debug'. * Remove ignore_value_none and ctx_ignore_none parameters. * Remove parameters on_success and on_failure. * Update BOTMETA. * Adjust docs reference. * Forgot required=True. * Fix changelog fragment. * Adjust unit tests. * Fix changelog. Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com> --------- Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
This commit is contained in:
parent
f34842b7b2
commit
0b72737cab
22 changed files with 43 additions and 901 deletions
|
|
@ -132,16 +132,7 @@ class CmdRunner(object):
|
|||
def binary(self):
|
||||
return self.command[0]
|
||||
|
||||
# remove parameter ignore_value_none in community.general 12.0.0
|
||||
def __call__(self, args_order=None, output_process=None, ignore_value_none=None, check_mode_skip=False, check_mode_return=None, **kwargs):
|
||||
if ignore_value_none is None:
|
||||
ignore_value_none = True
|
||||
else:
|
||||
self.module.deprecate(
|
||||
"Using ignore_value_none when creating the runner context is now deprecated, "
|
||||
"and the parameter will be removed in community.general 12.0.0. ",
|
||||
version="12.0.0", collection_name="community.general"
|
||||
)
|
||||
def __call__(self, args_order=None, output_process=None, check_mode_skip=False, check_mode_return=None, **kwargs):
|
||||
if output_process is None:
|
||||
output_process = _process_as_is
|
||||
if args_order is None:
|
||||
|
|
@ -153,7 +144,6 @@ class CmdRunner(object):
|
|||
return _CmdRunnerContext(runner=self,
|
||||
args_order=args_order,
|
||||
output_process=output_process,
|
||||
ignore_value_none=ignore_value_none, # DEPRECATION: remove in community.general 12.0.0
|
||||
check_mode_skip=check_mode_skip,
|
||||
check_mode_return=check_mode_return, **kwargs)
|
||||
|
||||
|
|
@ -165,12 +155,10 @@ class CmdRunner(object):
|
|||
|
||||
|
||||
class _CmdRunnerContext(object):
|
||||
def __init__(self, runner, args_order, output_process, ignore_value_none, check_mode_skip, check_mode_return, **kwargs):
|
||||
def __init__(self, runner, args_order, output_process, check_mode_skip, check_mode_return, **kwargs):
|
||||
self.runner = runner
|
||||
self.args_order = tuple(args_order)
|
||||
self.output_process = output_process
|
||||
# DEPRECATION: parameter ignore_value_none at the context level is deprecated and will be removed in community.general 12.0.0
|
||||
self.ignore_value_none = ignore_value_none
|
||||
self.check_mode_skip = check_mode_skip
|
||||
self.check_mode_return = check_mode_return
|
||||
self.run_command_args = dict(kwargs)
|
||||
|
|
@ -209,8 +197,7 @@ class _CmdRunnerContext(object):
|
|||
value = named_args[arg_name]
|
||||
elif not runner.arg_formats[arg_name].ignore_missing_value:
|
||||
raise MissingArgumentValue(self.args_order, arg_name)
|
||||
# DEPRECATION: remove parameter ctx_ignore_none in 12.0.0
|
||||
self.cmd.extend(runner.arg_formats[arg_name](value, ctx_ignore_none=self.ignore_value_none))
|
||||
self.cmd.extend(runner.arg_formats[arg_name](value))
|
||||
except MissingArgumentValue:
|
||||
raise
|
||||
except Exception as e:
|
||||
|
|
@ -226,7 +213,6 @@ class _CmdRunnerContext(object):
|
|||
@property
|
||||
def run_info(self):
|
||||
return dict(
|
||||
ignore_value_none=self.ignore_value_none, # DEPRECATION: remove in community.general 12.0.0
|
||||
check_rc=self.check_rc,
|
||||
environ_update=self.environ_update,
|
||||
args_order=self.args_order,
|
||||
|
|
|
|||
|
|
@ -16,16 +16,13 @@ def _ensure_list(value):
|
|||
|
||||
|
||||
class _ArgFormat(object):
|
||||
# DEPRECATION: set default value for ignore_none to True in community.general 12.0.0
|
||||
def __init__(self, func, ignore_none=None, ignore_missing_value=False):
|
||||
def __init__(self, func, ignore_none=True, ignore_missing_value=False):
|
||||
self.func = func
|
||||
self.ignore_none = ignore_none
|
||||
self.ignore_missing_value = ignore_missing_value
|
||||
|
||||
# DEPRECATION: remove parameter ctx_ignore_none in community.general 12.0.0
|
||||
def __call__(self, value, ctx_ignore_none=True):
|
||||
# DEPRECATION: replace ctx_ignore_none with True in community.general 12.0.0
|
||||
ignore_none = self.ignore_none if self.ignore_none is not None else ctx_ignore_none
|
||||
def __call__(self, value):
|
||||
ignore_none = self.ignore_none if self.ignore_none is not None else True
|
||||
if value is None and ignore_none:
|
||||
return []
|
||||
f = self.func
|
||||
|
|
|
|||
|
|
@ -15,9 +15,8 @@ from ansible_collections.community.general.plugins.module_utils.mh.deco import m
|
|||
class ModuleHelperBase(object):
|
||||
module = None
|
||||
ModuleHelperException = _MHE
|
||||
# in 12.0.0 add 'debug' to the tuple
|
||||
_delegated_to_module = (
|
||||
'check_mode', 'get_bin_path', 'warn', 'deprecate',
|
||||
'check_mode', 'get_bin_path', 'warn', 'deprecate', 'debug',
|
||||
)
|
||||
|
||||
def __init__(self, module=None):
|
||||
|
|
@ -29,18 +28,6 @@ class ModuleHelperBase(object):
|
|||
if not isinstance(self.module, AnsibleModule):
|
||||
self.module = AnsibleModule(**self.module)
|
||||
|
||||
# in 12.0.0 remove this if statement entirely
|
||||
if hasattr(self, 'debug'):
|
||||
msg = (
|
||||
"This class ({cls}) has an attribute 'debug' defined and that is deprecated. "
|
||||
"Method 'debug' will be an integral part of ModuleHelper in community.general "
|
||||
"12.0.0, delegated to the underlying AnsibleModule object. "
|
||||
"Please rename the existing attribute to prevent this message from showing.".format(cls=self.__class__.__name__)
|
||||
)
|
||||
self.deprecate(msg, version="12.0.0", collection_name="community.general")
|
||||
else:
|
||||
self._delegated_to_module = self._delegated_to_module + ('debug',)
|
||||
|
||||
@property
|
||||
def diff_mode(self):
|
||||
return self.module._diff
|
||||
|
|
|
|||
|
|
@ -13,22 +13,16 @@ from functools import wraps
|
|||
from ansible_collections.community.general.plugins.module_utils.mh.exceptions import ModuleHelperException
|
||||
|
||||
|
||||
def cause_changes(on_success=None, on_failure=None, when=None):
|
||||
# Parameters on_success and on_failure are deprecated and should be removed in community.general 12.0.0
|
||||
|
||||
def cause_changes(when=None):
|
||||
def deco(func):
|
||||
@wraps(func)
|
||||
def wrapper(self, *args, **kwargs):
|
||||
try:
|
||||
func(self, *args, **kwargs)
|
||||
if on_success is not None:
|
||||
self.changed = on_success
|
||||
elif when == "success":
|
||||
if when == "success":
|
||||
self.changed = True
|
||||
except Exception:
|
||||
if on_failure is not None:
|
||||
self.changed = on_failure
|
||||
elif when == "failure":
|
||||
if when == "failure":
|
||||
self.changed = True
|
||||
raise
|
||||
finally:
|
||||
|
|
|
|||
|
|
@ -1,115 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# This code is part of Ansible, but is an independent component.
|
||||
# This particular file snippet, and this file snippet only, is BSD licensed.
|
||||
# Modules you write using this snippet, which is embedded dynamically by Ansible
|
||||
# still belong to the author of the module, and may assign their own license
|
||||
# to the complete work.
|
||||
#
|
||||
# Copyright (c), Simon Dodsley <simon@purestorage.com>,2017
|
||||
# Simplified BSD License (see LICENSES/BSD-2-Clause.txt or https://opensource.org/licenses/BSD-2-Clause)
|
||||
# SPDX-License-Identifier: BSD-2-Clause
|
||||
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
HAS_PURESTORAGE = True
|
||||
try:
|
||||
from purestorage import purestorage
|
||||
except ImportError:
|
||||
HAS_PURESTORAGE = False
|
||||
|
||||
HAS_PURITY_FB = True
|
||||
try:
|
||||
from purity_fb import PurityFb, FileSystem, FileSystemSnapshot, SnapshotSuffix, rest # noqa: F401, pylint: disable=unused-import
|
||||
except ImportError:
|
||||
HAS_PURITY_FB = False
|
||||
|
||||
# (TODO: remove next line!)
|
||||
from functools import wraps # noqa: F401, pylint: disable=unused-import
|
||||
from os import environ
|
||||
# (TODO: remove next line!)
|
||||
from os import path # noqa: F401, pylint: disable=unused-import
|
||||
import platform
|
||||
|
||||
VERSION = 1.2
|
||||
USER_AGENT_BASE = 'Ansible'
|
||||
API_AGENT_VERSION = 1.5
|
||||
|
||||
|
||||
def get_system(module):
|
||||
"""Return System Object or Fail"""
|
||||
user_agent = '%(base)s %(class)s/%(version)s (%(platform)s)' % {
|
||||
'base': USER_AGENT_BASE,
|
||||
'class': __name__,
|
||||
'version': VERSION,
|
||||
'platform': platform.platform()
|
||||
}
|
||||
array_name = module.params['fa_url']
|
||||
api = module.params['api_token']
|
||||
|
||||
if array_name and api:
|
||||
system = purestorage.FlashArray(array_name, api_token=api, user_agent=user_agent)
|
||||
elif environ.get('PUREFA_URL') and environ.get('PUREFA_API'):
|
||||
system = purestorage.FlashArray(environ.get('PUREFA_URL'), api_token=(environ.get('PUREFA_API')), user_agent=user_agent)
|
||||
else:
|
||||
module.fail_json(msg="You must set PUREFA_URL and PUREFA_API environment variables or the fa_url and api_token module arguments")
|
||||
try:
|
||||
system.get()
|
||||
except Exception:
|
||||
module.fail_json(msg="Pure Storage FlashArray authentication failed. Check your credentials")
|
||||
return system
|
||||
|
||||
|
||||
def get_blade(module):
|
||||
"""Return System Object or Fail"""
|
||||
user_agent = '%(base)s %(class)s/%(version)s (%(platform)s)' % {
|
||||
'base': USER_AGENT_BASE,
|
||||
'class': __name__,
|
||||
'version': VERSION,
|
||||
'platform': platform.platform()
|
||||
}
|
||||
blade_name = module.params['fb_url']
|
||||
api = module.params['api_token']
|
||||
|
||||
if blade_name and api:
|
||||
blade = PurityFb(blade_name)
|
||||
blade.disable_verify_ssl()
|
||||
try:
|
||||
blade.login(api)
|
||||
versions = blade.api_version.list_versions().versions
|
||||
if API_AGENT_VERSION in versions:
|
||||
blade._api_client.user_agent = user_agent
|
||||
except rest.ApiException as e:
|
||||
module.fail_json(msg="Pure Storage FlashBlade authentication failed. Check your credentials")
|
||||
elif environ.get('PUREFB_URL') and environ.get('PUREFB_API'):
|
||||
blade = PurityFb(environ.get('PUREFB_URL'))
|
||||
blade.disable_verify_ssl()
|
||||
try:
|
||||
blade.login(environ.get('PUREFB_API'))
|
||||
versions = blade.api_version.list_versions().versions
|
||||
if API_AGENT_VERSION in versions:
|
||||
blade._api_client.user_agent = user_agent
|
||||
except rest.ApiException as e:
|
||||
module.fail_json(msg="Pure Storage FlashBlade authentication failed. Check your credentials")
|
||||
else:
|
||||
module.fail_json(msg="You must set PUREFB_URL and PUREFB_API environment variables or the fb_url and api_token module arguments")
|
||||
return blade
|
||||
|
||||
|
||||
def purefa_argument_spec():
|
||||
"""Return standard base dictionary used for the argument_spec argument in AnsibleModule"""
|
||||
|
||||
return dict(
|
||||
fa_url=dict(),
|
||||
api_token=dict(no_log=True),
|
||||
)
|
||||
|
||||
|
||||
def purefb_argument_spec():
|
||||
"""Return standard base dictionary used for the argument_spec argument in AnsibleModule"""
|
||||
|
||||
return dict(
|
||||
fb_url=dict(),
|
||||
api_token=dict(no_log=True),
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue