ktbyers / netmiko

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

SSH autodetect improvement #3130

Closed M0NsTeRRR closed 1 year ago

M0NsTeRRR commented 1 year ago

Hello,

I'm trying to add ssh_autodetect for fiberstore product (two differents firmware) linked to #3129 but the issue is one command give the company and an other one give the version.

System OID String : 1.3.6.1.4.1.52642.2.1.45.101 => 52642 = fiberstore

SW2-1#show system
 System Up Time         : 8 days, 12 hours, 50 minutes, and 49.27 seconds
 System Name            : SW2
 System Location        : Rack
 System Contact         : admin@example.com
 MAC Address (Unit 1)   : 64-9D-99-10-08-58
 System OID String  : 1.3.6.1.4.1.52642.2.1.45.101
 http Server        : Disabled
 http Server Port   : 80
 https Server       : Disabled
 https Server Port  : 443
 Telnet Server      : Disabled
 Telnet Server Port : 23

System Temperature:
-----------------------------------------------------------------
unit 1     Temperature 1:  55 degrees

System Power status:
-----------------------------------------------------------------
 Unit 1     Main Power Status      : Up

Operation Code Version : 1.7.5

SW2-1#show version
Unit 1 -----------------------------
 Serial Number          : CG1905044600N0124
 Hardware Version       : 1.0
 Number of Ports        : 28
 Loader Version         : 1.4
 Operation Code Version : 1.7.5

Maybe we could rewrite autodetect with flexibility to handle when more than one command is needed ?

"hp_comware": {
        "cmd": "display version",
        "search_patterns": ["HPE Comware", "HP Comware"],
        "priority": 99,
        "dispatch": "_autodetect_std",
    },

to

"hp_comware": {
        "search": [
          {"cmd": "display version", "patterns": ["HPE Comware", "HP Comware"]}
        ],
        "priority": 99,
        "dispatch": "_autodetect_std",
    },

If you agree with the idea, I can open a PR to rewrite it.

ktbyers commented 1 year ago

@M0NsTeRRR You can call a different custom function/method by using a different callable for dispatch i.e. you can call a different callable than _autodetect_std.

ktbyers commented 1 year ago

Let me know if that makes sense.

M0NsTeRRR commented 1 year ago

Of course, but I think that having a more generic function may be more useful and avoid having two functions that are quite similar in operation. That's up to you.

ktbyers commented 1 year ago

Yes, what I recommended above is the standard way to do this in Netmiko i.e. you would create a new function to accomplish your purpose and then call that as part of dispatch.