ktbyers / netmiko

Multi-vendor library to simplify Paramiko SSH connections to network devices
MIT License
3.55k stars 1.3k forks source link

Netmiko giving some issues while using send_config_set #1769

Closed vishnu9094 closed 4 years ago

vishnu9094 commented 4 years ago

I am having a simple code of sending a config to the router.

Setup : Network Automation tool ---------------- Router 1

Configuration :

from netmiko import ConnectHandler

iosvl2 = {
    'device_type' : 'cisco_ios',
    'ip':'192.168.122.10',
    'username':'network',
    'password':'rhinos',
}

connect=ConnectHandler(**iosvl2)
output=connect.send_command("show ip interface brief")
print(output)

config_command=['interface lo0','ip address 1.1.1.1 255.255.255.255']
output=connect.send_config_set(config_command)
print(output)

Below is my output `root@NetworkAutomation-1:~# python3 netmiko1.py Interface IP-Address OK? Method Status Protocol FastEthernet0/0 192.168.122.65 YES manual up up FastEthernet0/1 unassigned YES unset administratively down down FastEthernet1/0 unassigned YES unset administratively down down FastEthernet1/1 unassigned YES unset administratively down down FastEthernet2/0 unassigned YES unset administratively down down FastEthernet2/1 unassigned YES unset administratively down down FastEthernet3/0 unassigned YES unset administratively down down FastEthernet3/1 unassigned YES unset administratively down down Traceback (most recent call last): File "/usr/local/lib/python3.8/dist-packages/paramiko/channel.py", line 699, in recv out = self.in_buffer.read(nbytes, self.timeout) File "/usr/local/lib/python3.8/dist-packages/paramiko/buffered_pipe.py", line 164, in read raise PipeTimeout() paramiko.buffered_pipe.PipeTimeout

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/local/lib/python3.8/dist-packages/netmiko/base_connection.py", line 550, in _read_channel_expect new_data = self.remote_conn.recv(MAX_BUFFER) File "/usr/local/lib/python3.8/dist-packages/paramiko/channel.py", line 701, in recv raise socket.timeout() socket.timeout

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "netmiko1.py", line 16, in output=connect.send_config_set(config_command) File "/usr/local/lib/python3.8/dist-packages/netmiko/base_connection.py", line 1735, in send_config_set output += self.config_mode(cfg_mode_args) File "/usr/local/lib/python3.8/dist-packages/netmiko/cisco_base_connection.py", line 40, in config_mode return super().config_mode(config_command=config_command, pattern=pattern) File "/usr/local/lib/python3.8/dist-packages/netmiko/base_connection.py", line 1619, in config_mode if not self.check_config_mode(): File "/usr/local/lib/python3.8/dist-packages/netmiko/cisco/cisco_ios.py", line 29, in check_config_mode return super().check_config_mode(check_string=check_string, pattern=pattern) File "/usr/local/lib/python3.8/dist-packages/netmiko/cisco_base_connection.py", line 30, in check_config_mode return super().check_config_mode(check_string=check_string, pattern=pattern) File "/usr/local/lib/python3.8/dist-packages/netmiko/base_connection.py", line 1606, in check_config_mode output = self.read_until_pattern(pattern=pattern) File "/usr/local/lib/python3.8/dist-packages/netmiko/base_connection.py", line 627, in read_until_pattern return self._read_channel_expect(args, **kwargs) File "/usr/local/lib/python3.8/dist-packages/netmiko/base_connection.py", line 560, in _read_channel_expect raise NetmikoTimeoutException( netmiko.ssh_exception.NetmikoTimeoutException: Timed-out reading channel, data not available. root@NetworkAutomation-1:~# `

ktbyers commented 4 years ago

Does the account you are logging in with have permissions to change the configuration (i.e. privilege level 15)?

If not, you need to add a secret argument to your ConnectHandler dictionary and call the enable() method

vishnu9094 commented 4 years ago

It has privileged 15, i have tried them.

