Reputation: 77
Hey guys I am trying to test the commit of napalm, but it is not able to finding the cfg file, I also tried to change to "txt", but the same error. Here my code:
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()
and this is the error,both files are in the same folder:
user@user-pc:~/Documents/python_files$ /usr/bin/python3 /home/user/Documents/python_files/network/config_compare.py Traceback (most recent call last): File "/home/user/Documents/python_files/network/config_compare.py", line 18, in device.load_merge_candidate(filename="config.cfg") File "/home/user/.local/lib/python3.8/site-packages/napalm/ios/ios.py", line 315, in load_merge_candidate return_status, msg = self._load_candidate_wrapper( File "/home/user/.local/lib/python3.8/site-packages/napalm/ios/ios.py", line 282, in _load_candidate_wrapper (return_status, msg) = self._scp_file( File "/home/user/.local/lib/python3.8/site-packages/napalm/ios/ios.py", line 620, in _scp_file return self._xfer_file( File "/home/user/.local/lib/python3.8/site-packages/napalm/ios/ios.py", line 670, in _xfer_file with TransferClass(**kwargs) as transfer: File "/home/user/.local/lib/python3.8/site-packages/netmiko/ssh_dispatcher.py", line 278, in FileTransfer return FileTransferClass(*args, **kwargs) File "/home/user/.local/lib/python3.8/site-packages/netmiko/scp_handler.py", line 80, in init self.source_md5 = self.file_md5(source_file) File "/home/user/.local/lib/python3.8/site-packages/netmiko/scp_handler.py", line 257, in file_md5 with open(file_name, "rb") as f: FileNotFoundError: [Errno 2] No such file or directory: 'config.c
tks for any help..
Upvotes: 0
Views: 523
Reputation: 21
It looks like a problem with a filepath, are you sure that 'config.cfg' is in the same dir as your code?
Try the below to see if you can access the file (if you can't you need to modify the filepath):
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()
Upvotes: 0