napalm-automation / napalm-ios

Apache License 2.0
31 stars 40 forks source link

ISSUE WITH BASIC NAPALM CODE #196

Closed Aadasrh closed 7 years ago

Aadasrh commented 7 years ago

Recently i am having issue with basic NAPALM code. Can someone please check and advise,

CODE:

from napalm import get_network_driver
driver=get_network_driver("ios")
connection=driver(hostname="192.168.0.5", username="aady", password="cisco")
print("opening")
connection.open()

Error `C:\Users\Rambo\AppData\Local\Programs\Python\Python36-32\python.exe C:/Users/Rambo/.PyCharmCE2017.2/config/scratches/scratch.py opening Traceback (most recent call last): File "C:\Users\Rambo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\netmiko\base_connection.py", line 502, in establish_connection self.remote_conn_pre.connect(**ssh_connect_params) File "C:\Users\Rambo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\paramiko\client.py", line 329, in connect raise NoValidConnectionsError(errors) paramiko.ssh_exception.NoValidConnectionsError: [Errno None] Unable to connect to port 22 on 192.168.0.5

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:/Users/Rambo/.PyCharmCE2017.2/config/scratches/scratch.py", line 5, in connection.open() File "C:\Users\Rambo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\napalm_ios\ios.py", line 135, in open *self.netmiko_optional_args) File "C:\Users\Rambo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\netmiko\ssh_dispatcher.py", line 131, in ConnectHandler return ConnectionClass(args, **kwargs) File "C:\Users\Rambo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\netmiko\base_connection.py", line 150, in init self.establish_connection() File "C:\Users\Rambo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\netmiko\base_connection.py", line 506, in establish_connection raise NetMikoTimeoutException(msg) netmiko.ssh_exception.NetMikoTimeoutException: Connection to device timed-out: cisco_ios 192.168.0.5:22

Process finished with exit code 1`

Aadasrh commented 7 years ago

@ktbyers can you please have a look and advise sir.

Aadasrh commented 7 years ago

Correction i fixed the port issue not getting this error

C:\Users\Rambo\AppData\Local\Programs\Python\Python36-32\python.exe C:/Users/Rambo/.PyCharmCE2017.2/config/scratches/scratch.py opening Traceback (most recent call last): File "C:\Users\Rambo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\paramiko\channel.py", line 683, in recv out = self.in_buffer.read(nbytes, self.timeout) File "C:\Users\Rambo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\paramiko\buffered_pipe.py", line 160, in read raise PipeTimeout() paramiko.buffered_pipe.PipeTimeout

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\Users\Rambo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\netmiko\base_connection.py", line 282, in _read_channel_expect new_data = self.remote_conn.recv(MAX_BUFFER) File "C:\Users\Rambo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\paramiko\channel.py", line 685, in recv raise socket.timeout() socket.timeout

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:/Users/Rambo/.PyCharmCE2017.2/config/scratches/scratch.py", line 5, in connection.open() File "C:\Users\Rambo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\napalm_ios\ios.py", line 137, in open self.device.enable() File "C:\Users\Rambo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\netmiko\cisco_base_connection.py", line 17, in enable return super(CiscoBaseConnection, self).enable(cmd=cmd, pattern=pattern, re_flags=re_flags) File "C:\Users\Rambo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\netmiko\base_connection.py", line 875, in enable output += self.read_until_prompt() File "C:\Users\Rambo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\netmiko\base_connection.py", line 334, in read_until_prompt return self._read_channel_expect(*args, **kwargs) File "C:\Users\Rambo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\netmiko\base_connection.py", line 289, in _read_channel_expect raise NetMikoTimeoutException("Timed-out reading channel, data not available.") netmiko.ssh_exception.NetMikoTimeoutException: Timed-out reading channel, data not available.

Process finished with exit code 1

ktbyers commented 7 years ago

@Aadasrh It looks like you are failing to go into enable mode.

Probably need something like:

from napalm import get_network_driver
driver=get_network_driver("ios")
optional_args = {'secret': 'your_secret'}
connection=driver(hostname="192.168.0.5", username="aady", password="cisco", optional_args=optional_args)
print("opening")
connection.open()
Aadasrh commented 7 years ago

@ktbyers Hello sir,

it is working fine you were correct the program was not able to go into enable mode i changed the user privilege level on router and it is working now.

one small doubt i have before doing this change i also made a simple Netmiko script to check my SSH and ran a command as so how did it work .

Did it run the command without going to enable mode.

Below is the netmiko program that was working without making any changes to user privilege.

from netmiko import ConnectHandler
cisco_881 = {
'device_type': 'cisco_ios',
'ip': '192.168.0.5',
'username': 'aady',
'password': 'cisco',}
net_connect = ConnectHandler(**cisco_881)
output=net_connect.send_command("show ip int brief")
print(output)
ktbyers commented 7 years ago

@Aadasrh Yes, 'show ip int brief' does not require enable privileges so in the Netmiko case it worked as is.