napalm-automation / napalm

Network Automation and Programmability Abstraction Layer with Multivendor support
Apache License 2.0
2.24k stars 551 forks source link

inline_transfer not working if specifying the configuration directly on IOS #1227

Open VDavidCC opened 4 years ago

VDavidCC commented 4 years ago

I'm using this scipt:

from napalm import get_network_driver
import time

with open('Devices.txt') as f:
    IpList = f.read().splitlines()

for ip_address in IpList:
    driver = get_network_driver('ios')
    iosv = driver(ip_address, '', '', optional_args= {'secret': ''})
    iosv.open()
    iosv.load_merge_candidate(config='no username respaldo' + '\n')
    iosv.commit_config()

But when i run got this error:

Traceback (most recent call last):
  File "usersremove.py", line 42, in <module>
    iosv.load_merge_candidate(config='no username respaldo' + '\n')
  File "C:\Program Files (x86)\Python38-32\lib\site-packages\napalm\ios\ios.py",
 line 315, in load_merge_candidate
    return_status, msg = self._load_candidate_wrapper(
  File "C:\Program Files (x86)\Python38-32\lib\site-packages\napalm\ios\ios.py",
 line 269, in _load_candidate_wrapper
    (return_status, msg) = self._scp_file(
  File "C:\Program Files (x86)\Python38-32\lib\site-packages\napalm\ios\ios.py",
 line 620, in _scp_file
    return self._xfer_file(
  File "C:\Program Files (x86)\Python38-32\lib\site-packages\napalm\ios\ios.py",
 line 692, in _xfer_file
    transfer.transfer_file()
  File "C:\Program Files (x86)\Python38-32\lib\site-packages\netmiko\scp_handler
.py", line 336, in transfer_file
    self.put_file()
  File "C:\Program Files (x86)\Python38-32\lib\site-packages\netmiko\scp_handler
.py", line 349, in put_file
    self.scp_conn.scp_transfer_file(self.source_file, destination)
  File "C:\Program Files (x86)\Python38-32\lib\site-packages\netmiko\scp_handler
.py", line 41, in scp_transfer_file
    self.scp_client.put(source_file, dest_file)
  File "C:\Program Files (x86)\Python38-32\lib\site-packages\scp.py", line 158,
in put
    self._recv_confirm()
  File "C:\Program Files (x86)\Python38-32\lib\site-packages\scp.py", line 363,
in _recv_confirm
    raise SCPException(asunicode(msg[1:]))
scp.SCPException: Privilege denied.

Then i tried adding inline_transfer = True in optional args, but still don't work now im getting this error:

Traceback (most recent call last):
  File "usersremove.py", line 42, in <module>
    iosv.load_merge_candidate(config='no username respaldo' + '\n')
  File "C:\Program Files (x86)\Python38-32\lib\site-packages\napalm\ios\ios.py",
 line 315, in load_merge_candidate
    return_status, msg = self._load_candidate_wrapper(
  File "C:\Program Files (x86)\Python38-32\lib\site-packages\napalm\ios\ios.py",
 line 261, in _load_candidate_wrapper
    (return_status, msg) = self._inline_tcl_xfer(
  File "C:\Program Files (x86)\Python38-32\lib\site-packages\napalm\ios\ios.py",
 line 604, in _inline_tcl_xfer
    return self._xfer_file(
  File "C:\Program Files (x86)\Python38-32\lib\site-packages\napalm\ios\ios.py",
 line 670, in _xfer_file
    with TransferClass(**kwargs) as transfer:
  File "C:\Program Files (x86)\Python38-32\lib\site-packages\netmiko\cisco\cisco
_ios.py", line 90, in __init__
    self.source_md5 = self.config_md5(source_config)
  File "C:\Program Files (x86)\Python38-32\lib\site-packages\netmiko\cisco\cisco
_ios.py", line 172, in config_md5
    return super().file_md5(source_config, add_newline=True)
  File "C:\Program Files (x86)\Python38-32\lib\site-packages\netmiko\scp_handler
.py", line 284, in file_md5
    with open(file_name, "rb") as f:
OSError: [Errno 22] Invalid argument: 'no username respaldo \n'

I know that there is a workaround using a user privilege 15 but for my purpose is nos possible to do that, please help me.

i typed this on the cisco switch:

S1#tclsh
S1(tcl)#exit
S1#

But i'm not getting any response or log...

ktbyers commented 4 years ago

Okay, there is a probably bug in inline_transfer. As a workaround, you would need to put your configuration changes in an external file.

In other words, call:

 load_merge_candidate(filename="my_changes.txt")
VDavidCC commented 4 years ago

That solved the problem, thank you!

ktbyers commented 4 years ago

I am going to re-open() to track the original issue.

BENBUNOR commented 1 year ago

@ktbyers

here is my code that i am running:

import json from napalm import get_network_driver from getpass import getpass driver = get_network_driver('ios')

device = driver( hostname='10.0.0.0', username='adm', password=getpass(), optional_args={'inline_transfer': ''} ) device.open()

device.load_merge_candidate(filename='config.txt')

diffs = device.compare_config()

if len(diffs) > 0: print(diffs) device.commit_config() else: print('no change is required') device.discard_config()

device.close()

i have privilege 15 access, and i still get this error: scp.SCPException: Privilege denied.