def test_csv_write(self): print('\n**** Testing writing CSV file ***') # Test that the output CSV is correct util.write_devices_info(csv_test_output_filename, csv_test_devices_list) self.assertTrue(filecmp.cmp(csv_test_input_filename, csv_test_output_filename), "Failed CSV write")
def test_csv_write(self): print '\n**** Testing writing CSV file ***' # Test that the output CSV is correct util.write_devices_info(csv_test_output_filename, csv_test_devices_list) self.assertTrue(filecmp.cmp(csv_test_input_filename, csv_test_output_filename), "Failed CSV write")
devices_list = read_devices_info( 'json-devices') # read JSON info for all devices for device in devices_list: print( '==== Device =============================================================' ) device.connect() # connect to this specific device device.get_interfaces() # get interface info for this specific device print_device_info(device) # print device details for this device write_devices_info('json-devices-out', devices_list) # write JSON entry for all devices # Do it again, reading from our output file, to prove we did it correctly print( '-----------------------------------------------------------------------------' ) print( '---------- Reading from our output file, doing it again ---------------------' ) devices_list = read_devices_info( 'json-devices-out') # read JSON info for all devices for device in devices_list:
#==================================================================== # Main program: connect to device, show interface, display devices_list = read_devices_info('json-devices') # read JSON info for all devices for device in devices_list: print '==== Device =============================================================' device.connect() # connect to this specific device device.get_interfaces() # get interface info for this specific device print_device_info(device) # print device details for this device write_devices_info('json-devices-out', devices_list) # write JSON entry for all devices # Do it again, reading from our output file, to prove we did it correctly print '-----------------------------------------------------------------------------' print '---------- Reading from our output file, doing it again ---------------------' devices_list = read_devices_info('json-devices-out') # read JSON info for all devices for device in devices_list: print '==== Device =============================================================' device.connect() # connect to this specific device device.get_interfaces() # get interface info for this specific device
#---- Get interfaces from device ---------------------------------- def get_interfaces(self): self.session.sendline('show interface brief') result = self.session.expect('#') self.interfaces = self.session.before #File: main.py from util import read_devices_info from util import print_device_info from util import write_devices_info #==================================================================== # Main program: connect to device, show interface, display devices_list = read_devices_info('csv-devices') # read CSV info for all devices for device in devices_list: print '==== Device =============================================================' device.connect() # connect to this specific device device.get_interfaces() # get interface info for this specific device print_device_info(device) # print device details for this device write_devices_info('csv-devices-out', devices_list) # write CSV entry for all devices