ktbyers commented 4 years ago

Okay, I will need to see the output of your log file when this error happens:

https://github.com/ktbyers/netmiko/blob/develop/COMMON_ISSUES.md#enable-netmiko-logging-of-all-reads-and-writes-of-the-communications-channel

ktbyers commented 4 years ago

@vishnu9094 Any update on providing the log file output?

narayanankl commented 4 years ago

Hi, I have the same issue and logs are as foloowing.

Traceback (most recent call last): File "/usr/local/lib/python3.8/dist-packages/paramiko/channel.py", line 699, in recv out = self.in_buffer.read(nbytes, self.timeout) File "/usr/local/lib/python3.8/dist-packages/paramiko/buffered_pipe.py", line 164, in read raise PipeTimeout() paramiko.buffered_pipe.PipeTimeout

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/local/lib/python3.8/dist-packages/netmiko/base_connection.py", line 550, in _read_channel_expect new_data = self.remote_conn.recv(MAX_BUFFER) File "/usr/local/lib/python3.8/dist-packages/paramiko/channel.py", line 701, in recv raise socket.timeout() socket.timeout

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "netmiko1.py", line 10, in output = net_connect.send_config_set(config_commands) File "/usr/local/lib/python3.8/dist-packages/netmiko/base_connection.py", line 1735, in send_config_set output += self.config_mode(cfg_mode_args) File "/usr/local/lib/python3.8/dist-packages/netmiko/cisco_base_connection.py", line 40, in config_mode return super().config_mode(config_command=config_command, pattern=pattern) File "/usr/local/lib/python3.8/dist-packages/netmiko/base_connection.py", line 1619, in config_mode if not self.check_config_mode(): File "/usr/local/lib/python3.8/dist-packages/netmiko/cisco/cisco_ios.py", line 29, in check_config_mode return super().check_config_mode(check_string=check_string, pattern=pattern) File "/usr/local/lib/python3.8/dist-packages/netmiko/cisco_base_connection.py", line 30, in check_config_mode return super().check_config_mode(check_string=check_string, pattern=pattern) File "/usr/local/lib/python3.8/dist-packages/netmiko/base_connection.py", line 1606, in check_config_mode output = self.read_until_pattern(pattern=pattern) File "/usr/local/lib/python3.8/dist-packages/netmiko/base_connection.py", line 627, in read_until_pattern return self._read_channel_expect(args, **kwargs) File "/usr/local/lib/python3.8/dist-packages/netmiko/base_connection.py", line 560, in _read_channel_expect raise NetmikoTimeoutException( netmiko.ssh_exception.NetmikoTimeoutException: Timed-out reading channel, data not available.

ktbyers commented 4 years ago

@narayanankl I don't see the log file (the only thing above is the exception stack trace):

I need the following:

https://github.com/ktbyers/netmiko/blob/develop/COMMON_ISSUES.md#enable-netmiko-logging-of-all-reads-and-writes-of-the-communications-channel

narayanankl commented 4 years ago

test_log.txt

@ktbyers , thanks for your response, please see the attached log for your reference.

narayanankl commented 4 years ago

@ktbyers , thanks for your guidance, the log helped me to identify the issue.

Issue was related to privilege mode.

adding below the two statemests helped me to run my first basic script successful.

  1. net_connect.enable()
  2. 'secret': 'test123' +++++++++++++++++++++++++++++++++++++++++++

from netmiko import ConnectHandler import logging logging.basicConfig(filename='test.log', level=logging.DEBUG) logger = logging.getLogger("netmiko")

ios_l2 = {'device_type': 'cisco_ios', 'ip': '192.168.122.200', 'username': 'test', 'password': 'test123', 'secret': 'test123'}

net_connect = ConnectHandler(**ios_l2) output = net_connect.send_command('show ip int brief') print(output) net_connect.enable() config_commands = ['int lo 200'] output = net_connect.send_config_set(config_commands) print(output)