mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-08-22 22:11:44 -07:00
Fix unwanted deprecation message in network module args (#28984)
* Fix unwanted deprecation message in network module argspec Fixes #25663 Fixes #24537 * segregate provider spec and top level arg spec * add deprecation key in top level arg spec * remove action plugin code to load provider and add that logic at a common place in network_common.py file * Fix CI issue * Minor change
This commit is contained in:
parent
d52316fcc2
commit
599fe23ed6
30 changed files with 283 additions and 634 deletions
|
@ -22,8 +22,7 @@ import copy
|
|||
|
||||
from ansible import constants as C
|
||||
from ansible.plugins.action import ActionBase
|
||||
from ansible.module_utils.basic import AnsibleFallbackNotFound
|
||||
from ansible.module_utils.six import iteritems
|
||||
from ansible.module_utils.network_common import load_provider
|
||||
|
||||
from imp import find_module, load_module
|
||||
|
||||
|
@ -47,7 +46,16 @@ class ActionModule(ActionBase):
|
|||
play_context = copy.deepcopy(self._play_context)
|
||||
play_context.network_os = self._get_network_os(task_vars)
|
||||
|
||||
self.provider = self._load_provider(play_context.network_os)
|
||||
# we should be able to stream line this a bit by creating a common
|
||||
# provider argument spec in module_utils/network_common.py or another
|
||||
# option is that there isn't a need to push provider into the module
|
||||
# since the connection is started in the action handler.
|
||||
f, p, d = find_module('ansible')
|
||||
f2, p2, d2 = find_module('module_utils', [p])
|
||||
f3, p3, d3 = find_module(play_context.network_os, [p2])
|
||||
module = load_module('ansible.module_utils.' + play_context.network_os, f3, p3, d3)
|
||||
|
||||
self.provider = load_provider(module.get_provider_argspec(), self._task.args)
|
||||
|
||||
if play_context.network_os == 'junos':
|
||||
play_context.connection = 'netconf'
|
||||
|
@ -154,39 +162,3 @@ class ActionModule(ActionBase):
|
|||
implementation_module = None
|
||||
|
||||
return implementation_module
|
||||
|
||||
def _load_provider(self, network_os):
|
||||
# we should be able to stream line this a bit by creating a common
|
||||
# provider argument spec in module_utils/network_common.py or another
|
||||
# option is that there isn't a need to push provider into the module
|
||||
# since the connection is started in the action handler.
|
||||
f, p, d = find_module('ansible')
|
||||
f2, p2, d2 = find_module('module_utils', [p])
|
||||
f3, p3, d3 = find_module(network_os, [p2])
|
||||
module = load_module('ansible.module_utils.' + network_os, f3, p3, d3)
|
||||
|
||||
provider = self._task.args.get('provider', {})
|
||||
for key, value in iteritems(module.get_argspec()):
|
||||
if key != 'provider' and key not in provider:
|
||||
if key in self._task.args:
|
||||
provider[key] = self._task.args[key]
|
||||
elif 'fallback' in value:
|
||||
provider[key] = self._fallback(value['fallback'])
|
||||
elif key not in provider:
|
||||
provider[key] = None
|
||||
return provider
|
||||
|
||||
def _fallback(self, fallback):
|
||||
strategy = fallback[0]
|
||||
args = []
|
||||
kwargs = {}
|
||||
|
||||
for item in fallback[1:]:
|
||||
if isinstance(item, dict):
|
||||
kwargs = item
|
||||
else:
|
||||
args = item
|
||||
try:
|
||||
return strategy(*args, **kwargs)
|
||||
except AnsibleFallbackNotFound:
|
||||
pass
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue