Open alextremblay opened 1 year ago
@alextremblay Couldn't you just load the existing dictionary in ssh_dispatcher and add a new key and the associated class?
from netmiko.ssh_dispatcher import CLASS_MAPPER
CLASS_MAPPER["my_driver"] = MyClass
unfortuantely, no.
the CLASS_MAPPER
global variable can be imported and manipulated, but the platforms
, platforms_base
, and platforms_str
global variables from that same module cannot, and they also need to be modified in order for the ssh_dispatcher
function to work properly
I'm working on a PR for this as we speak, and will submit it shortly
Good point on platforms
--you don't need platforms_base
nor platforms_str
though.
So this works:
from netmiko.cisco.cisco_nxos_ssh import CiscoNxosSSH
from netmiko.ssh_dispatcher import CLASS_MAPPER, platforms
from netmiko import ConnectHandler
class MyClass(CiscoNxosSSH):
pass
CLASS_MAPPER["my_driver"] = MyClass
platforms.append("my_driver")
device = {
"device_type": "my_driver",
"host": "nxos1.lasthop.io",
"username": "admin",
"password": "password",
}
with ConnectHandler(**device) as nc:
d = nc.send_command("show lldp neighbors detail")
print(d)
I am open to the PR though not really sure it is needed (since it is just three lines of code to do this with the existing code base).
you would also need to update platforms_str
, for situations where a typo or misconfiguration results in ssh_dispatcher
not being able to find the mistyped driver name, or the end user will be very confused why their actual driver name doesn't show up in the list of drivers in the exception raised by the ssh_dispatcher
function
Okay, we will just disagree on whether platforms_str
is needed here.
I will look at the PR.
It would be nice for netmiko users to be able to locally develop drivers for new hardware or modify / extend existing drivers and dog-food them for a while before submitting PRs to merge them into netmiko itself.
It would be really nice if, for example, a user could implement a new driver like so:
Or make local modifications to netmiko's behaviour like so: