add provider to iosxr shared module
This commit adds a new argument `provider` to the iosxr shared module that allows common connection parameters to be passed as a dict object. The constraints on the args still applies. This commit also updates the iosxr doc fragment.
This commit is contained in:
parent
7640eca368
commit
0f2917fde3
2 changed files with 21 additions and 13 deletions
|
@ -23,7 +23,8 @@ NET_COMMON_ARGS = dict(
|
||||||
host=dict(required=True),
|
host=dict(required=True),
|
||||||
port=dict(default=22, type='int'),
|
port=dict(default=22, type='int'),
|
||||||
username=dict(required=True),
|
username=dict(required=True),
|
||||||
password=dict(no_log=True)
|
password=dict(no_log=True),
|
||||||
|
provider=dict()
|
||||||
)
|
)
|
||||||
|
|
||||||
def to_list(val):
|
def to_list(val):
|
||||||
|
@ -53,10 +54,10 @@ class Cli(object):
|
||||||
def send(self, commands):
|
def send(self, commands):
|
||||||
return self.shell.send(commands)
|
return self.shell.send(commands)
|
||||||
|
|
||||||
class IosxrModule(AnsibleModule):
|
class NetworkModule(AnsibleModule):
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(IosxrModule, self).__init__(*args, **kwargs)
|
super(NetworkModule, self).__init__(*args, **kwargs)
|
||||||
self.connection = None
|
self.connection = None
|
||||||
self._config = None
|
self._config = None
|
||||||
|
|
||||||
|
@ -66,6 +67,14 @@ class IosxrModule(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)
|
||||||
|
@ -96,26 +105,18 @@ class IosxrModule(AnsibleModule):
|
||||||
return self.execute('show running-config')[0]
|
return self.execute('show running-config')[0]
|
||||||
|
|
||||||
def get_module(**kwargs):
|
def get_module(**kwargs):
|
||||||
"""Return instance of IosxrModule
|
"""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 = IosxrModule(**kwargs)
|
module = NetworkModule(**kwargs)
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
|
|
|
@ -48,5 +48,12 @@ options:
|
||||||
the SSH session
|
the SSH session
|
||||||
required: false
|
required: false
|
||||||
default: null
|
default: null
|
||||||
|
provider:
|
||||||
|
description:
|
||||||
|
- Convience method that allows all M(iosxr) 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…
Reference in a new issue