ktbyers / netmiko

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

SNMP autodetect is broken if you feed a hostname into it. #3144

Open ktbyers opened 1 year ago

ktbyers commented 1 year ago

Traceback (most recent call last): File "/home/kbyers/netmiko_course/class10/collateral/snmp_detect.py", line 9, in my_snmp = SNMPDetect( File "/home/kbyers/VENV/py3_venv/src/netmiko/netmiko/snmp_autodetect.py", line 248, in init if ipaddress.ip_address(self.hostname).version == 6: File "/usr/local/lib/python3.9/ipaddress.py", line 53, in ip_address raise ValueError('%r does not appear to be an IPv4 or IPv6 address' % ValueError: 'cisco1.lasthop.io' does not appear to be an IPv4 or IPv6 address

ipaddress.ip_address does not support a hostname here.

ktbyers commented 1 year ago

Relevant change that broke this:

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

ktbyers commented 1 year ago

CC: @kacem-expereo

ktbyers commented 1 year ago

Need better testing for snmp_autodetect (would this have been caught in my standard release process)?

kacem-expereo commented 1 year ago

Sorry about this, indeed i actually never use hostnames when using netmiko and didn't think about it at all. I can replace ipaddress library with socket library which will help to figure out if it's using ipv4 or ipv6 and at the same time resolve the hostname. In the case where one host has both ipv4 and ipv6 we'd pass the hostname to cmdgen.UdpTransportTarget (so ipv4) as it would have been done before i break it.

Let me know if this is acceptable!

Draft : https://github.com/kacem-expereo/netmiko/tree/%233144

If it looks fine, I will manually test it against ipv4 only ipv6 only fqdn, then ipv4+ipv6 fqdn. Should I also find out how to test it automatically ?

Kindly,

ktbyers commented 1 year ago

@kacem-expereo Do you want to do a PR on this?

kacem-expereo commented 1 year ago

@ktbyers sure, i will proceed with some testing on my side and move forward with a PR :)

kacem-expereo commented 1 year ago

It's done @ktbyers ,sorry for the delay! waiting for your comments Kindly,