def retrieve_config():
 DEBUG = True
 net_devices = NetworkDevice.objects.all()
 for a_device in net_devices:
  if ('ssh' in a_device.device_class):
   if DEBUG:
    print 'Retrieve device configuration: {} {}\n'.format(a_device.device_name, a_device.device_class)
   ssh_connect = SSHConnection(a_device)
   ssh_connect.enable_mode()
   output = ssh_connect.send_command('show run\n')
   file_name = (a_device.device_name + '.txt')
   full_path = (CFGS_DIR + file_name)
   if DEBUG:
    print 'Writing configuration file to file system\n'
   with open(full_path, 'w') as f:
    f.write(output)

def retrieve_config ( ) : DEBUG = True net_devices = NetworkDevice . objects . all ( ) for a_device in net_devices : if ( 'ssh' in a_device . device_class ) : if DEBUG : print 'Retrieve device configuration: {} {}\n' . format ( a_device . device_name , a_device . device_class ) ssh_connect = SSHConnection ( a_device ) ssh_connect . enable_mode ( ) output = ssh_connect . send_command ( 'show run\n' ) file_name = ( a_device . device_name + '.txt' ) full_path = ( CFGS_DIR + file_name ) if DEBUG : print 'Writing configuration file to file system\n' with open ( full_path , 'w' ) as f : f . write ( output )
use ssh to retrieve the network device running configuration .