有人可以帮忙吗?当我尝试使用凝固汽油弹测试简单代码时出现错误。我在 GNS3 上使用了 cisco。我还添加了可选参数(delay_factor),但它得到了相同的错误。
from napalm import get_network_driver
driver = get_network_driver("ios")
others = {
"secret" : "cisco",
"dest_file_system" : "nvram:",
'delay_factor': 5
}
device = driver(hostname="192.168.124.148", username="cisco", password="cisco", optional_args=others)
device.open()
device.load_merge_candidate(filename="candidate")
compare = device.compare_config()
print(compare)
device.commit_config()
device.close()
Traceback (most recent call last):
File "c.py", line 16, in <module>
device.commit_config()
File "/Users/zakky.muhammad/Downloads/tmp/Env/lib/python3.8/site-packages/napalm/ios/ios.py", line 555, in commit_config
output += self.device.save_config()
File "/Users/zakky.muhammad/Downloads/tmp/Env/lib/python3.8/site-packages/netmiko/cisco/cisco_ios.py", line 37, in save_config
return super(CiscoIosBase, self).save_config(
File "/Users/zakky.muhammad/Downloads/tmp/Env/lib/python3.8/site-packages/netmiko/cisco_base_connection.py", line 224, in save_config
output = self.send_command(command_string=cmd)
File "/Users/zakky.muhammad/Downloads/tmp/Env/lib/python3.8/site-packages/netmiko/base_connection.py", line 1335, in send_command
raise IOError(
OSError: Search pattern never detected in send_command_expect: R\#
您可以使用我在下面分享的代码。
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.')
嘿,如果有人仍然面临同样的问题,您可以在设置基本配置后尝试在目标路由器中运行“复制运行配置启动配置”。我没有解释它是如何工作的,但不知何故,如果我在初始配置后运行命令,从外部推送的脚本将会成功。