@ -36,7 +36,6 @@ from ansible.module_utils.basic import env_fallback
from ansible . module_utils . connection import Connection , ConnectionError
from ansible . module_utils . connection import Connection , ConnectionError
from ansible . module_utils . network . common . config import NetworkConfig , dumps
from ansible . module_utils . network . common . config import NetworkConfig , dumps
from ansible . module_utils . network . common . utils import to_list , ComplexList
from ansible . module_utils . network . common . utils import to_list , ComplexList
from ansible . module_utils . six import iteritems
from ansible . module_utils . urls import fetch_url
from ansible . module_utils . urls import fetch_url
_DEVICE_CONNECTION = None
_DEVICE_CONNECTION = None
@ -61,41 +60,15 @@ eos_provider_spec = {
eos_argument_spec = {
eos_argument_spec = {
' provider ' : dict ( type = ' dict ' , options = eos_provider_spec ) ,
' provider ' : dict ( type = ' dict ' , options = eos_provider_spec ) ,
}
}
eos_top_spec = {
' host ' : dict ( removed_in_version = 2.9 ) ,
' port ' : dict ( removed_in_version = 2.9 , type = ' int ' ) ,
' username ' : dict ( removed_in_version = 2.9 ) ,
' password ' : dict ( removed_in_version = 2.9 , no_log = True ) ,
' ssh_keyfile ' : dict ( removed_in_version = 2.9 , type = ' path ' ) ,
' authorize ' : dict ( fallback = ( env_fallback , [ ' ANSIBLE_NET_AUTHORIZE ' ] ) , type = ' bool ' ) ,
' auth_pass ' : dict ( removed_in_version = 2.9 , no_log = True ) ,
' use_ssl ' : dict ( removed_in_version = 2.9 , type = ' bool ' ) ,
' validate_certs ' : dict ( removed_in_version = 2.9 , type = ' bool ' ) ,
' timeout ' : dict ( removed_in_version = 2.9 , type = ' int ' ) ,
' transport ' : dict ( removed_in_version = 2.9 , choices = [ ' cli ' , ' eapi ' ] )
}
eos_argument_spec . update ( eos_top_spec )
def get_provider_argspec ( ) :
def get_provider_argspec ( ) :
return eos_provider_spec
return eos_provider_spec
def load_params ( module ) :
provider = module . params . get ( ' provider ' ) or dict ( )
for key , value in iteritems ( provider ) :
if key in eos_argument_spec :
if module . params . get ( key ) is None and value is not None :
module . params [ key ] = value
def get_connection ( module ) :
def get_connection ( module ) :
global _DEVICE_CONNECTION
global _DEVICE_CONNECTION
if not _DEVICE_CONNECTION :
if not _DEVICE_CONNECTION :
load_params ( module )
if is_local_eapi ( module ) :
if is_local_eapi ( module ) :
conn = LocalEapi ( module )
conn = LocalEapi ( module )
else :
else :
@ -210,23 +183,24 @@ class LocalEapi:
self . _session_support = None
self . _session_support = None
self . _device_configs = { }
self . _device_configs = { }
host = module . params [ ' provider ' ] [ ' host ' ]
provider = module . params . get ( " provider " ) or { }
port = module . params [ ' provider ' ] [ ' port ' ]
host = provider . get ( ' host ' )
port = provider . get ( ' port ' )
self . _module . params [ ' url_username ' ] = self . _module . params [ ' username ' ]
self . _module . params [ ' url_username ' ] = provider . get ( ' username ' )
self . _module . params [ ' url_password ' ] = self . _module . params [ ' password ' ]
self . _module . params [ ' url_password ' ] = provider . get ( ' password ' )
if module. params [ ' provider ' ] [ ' use_ssl ' ] :
if provider. get ( ' use_ssl ' ) :
proto = ' https '
proto = ' https '
else :
else :
proto = ' http '
proto = ' http '
module . params [ ' validate_certs ' ] = module. params [ ' provider ' ] [ ' validate_certs ' ]
module . params [ ' validate_certs ' ] = provider. get ( ' validate_certs ' )
self . _url = ' %s :// %s : %s /command-api ' % ( proto , host , port )
self . _url = ' %s :// %s : %s /command-api ' % ( proto , host , port )
if module. params [ ' auth_pass ' ] :
if provider. get ( " auth_pass " ) :
self . _enable = { ' cmd ' : ' enable ' , ' input ' : module. params [ ' auth_pass ' ] }
self . _enable = { ' cmd ' : ' enable ' , ' input ' : provider. get ( ' auth_pass ' ) }
else :
else :
self . _enable = ' enable '
self . _enable = ' enable '
@ -251,7 +225,7 @@ class LocalEapi:
data = self . _module . jsonify ( body )
data = self . _module . jsonify ( body )
headers = { ' Content-Type ' : ' application/json-rpc ' }
headers = { ' Content-Type ' : ' application/json-rpc ' }
timeout = self . _module . params [ ' timeout' ]
timeout = self . _module . params [ ' provider' ] [ ' timeout' ]
use_proxy = self . _module . params [ ' provider ' ] [ ' use_proxy ' ]
use_proxy = self . _module . params [ ' provider ' ] [ ' use_proxy ' ]
response , headers = fetch_url (
response , headers = fetch_url (
@ -595,12 +569,10 @@ def is_json(cmd):
def is_local_eapi ( module ) :
def is_local_eapi ( module ) :
transports = [ ]
transports . append ( module . params . get ( ' transport ' , " " ) )
provider = module . params . get ( ' provider ' )
provider = module . params . get ( ' provider ' )
if provider :
if provider :
transports . append ( provider . get ( ' transport ' , " " ) )
return provider . get ( ' transport ' ) == ' eapi '
return ' eapi ' in transports
return False
def to_command ( module , commands ) :
def to_command ( module , commands ) :