def test_csv_read(self): print '\n**** Testing reading CSV file ***' # Test that we can correctly read in CSV values csv_devices_list = util.read_devices_info(csv_test_input_filename) self.assertEqual(csv_devices_list, csv_test_devices_list, "Failed read device list")
def test_csv_read(self): print('\n**** Testing reading CSV file ***') # Test that we can correctly read in CSV values csv_devices_list = util.read_devices_info(csv_test_input_filename) self.assertEqual(csv_devices_list, csv_test_devices_list, "Failed read device list")
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( '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 ---------------------'
main.py import logging from util import read_devices_info from devclass import NetworkDeviceIOS #==================================================================== devices_filename = 'csv-devices' logging.basicConfig(filename='prne.log', format='%(asctime)s %(message)s', level=logging.INFO) devices_list_in = read_devices_info(devices_filename) # read CSV info for devices logging.info('main: read %s devices from %s', len(devices_list_in), devices_filename) # Iterate through all devices from the file, creating device objects for each devices_list = [] for device_in in devices_list_in: device = NetworkDeviceIOS(device_in[0], # Device name device_in[2], # Device IP address device_in[3], # Device username device_in[4]) # Device password logging.info('main: created device: %s IP: %s', device.name, device.ip_address) print '----- device: name: ',device.name,' IP: ',device.ip_address
#--- Set up logging -------------------- logger = logging.getLogger('main') logger.setLevel(logging.INFO) handler = logging.handlers.RotatingFileHandler('main.log', maxBytes=20000, backupCount=4) handler.setFormatter( logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')) logger.addHandler(handler) #--- Read in devices from file and put it in a Device List --------- devices_list_in = read_devices_info( devices_filename ) # read CSV info for all devices from the file "devices_filename" mentioned above logger.info('read %s devices from %s', len(devices_list_in), devices_filename) # Iterate through all devices from the file, creating device objects for each devices_list = [] for device_in in devices_list_in: device = NetworkDeviceIOS( device_in[0], # Device name device_in[2], # Device IP address device_in[3], # Device username device_in[4]) # Device password
devices_filename = 'csv-devices' #--- Set up logging -------------------- logger = logging.getLogger('main') logger.setLevel(logging.INFO) handler = logging.handlers.RotatingFileHandler('main.log', maxBytes=20000, backupCount=4) handler.setFormatter( logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')) logger.addHandler(handler) #--- Read in devices from file --------- devices_list_in = read_devices_info( devices_filename) # read CSV info for all devices logger.info('read %s devices from %s', len(devices_list_in), devices_filename) # Iterate through all devices from the file, creating device objects for each devices_list = [] for device_in in devices_list_in: device = NetworkDeviceIOS( device_in[0], # Device name device_in[2], # Device IP address device_in[3], # Device username device_in[4]) # Device password logger.info('created device: %s IP: %s', device.name, device.ip_address)
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('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 '-----------------------------------------------------------------------------'
self.session.expect('#') #---- 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
import util #==================================================================== # Main program: connect to device, show interface, display devices_list = util.read_devices_info('devices.txt') for device in devices_list: print( '==== Device =============================================================' ) device.connect() device.get_interfaces() util.print_device_info(device)
from util import read_devices_info from util import print_device_info #==================================================================== # Main program: connect to device, show interface, display devices_list = read_devices_info('sbx') for device in devices_list: print( '==== Device =============================================================' ) device.connect() device.get_interfaces() print_device_info(device)
#==================================================================== devices_filename = 'csv-devices' #--- Set up logging -------------------- logger = logging.getLogger('main') logger.setLevel(logging.INFO) handler = logging.handlers.RotatingFileHandler('main.log',maxBytes=20000,backupCount=4) handler.setFormatter(logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')) logger.addHandler(handler) #--- Read in devices from file and put it in a Device List --------- devices_list_in = read_devices_info(devices_filename) # read CSV info for all devices from the file "devices_filename" mentioned above logger.info('read %s devices from %s', len(devices_list_in), devices_filename) # Iterate through all devices from the file, creating device objects for each devices_list = [] for device_in in devices_list_in: device = NetworkDeviceIOS(device_in[0], # Device name device_in[2], # Device IP address device_in[3], # Device username device_in[4]) # Device password logger.info('created device: %s IP: %s', device.name, device.ip_address)