1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

adds provider argument to nxos shared module

The provider argument accepts the set of device common arguments as a
dict object.  Individual connection arguments can still be included and
take priority over the provider argument.  This update includes additions
to the nxos doc fragment
This commit is contained in:
Peter Sprygada 2016-01-19 08:38:38 -05:00
parent 9cba1a7c69
commit 981265ac84
2 changed files with 21 additions and 13 deletions

View file

@ -24,7 +24,8 @@ NET_COMMON_ARGS = dict(
username=dict(required=True),
password=dict(no_log=True),
transport=dict(choices=['cli', 'nxapi']),
use_ssl=dict(default=False, type='bool')
use_ssl=dict(default=False, type='bool'),
provider=dict()
)
NXAPI_COMMAND_TYPES = ['cli_show', 'cli_show_ascii', 'cli_conf', 'bash']
@ -131,10 +132,10 @@ class Cli(object):
def send(self, commands, encoding='text'):
return self.shell.send(commands)
class NxosModule(AnsibleModule):
class NetworkModule(AnsibleModule):
def __init__(self, *args, **kwargs):
super(NxosModule, self).__init__(*args, **kwargs)
super(NetworkModule, self).__init__(*args, **kwargs)
self.connection = None
self._config = None
@ -144,6 +145,14 @@ class NxosModule(AnsibleModule):
self._config = self.get_config()
return self._config
def _load_params(self):
params = super(NetworkModule, self)._load_params()
provider = params.get('provider') or dict()
for key, value in provider.items():
if key in NET_COMMON_ARGS.keys():
params[key] = value
return params
def connect(self):
if self.params['transport'] == 'nxapi':
self.connection = Nxapi(self)
@ -191,26 +200,18 @@ class NxosModule(AnsibleModule):
return resp['ins_api']['outputs']['output']['body']
def get_module(**kwargs):
"""Return instance of NxosModule
"""Return instance of NetworkModule
"""
argument_spec = NET_COMMON_ARGS.copy()
if kwargs.get('argument_spec'):
argument_spec.update(kwargs['argument_spec'])
kwargs['argument_spec'] = argument_spec
kwargs['check_invalid_arguments'] = False
module = NxosModule(**kwargs)
module = NetworkModule(**kwargs)
# HAS_PARAMIKO is set by module_utils/shell.py
if module.params['transport'] == 'cli' and not HAS_PARAMIKO:
module.fail_json(msg='paramiko is required but does not appear to be installed')
# copy in values from local action.
params = json_dict_unicode_to_bytes(json.loads(MODULE_COMPLEX_ARGS))
for key, value in params.iteritems():
module.params[key] = value
module.connect()
return module

View file

@ -65,5 +65,12 @@ options:
required: false
default: false
choices: BOOLEANS
provider:
description:
- Convience method that allows all M(nxos) arguments to be passed as
a dict object. All constraints (required, choices, etc) must be
met either by individual arguments or values in this dict.
required: false
default: null
"""