adds provider argument to ios shared module

New argument `provider` added to the ios shared module that provides
the ability to pass all of the common ios arguments as a dict.  This commit
includes some minor bugfixes and refactoring of names.   It also includes
udpates to the ios documentation fragment for the new argument
pull/14009/head
Peter Sprygada 9 years ago
parent e2ff26a5cf
commit 9cba1a7c69

@ -26,6 +26,7 @@ NET_COMMON_ARGS = dict(
password=dict(no_log=True), password=dict(no_log=True),
authorize=dict(default=False, type='bool'), authorize=dict(default=False, type='bool'),
auth_pass=dict(no_log=True), auth_pass=dict(no_log=True),
provider=dict()
) )
def to_list(val): def to_list(val):
@ -59,10 +60,10 @@ class Cli(object):
def send(self, commands): def send(self, commands):
return self.shell.send(commands) return self.shell.send(commands)
class IosModule(AnsibleModule): class NetworkModule(AnsibleModule):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(IosModule, self).__init__(*args, **kwargs) super(NetworkModule, self).__init__(*args, **kwargs)
self.connection = None self.connection = None
self._config = None self._config = None
@ -72,6 +73,14 @@ class IosModule(AnsibleModule):
self._config = self.get_config() self._config = self.get_config()
return self._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): def connect(self):
try: try:
self.connection = Cli(self) self.connection = Cli(self)
@ -107,27 +116,19 @@ class IosModule(AnsibleModule):
return self.execute(cmd)[0] return self.execute(cmd)[0]
def get_module(**kwargs): def get_module(**kwargs):
"""Return instance of IosModule """Return instance of NetworkModule
""" """
argument_spec = NET_COMMON_ARGS.copy() argument_spec = NET_COMMON_ARGS.copy()
if kwargs.get('argument_spec'): if kwargs.get('argument_spec'):
argument_spec.update(kwargs['argument_spec']) argument_spec.update(kwargs['argument_spec'])
kwargs['argument_spec'] = argument_spec kwargs['argument_spec'] = argument_spec
kwargs['check_invalid_arguments'] = False
module = IosModule(**kwargs) module = NetworkModule(**kwargs)
# HAS_PARAMIKO is set by module_utils/shell.py # HAS_PARAMIKO is set by module_utils/shell.py
if not HAS_PARAMIKO: if not HAS_PARAMIKO:
module.fail_json(msg='paramiko is required but does not appear to be installed') 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() module.connect()
return module return module

@ -63,5 +63,12 @@ options:
does nothing does nothing
required: false required: false
default: none default: none
provider:
description:
- Convience method that allows all M(ios) 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
""" """

Loading…
Cancel
Save