Nornir Netmiko 查看支持的设备类型

在NetDevOps开发写Nornir脚本时,会碰到多种多样的设备类型,需要经常查找Nornir支持的设备类型。每次使用时都需要在网络上搜索,太浪费时间了。

后来发现Nornir使用Netmiko,所以只需要查看netmiko支持的设备类型即可。

记录下查看方法:

请确保已经安装netmiko后,再查找 ssh_dispatcher.py 文件:

    Centos路径:
        /opt/rh/rh-python38/root/usr/local/lib/python3.8/site-packages/netmiko/ssh_dispatcher.py

     Ubuntu路径:
        /usr/local/lib/python3.8/dist-packages/netmiko/ssh_dispatcher.py

    Windows路径:
        C:\Users\Admin\AppData\Local\Programs\Python\Python38\Lib\site-packages\netmiko\ssh_dispatcher.py

不同的系统路径不同,Linux可查找文件名 :sudo find / -name ssh_dispatcher.py 



查看 CLASS_MAPPER_BASE 下面的内容:
# The keys of this dictionary are the supported device_types
CLASS_MAPPER_BASE = {
    "a10": A10SSH,
    "accedian": AccedianSSH,
    "adtran_os": AdtranOSSSH,
    "alcatel_aos": AlcatelAosSSH,
    "alcatel_sros": NokiaSrosSSH,
    "allied_telesis_awplus": AlliedTelesisAwplusSSH,
    "apresia_aeos": ApresiaAeosSSH,
    "arista_eos": AristaSSH,
    "aruba_os": ArubaSSH,
    "aruba_osswitch": HPProcurveSSH,
    "aruba_procurve": HPProcurveSSH,
    "avaya_ers": ExtremeErsSSH,
    "avaya_vsp": ExtremeVspSSH,

其中 "aruba_os"之类的, 就是Nornir支持的设备类型啦。

使用以下脚本也可以:

from netmiko import platforms

for i in platforms:
    print(i)

ssh_platforms = [i for i in platforms if 'telnet' not in i and 'serial' not in i and 'ssh' not in i]
ssh_platforms.remove('abc')
ssh_platforms.remove('autodetect')
ssh_platforms.remove('terminal_server')

telnet_platforms = [i for i in platforms if 'telnet' in i]
serial_platforms = [i for i in platforms if 'serial' in i]

print(ssh_platforms)
print(len(ssh_platforms))
print(telnet_platforms)
print(len(telnet_platforms))
print(serial_platforms)

引用:

Netmiko官方文档

你可能感兴趣的:(python)