#NEWLINE# def run( self ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# device = ciscolib . Device ( self . host , PASSWORD ) #NEWLINE# device . connect ( ) #NEWLINE# #UNINDENT# except ciscolib . AuthenticationError : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# device = ciscolib . Device ( self . host , USER_PASSWORD , USERNAME ) #NEWLINE# device . connect ( ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# print ( ( 'Unable to connect to %s' % self . host ) ) #NEWLINE# return #NEWLINE# #UNINDENT# #UNINDENT# except : #NEWLINE# #INDENT# print ( ( 'Unable to connect to %s' % self . host ) ) #NEWLINE# return #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# model = device . get_model ( ) #NEWLINE# #UNINDENT# except ciscolib . ModelNotSupported : #NEWLINE# #INDENT# print ( ( '!! Model of %s is not supported!' % self . host ) ) #NEWLINE# return #NEWLINE# #UNINDENT# if ( interfaces in models ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# with models_lock : #NEWLINE# #INDENT# models . append ( model ) #NEWLINE# #UNINDENT# #UNINDENT# output_dir = ( 'fixtures/%s/' % model ) #NEWLINE# try : #NEWLINE# #INDENT# os . mkdir ( output_dir ) #NEWLINE# #UNINDENT# except OSError as e : #NEWLINE# #INDENT# if ( e . errno != 17 ) : #NEWLINE# #INDENT# print ( ( '!! Unable to create model directory %s' % output_dir ) ) #NEWLINE# return #NEWLINE# #UNINDENT# #UNINDENT# open ( ( output_dir + 'show_int_status.txt' ) , 'w' ) . write ( device . cmd ( 'show int status' ) ) #NEWLINE# open ( ( output_dir + 'show_cdp_neighbors_detail.txt' ) , 'w' ) . write ( device . cmd ( 'show cdp neighbors detail' ) ) #NEWLINE# open ( ( output_dir + 'show_version.txt' ) , 'w' ) . write ( device . cmd ( 'show version' ) ) #NEWLINE# open ( ( output_dir + 'show_arp.txt' ) , 'w' ) . write ( device . cmd ( 'show arp' ) ) #NEWLINE# mac_data = '' #NEWLINE# mac_cmd = '' #NEWLINE# try : #NEWLINE# #INDENT# mac_cmd = 'show mac-address-table' #NEWLINE# mac_data = device . cmd ( mac_cmd ) #NEWLINE# #UNINDENT# except ciscolib . InvalidCommand : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# mac_cmd = 'show mac address-table' #NEWLINE# mac_data = device . cmd ( mac_cmd ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# print ( ( '!! Unable to get mac data for %s' % self . host ) ) #NEWLINE# #UNINDENT# #UNINDENT# if ( mac_data != '' ) : #NEWLINE# #INDENT# open ( ( ( output_dir + mac_cmd . replace ( ' ' , '_' ) ) + '.txt' ) , 'w' ) . write ( mac_data ) #NEWLINE# #UNINDENT# interfaces_re = '((?:\\w+|-|/!)+\\d+(?:/\\d+)*) is (?:up|down)' #NEWLINE# interfaces = device . cmd ( 'show interfaces' ) #NEWLINE# open ( ( output_dir + 'show_interfaces.txt' ) , 'w' ) . write ( interfaces ) #NEWLINE# for result in re . findall ( interfaces_re , interfaces ) : #NEWLINE# #INDENT# filename = ( 'show_interface_%s_status.txt' % result ) #NEWLINE# filename = filename . replace ( '/' , '+' ) #NEWLINE# open ( ( output_dir + filename ) , 'w' ) . write ( device . cmd ( ( 'show interface %s status' % result ) ) )