0

hey i am trying to set a config revert on every config commands i send to netmiko. cant manage to find any solution for doing that task. i want to set a time which if the configuration isnt complete then it will revert to before the configuration.

tried to use NAAS and send "configure terminal revert timer 1" and then a random config command but it seems netmiko expects a specific output from each command so it falls after i send it. i cant change the netmiko setting because i need to update it once in a while

1 Answers1

2

I wrote the following code using the NAPALM's device.rollback() feature. You can do it this way too.

from napalm import get_network_driver
driver = get_network_driver('eos')
device = driver('ip_address', 'username', 'password')
device.open()

device.load_replace_candidate(filename='device.conf')
print (device.compare_config())

if len(device.compare_config()) > 0:
    choice = input("\nWould you like to Replace the Configuration file? [yN]: ")
    if choice == 'y':
        print('Committing ...')
        device.commit_config()

        choice = input("\nWould you like to Rollback to previous config? [yN]: ") 
        if choice == 'y':
            print('Rollback config is in progress ...')
            device.rollback()  
    else:
        print('Discarding ...')
        device.discard_config()
else:
    print ('No difference')

device.close()
print('Done.')

Resource: https://napalm.readthedocs.io/en/develop/tutorials/changing_the_config.html

Baris Sonmez
  • 477
  • 2
  • 8