netmiko icon indicating copy to clipboard operation
netmiko copied to clipboard

ConnectHandler() takes 40 second to connect into 'fortinet' device

Open Raqs1N opened this issue 5 years ago • 5 comments

Hi guys, I'm new to netmiko and I'm trying using it for automation. right now my first code to connect into a device was kind a cool except one thing - it takes 40 whole seconds to finish the "ConnectHandler(**kwargs)" function and connecting into my fortigate device.

I'm also new to python, so I couldn't understand how the library works and where does the connection function happen and when?

I hope some1 could help me here or I will have to create my own library to connect into my network devices through secureCRT shell, and write my own regex to find output and stuff which could be nice, but I rather not do that if the netmiko library is a good choice, but I can't afford waiting 40 seconds for execution everytime!

Thanks you very much , this is the code:

import netmiko as n import time

print(n.file)

device = { 'device_type': 'fortinet',
'host': 'my-ip',
'username': 'username',
'password': 'password'}

start = time.time() forti200D = n.ConnectHandler(**device) # It takes about 40 sec to create the connection end = time.time() print(round(end - start , 2)) #output = 41.27 seconds exactly each time I execute the program

print(forti200D.find_prompt()) # fast output , about 0.2 second long after the "print()" function

Raqs1N avatar Jan 21 '21 16:01 Raqs1N

You probably need to include the Netmiko session_log and debug log output.

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

ktbyers avatar Jan 21 '21 18:01 ktbyers

test.log

Here is the generated log, can't tell whats the problem, it shouldn't take 40 seconds. I hope you can tell whats going on.

Also, I can see there are some commands inserted automaticaly to the device's CLI, some of them aren't even valid, could you explain this?

Raqs1N avatar Jan 21 '21 18:01 Raqs1N

You probably need to include the Netmiko session_log and debug log output.

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

Raqs1N avatar Jan 21 '21 18:01 Raqs1N

Yeah, this driver is a bit of a mess and does a whole bunch of things after logging in. The code is here:

https://github.com/ktbyers/netmiko/blob/develop/netmiko/fortinet/fortinet_ssh.py#L17

It doesn't surprise me it is that slow given the set of things the driver is doing.

If someone wants to reimplement the driver, I am open to it. I don't have a Fortinet device so it will probably need to be someone else.

Regards, Kirk

ktbyers avatar Jan 22 '21 01:01 ktbyers

add 'fast_cli' : True to the fortinet object, it reduced my SSH times from 42 seconds to 4.5 seconds

ritxsec avatar Jun 17 '21 20:06 ritxsec

Updated Fortinet driver is located here:

https://github.com/ktbyers/netmiko/pull/3091

ktbyers avatar Jan 24 '23 00:01 ktbyers