<s> from interfaces import Interface <EOL> from ncclient import manager <EOL> import re <EOL> import sys <EOL> import xml . dom . minidom <EOL> HOST = '<STR_LIT>' <EOL> PORT = <NUM_LIT> <EOL> USER = '<STR_LIT:root>' <EOL> PASS = '<STR_LIT>' <EOL> FILE = '<STR_LIT>' <EOL> def get_interface_state ( host , port , user , passwd , filename ) : <EOL> """<STR_LIT>""" <EOL> with manager . connect ( host = host , port = port , username = user , password = passwd , <EOL> hostkey_verify = False , device_params = { '<STR_LIT:name>' : '<STR_LIT:default>' } , <EOL> allow_agent = False , look_for_keys = False ) as m : <EOL> with open ( filename ) as f : <EOL> try : <EOL> rpc_reply = m . edit_config ( target = '<STR_LIT>' , config = f . read ( ) ) <EOL> except Exception as e : <EOL> print ( "<STR_LIT>" ) <EOL> print ( e ) <EOL> sys . exit ( ) <EOL> if rpc_reply . ok is not True : <EOL> print ( "<STR_LIT>" ) <EOL> sys . exit ( ) <EOL> try : <EOL> rpc_reply = m . get ( filter = ( '<STR_LIT>' , "<STR_LIT>" ) ) <EOL> except Exception as e : <EOL> print ( "<STR_LIT>" ) <EOL> print ( e ) <EOL> sys . exit ( ) <EOL> if rpc_reply . ok is not True : <EOL> print ( "<STR_LIT>" ) <EOL> sys . exit ( ) <EOL> else : <EOL> return ( rpc_reply ) <EOL> def main ( ) : <EOL> """<STR_LIT>""" <EOL> list_interfaces = [ ] <EOL> result = get_interface_state ( HOST , PORT , USER , PASS , FILE ) <EOL> print ( xml . dom . minidom . parseString ( result . xml ) . toprettyxml ( ) ) <EOL> interfaces = xml . dom . minidom . parseString ( result . xml ) . getElementsByTagName ( '<STR_LIT>' ) <EOL> for each in interfaces : <EOL> if re . match ( '<STR_LIT>' , each . getElementsByTagName ( '<STR_LIT:name>' ) [ <NUM_LIT:0> ] . firstChild . nodeValue ) : <EOL> interface = Interface ( each . getElementsByTagName ( '<STR_LIT:name>' ) [ <NUM_LIT:0> ] . firstChild . nodeValue , <EOL> each . getElementsByTagName ( '<STR_LIT>' ) [ <NUM_LIT:0> ] . firstChild . nodeValue ) <EOL> list_interfaces . append ( interface ) <EOL> for each in list_interfaces : <EOL> each . prints ( ) <EOL> for each in list_interfaces : <EOL> each . check_down ( ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> sys . exit ( main ( ) ) </s>
