@ -28,16 +28,13 @@
# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
#
import os
import os
import re
import time
import time
from ansible . module_utils . basic import env_fallback , get_exception
from ansible . module_utils . basic import env_fallback
from ansible . module_utils . network_common import to_list
from ansible . module_utils . connection import exec_command
from ansible . module_utils . net cli import Command
from ansible . module_utils . net work_common import to_list , ComplexList
from ansible . module_utils . six import iteritems
from ansible . module_utils . six import iteritems
from ansible . module_utils . network import NetworkError
from ansible . module_utils . urls import fetch_url
from ansible . module_utils . urls import fetch_url
from ansible . module_utils . connection import exec_command
_DEVICE_CONNECTION = None
_DEVICE_CONNECTION = None
@ -57,7 +54,7 @@ eos_argument_spec = {
' validate_certs ' : dict ( type = ' bool ' ) ,
' validate_certs ' : dict ( type = ' bool ' ) ,
' timeout ' : dict ( type = ' int ' ) ,
' timeout ' : dict ( type = ' int ' ) ,
' provider ' : dict ( type = ' dict ' , no_log = True ),
' provider ' : dict ( type = ' dict ' ),
' transport ' : dict ( choices = [ ' cli ' , ' eapi ' ] )
' transport ' : dict ( choices = [ ' cli ' , ' eapi ' ] )
}
}
@ -225,7 +222,7 @@ class Cli:
self . _module . fail_json ( msg = err , commands = commands )
self . _module . fail_json ( msg = err , commands = commands )
rc , out , err = self . exec_command ( ' show session-config diffs ' )
rc , out , err = self . exec_command ( ' show session-config diffs ' )
if rc == 0 :
if rc == 0 and out :
result [ ' diff ' ] = out . strip ( )
result [ ' diff ' ] = out . strip ( )
if commit :
if commit :
@ -327,7 +324,7 @@ class Eapi:
item [ ' command ' ] = str ( item [ ' command ' ] ) . replace ( ' | json ' , ' ' )
item [ ' command ' ] = str ( item [ ' command ' ] ) . replace ( ' | json ' , ' ' )
item [ ' output ' ] == ' json '
item [ ' output ' ] == ' json '
if output != item [ ' output ' ] :
if output and output != item [ ' output ' ] :
responses . extend ( _send ( queue , output ) )
responses . extend ( _send ( queue , output ) )
queue = list ( )
queue = list ( )
@ -407,7 +404,7 @@ class Eapi:
response = self . send_request ( commands , output = ' text ' )
response = self . send_request ( commands , output = ' text ' )
diff = response [ ' result ' ] [ 1 ] [ ' output ' ]
diff = response [ ' result ' ] [ 1 ] [ ' output ' ]
if diff :
if len ( diff ) > 0 :
result [ ' diff ' ] = diff
result [ ' diff ' ] = diff
return result
return result
@ -417,13 +414,41 @@ is_text = lambda x: not str(x).endswith('| json')
supports_sessions = lambda x : get_connection ( module ) . supports_sessions
supports_sessions = lambda x : get_connection ( module ) . supports_sessions
def is_eapi ( module ) :
transport = module . params [ ' transport ' ]
provider_transport = ( module . params [ ' provider ' ] or { } ) . get ( ' transport ' )
return ' eapi ' in ( transport , provider_transport )
def to_command ( module , commands ) :
if is_eapi ( module ) :
default_output = ' json '
else :
default_output = ' text '
transform = ComplexList ( dict (
command = dict ( key = True ) ,
output = dict ( default = default_output ) ,
prompt = dict ( ) ,
answer = dict ( )
) , module )
commands = transform ( to_list ( commands ) )
for index , item in enumerate ( commands ) :
if is_json ( item [ ' command ' ] ) :
item [ ' output ' ] = ' json '
elif is_text ( item [ ' command ' ] ) :
item [ ' output ' ] = ' text '
return commands
def get_config ( module , flags = [ ] ) :
def get_config ( module , flags = [ ] ) :
conn = get_connection ( module )
conn = get_connection ( module )
return conn . get_config ( flags )
return conn . get_config ( flags )
def run_commands ( module , commands ) :
def run_commands ( module , commands ) :
conn = get_connection ( module )
conn = get_connection ( module )
return conn . run_commands ( commands )
return conn . run_commands ( to_command( module , commands) )
def load_config ( module , config , commit = False , replace = False ) :
def load_config ( module , config , commit = False , replace = False ) :
conn = get_connection ( module )
conn = get_connection ( module )