def backup_config(a_device):
 DEBUG = True
 perform_diff = False
 if DEBUG:
  print 'Retrieve device configuration via SSH: {}\n'.format(a_device.device_name)
 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 = (global_params.CFGS_DIR + file_name)
 bup_file = ((global_params.CFGS_DIR + a_device.device_name) + '.old')
 if os.path.isfile(full_path):
  cmd_status = subprocess.call(['/bin/mv', full_path, bup_file])
  perform_diff = True
 if DEBUG:
  print 'Writing configuration file to file system\n'
 with open(full_path, 'w') as f:
  f.write(output)
 a_device.cfg_file = file_name
 a_device.cfg_archive_time = timezone.make_aware(datetime.now(), timezone.get_current_timezone())
 a_device.cfg_last_changed = int(snmp_wrapper(a_device, oid=global_params.OID_RUNNING_LAST_CHANGED))
 a_device.save()
 if perform_diff:
  return find_diff(full_path, bup_file)
 else:
  return None

def backup_config ( a_device ) : DEBUG = True perform_diff = False if DEBUG : print 'Retrieve device configuration via SSH: {}\n' . format ( a_device . device_name ) 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 = ( global_params . CFGS_DIR + file_name ) bup_file = ( ( global_params . CFGS_DIR + a_device . device_name ) + '.old' ) if os . path . isfile ( full_path ) : cmd_status = subprocess . call ( [ '/bin/mv' , full_path , bup_file ] ) perform_diff = True if DEBUG : print 'Writing configuration file to file system\n' with open ( full_path , 'w' ) as f : f . write ( output ) a_device . cfg_file = file_name a_device . cfg_archive_time = timezone . make_aware ( datetime . now ( ) , timezone . get_current_timezone ( ) ) a_device . cfg_last_changed = int ( snmp_wrapper ( a_device , oid = global_params . OID_RUNNING_LAST_CHANGED ) ) a_device . save ( ) if perform_diff : return find_diff ( full_path , bup_file ) else : return None
retrieve configuration from network device .