@ -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 N xos Module( AnsibleModule ) :
class N etwork Module( AnsibleModule ) :
def __init__ ( self , * args , * * kwargs ) :
super ( N xos Module, self ) . __init__ ( * args , * * kwargs )
super ( N etwork Module, 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 N xos Module
""" Return instance of N etwork Module
"""
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 = N xos Module( * * kwargs )
module = N etwork Module( * * 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