嘿伙计们,我正在尝试测试凝固汽油弹的提交,但它找不到 cfg 文件,我也尝试更改为"txt",但同样的错误。 这是我的代码:
import napalm
import json
driver = napalm.get_network_driver("ios")
device = driver(
hostname="10.0.0.254",
username="cisco",
password="cisco",
optional_args={"secret" : "cisco"}
)
device.open()
device.load_merge_candidate(filename="config.cfg")
device.commit_config()
device.close()
这是错误,两个文件都在同一个文件夹中:
user@user-pc:~/Documents/python_files$/usr/bin/python3/首页/用户/文档/python_files/网络/config_compare.py 回溯 (最近一次通话(:文件 "/home/user/Documents/python_files/network/config_compare.py",行 18, 英寸 device.load_merge_candidate(filename="config.cfg"( 文件 "/home/user/.local/lib/python3.8/site-packages/napalm/ios/ios.py", 315路,load_merge_candidate return_status, msg = self._load_candidate_wrapper( File "/home/user/.local/lib/python3.8/site-packages/napalm/ios/ios.py", 282行,_load_candidate_wrapper (return_status, msg( = self._scp_file( 文件 "/home/user/.local/lib/python3.8/site-packages/napalm/ios/ios.py", 620路,_scp_file 返回 self._xfer_file( 文件 "/home/user/.local/lib/python3.8/site-packages/napalm/ios/ios.py", 670路,_xfer_file 使用 TransferClass(**kwargs( 作为传输:文件 "/home/user/.local/lib/python3.8/site-packages/netmiko/ssh_dispatcher.py", 第 278 行,在文件传输中 return FileTransferClass(*args, **kwargs( File "/home/user/.local/lib/python3.8/site-packages/netmiko/scp_handler.py", 第 80 行,在initself.source_md5 = self.file_md5(source_file( 文件 "/home/user/.local/lib/python3.8/site-packages/netmiko/scp_handler.py", 257号线,file_md5 将 open(file_name, "rb"( 作为 f: FileNotFoundError: [Errno 2] 没有这样的文件或目录: 'config.c
tks 寻求任何帮助..
看起来文件路径有问题,您确定"config.cfg"与您的代码位于同一目录中吗?
尝试以下操作以查看是否可以访问该文件(如果不能,则需要修改文件路径(:
import napalm
driver = napalm.get_network_driver("ios")
device = driver(
hostname="10.0.0.254",
username="cisco",
password="cisco",
optional_args={"secret" : "cisco"}
)
device.open()
print('This is a config to be added:n')
with open('config.cfg','r') as f:
output = f.read()
device.load_merge_candidate(filename="config.cfg")
# I would add this to see what's you are merging:
print(device.compare_config())
confirm_config= input('Do you want to deploy the above config? Press Y to deploy n')
if confirm_config == 'Y':
device.commit_config()
device.close()
else:
device.close()