diff --git a/nornir_netmiko/connections/netmiko.py b/nornir_netmiko/connections/netmiko.py index 59dd641..1d957bf 100644 --- a/nornir_netmiko/connections/netmiko.py +++ b/nornir_netmiko/connections/netmiko.py @@ -1,6 +1,7 @@ from typing import Any, Dict, Optional from netmiko import ConnectHandler +from netmiko.ssh_autodetect import SSHDetect from nornir.core.configuration import Config @@ -14,6 +15,7 @@ "eos": "arista_eos", "junos": "juniper_junos", "iosxr": "cisco_xr", + "netmiko_auto": "autodetect", } @@ -52,7 +54,16 @@ def open( if platform is not None: # Look platform up in corresponding map, if no entry return the host.nos unmodified platform = napalm_to_netmiko_map.get(platform, platform) - parameters["device_type"] = platform + if platform == "autodetect": # If we are using autodect + parameters["device_type"] = platform + guesser = SSHDetect(**parameters) + best_match = guesser.autodetect() + if best_match: # If we find a device_type + parameters["device_type"] = best_match + else: + raise ValueError("Netmiko cannot detect the device_type") + else: + parameters["device_type"] = platform extras = extras or {} parameters.update(extras)