【问题标题】:revert / rollback a configuration with netmiko使用 netmiko 恢复/回滚配置
【发布时间】:2022-08-22 06:03:33
【问题描述】:

嘿,我正在尝试在我发送给 netmiko 的每个配置命令上设置配置恢复。无法找到任何解决方案来完成该任务。 我想设置一个时间,如果配置没有完成,那么它将恢复到配置之前。

尝试使用 NAAS 并发送“配置终端恢复计时器 1”,然后发送随机配置命令,但似乎 netmiko 期望每个命令都有特定的输出,所以它在我发送后下降。我无法更改 netmiko 设置,因为我需要不时更新它

    标签: python configuration config revert netmiko


    【解决方案1】:

    我使用 NAPALM 的 device.rollback() 功能编写了以下代码。你也可以这样做。

    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.')
    

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

    【讨论】:

      猜你喜欢
      • 2011-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-08
      • 2011-03-02
      • 1970-01-01
      • 2022-10-19
      相关资源
      最近更新 更多