#NEWLINE# def connect( host , user , password ) : #NEWLINE# #INDENT# with manager . connect ( host = host , port = 22 , username = user , password = password , timeout = 10 , device_params = { #NEWLINE# #INDENT# 'name' : 'junos' , #NEWLINE# #UNINDENT# } , hostkey_verify = False ) as conn : #NEWLINE# #INDENT# vpns = conn . command ( 'show l2circuit connections' ) . xpath ( 'l2circuit-connection-information/l2circuit-neighbor' ) #NEWLINE# connection_dict = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for vpn in vpns : #NEWLINE# #INDENT# neighbor = '' #NEWLINE# for tag in vpn . getchildren ( ) : #NEWLINE# #INDENT# connection_details_dict = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# if ( tag . tag == 'neighbor-address' ) : #NEWLINE# #INDENT# neighbor = tag . text #NEWLINE# #UNINDENT# if ( tag . tag == 'connection' ) : #NEWLINE# #INDENT# for child in tag . getchildren ( ) : #NEWLINE# #INDENT# if ( child . tag == 'local-interface' ) : #NEWLINE# #INDENT# ifce = child . find ( 'interface-name' ) . text #NEWLINE# connection_details_dict . update ( { #NEWLINE# #INDENT# 'interface' : ifce , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( child . tag == 'connection-id' ) : #NEWLINE# #INDENT# cid = child . text #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# connection_details_dict . update ( { #NEWLINE# #INDENT# child . tag : child . text , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# connection_details_dict . update ( { #NEWLINE# #INDENT# 'neighbor' : neighbor , #NEWLINE# #UNINDENT# } ) #NEWLINE# if connection_dict . get ( cid ) : #NEWLINE# #INDENT# connection_dict . get ( cid ) . append ( connection_details_dict ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# connection_dict . update ( { #NEWLINE# #INDENT# cid : [ connection_details_dict ] , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# return connection_dict