「非公式シリーズ」netmikoのデバイスタイプに指定できるdevice typeを調べるためのpythonスクリプト
netmikoを使うときに、以下のリンク先のnetmikoの公式サイト(netmikoのGitHub)にのってるサンプルスクリプトがなにかと参考になります。例えば、使用できるdevice typeを調べる方法とか、ログをとる方法が載ってたり。
ただ、netmikoの公式サイト(netmikoのGitHub)にのってるサンプルスクリプトだと、説明が何もないのでnetmikoをこれから使おうと言う方にはちょっと厳しめです。(英語だし、、、)
そこで、勝手にnetmiko公式サイト(netmikoのGitHub)のサンプルスクリプトを、日本語での意味などを追記して掲載しているシリーズです。
今回は、デバイスタイプに指定できるdevice typeを調べるためのpythonスクリプトです。
デバイスタイプに指定できるdevice typeを調べるためのpythonスクリプト
available_device_types.py
from netmiko import ConnectHandler # デバイスタイプに'invalid'と指定 cisco1 = { "device_type": "invalid", "host": "cisco1.lasthop.io", "username": "pyclass", "password": "invalid" } net_connect = ConnectHandler(**cisco1) net_connect.disconnect()
解説
サンプルスクリプトのように、device_typeの値に"invalid"と指定したスクリプトを実行するとエラーとなります。
このとき、数行エラーメッセージが出力されますが、そのあとに使用できるデバイスタイプ一覧がされ、使用できるデバイスタイプ一覧を確認することができます。
(実は、device_typeは"invalid"でなくても、適当な文字列でもかまいません)
今回の方法で確認できるのは、ssh接続を行いたいときに使用するdevice_typeなります。
もし、telnet接続を行いたいときに使用するdevice_typeを確認したい方は、device_typeの値に"invalid_telnet"と指定してください。
(device_typeの名前の_telnetが後ろに付くと、telnet接続を使用するようにnetmikoは実装されています)
また、本サンプルスクリプトは、実行してもエラーとなるため実際にはリモート接続を行わないため、"host"や"username"などは、適当な文字列でも問題ありません。
実行例
> python .\available_device_types.py Traceback (most recent call last): File "available_device_types.py", line 28, in <module> net_connect = ConnectHandler(**cisco1) File "\netmiko\ssh_dispatcher.py", line 321, in ConnectHandler raise ValueError( ValueError: Unsupported 'device_type' currently supported platforms are: a10 accedian adtran_os alcatel_aos alcatel_sros allied_telesis_awplus apresia_aeos arista_eos aruba_os aruba_osswitch aruba_procurve avaya_ers avaya_vsp broadcom_icos brocade_fastiron brocade_fos brocade_netiron brocade_nos brocade_vdx brocade_vyos calix_b6 cdot_cros centec_os checkpoint_gaia ciena_saos cisco_asa cisco_ftd cisco_ios cisco_nxos cisco_s300 cisco_tp cisco_wlc cisco_xe cisco_xr 以下は省略
netmikoのサンプルスクリプトをお探しの方へ
netmikoのサンプルスクリプトを探している方は、以下に記載したnetmiko公式(netmikoのGitHub)を一度見てみてください。
上記のリンク先に掲載されている内容ですが、以下のような情報が掲載されていますので探し物が見つかるかもしれません。
Available Device Types
- Available device types
Simple Examples
- Simple example
- Connect using a dictionary
- Dictionary with a context manager
- Enable mode
Multiple Devices (simple example)
- Connecting to multiple devices
Show Commands
- Executing a show command
- Handling commands that prompt (timing)
- Handling commands that prompt (expect_string)
- Using global_delay_factor
- Adjusting delay_factor
Parsers (TextFSM and Genie)
- TextFSM example
- Genie example
Configuration Changes
- Configuration changes
- Configuration changes from a file
Logging and Session Log
- Session log
- Standard logging
Secure Copy
- Secure Copy
Auto Detection of Device Type
- Auto detection using SSH
- Auto detection using SNMPv3
- Auto detection using SNMPv2c
Terminal Server Example
- Terminal Server and Redispatch
以上です。
netmikoのデバイスタイプ一覧
pythonの外部ライブラリ:netmikoで、接続するデバイスの種類を指定するときに使用するデバイスタイプ一覧です。(2022年1月16日(日)に抽出)
自分が使用しているデバイスを指定するときに、どのようなデバイスタイプの名前を指定したらいいかわからないときに参考にしてください。
今回取り上げたデバイスタイプ名は、実際のnetmikoのスクリプトでいうところの、以下の中の'device_type':のパラメータの部分になります。
from netmiko import ConnectHandler cisco_881 = { 'device_type': 'cisco_ios', # この'cisco_ios'の部分になります 'host': '10.10.10.10', 'username': 'test', 'password': 'password', 'secret': 'secret', }
telnetとsshでは、指定するデバイスタイプ名が異なります。
はじめにtelnetを使用するときのデバイスタイプ名、そのあとにsshを使用するときのデバイスタイプ名を記載します。
adtran_os_telnet
apresia_aeos_telnet
arista_eos_telnet
aruba_procurve_telnet
brocade_fastiron_telnet
brocade_netiron_telnet
calix_b6_telnet
centec_os_telnet
ciena_saos_telnet
cisco_ios_telnet
cisco_xr_telnet
cisco_s300_telnet
dell_dnos6_telnet
dell_powerconnect_telnet
dlink_ds_telnet
extreme_telnet
extreme_exos_telnet
extreme_netiron_telnet
generic_telnet
generic_termserver_telnet
hp_procurve_telnet
hp_comware_telnet
huawei_telnet
huawei_olt_telnet
ipinfusion_ocnos_telnet
juniper_junos_telnet
nokia_sros_telnet
oneaccess_oneos_telnet
paloalto_panos_telnet
rad_etx_telnet
raisecom_telnet
ruckus_fastiron_telnet
ruijie_os_telnet
supermicro_smis_telnet
tplink_jetstream_telnet
yamaha_telnet
zte_zxros_telnet
a10
accedian
adtran_os
alcatel_aos
alcatel_sros
allied_telesis_awplus
apresia_aeos
arista_eos
aruba_os
aruba_osswitch
aruba_procurve
avaya_ers
avaya_vsp
broadcom_icos
brocade_fos
brocade_fastiron
brocade_netiron
brocade_nos
brocade_vdx
brocade_vyos
checkpoint_gaia
calix_b6
cdot_cros
centec_os
ciena_saos
cisco_asa
cisco_ftd
cisco_ios
cisco_nxos
cisco_s300
cisco_tp
cisco_viptela
cisco_wlc
cisco_xe
cisco_xr
cloudgenix_ion
coriant
dell_dnos9
dell_force10
dell_os6
dell_os9
dell_os10
dell_sonic
dell_powerconnect
dell_isilon
dlink_ds
endace
eltex
eltex_esr
enterasys
ericsson_ipos
extreme
extreme_ers
extreme_exos
extreme_netiron
extreme_nos
extreme_slx
extreme_vdx
extreme_vsp
extreme_wing
f5_ltm
f5_tmsh
f5_linux
flexvnf
fortinet
generic
generic_termserver
hp_comware
hp_procurve
huawei
huawei_smartax
huawei_olt
huawei_vrpv8
ipinfusion_ocnos
juniper
juniper_junos
juniper_screenos
keymile
keymile_nos
linux
mikrotik_routeros
mikrotik_switchos
mellanox
mellanox_mlnxos
mrv_lx
mrv_optiswitch
netapp_cdot
netgear_prosafe
netscaler
nokia_sros
oneaccess_oneos
ovs_linux
paloalto_panos
pluribus
quanta_mesh
rad_etx
raisecom_roap
ruckus_fastiron
ruijie_os
sixwind_os
sophos_sfos
supermicro_smis
tplink_jetstream
ubiquiti_edge
ubiquiti_edgerouter
ubiquiti_edgeswitch
ubiquiti_unifiswitch
vyatta_vyos
vyos
watchguard_fireware
zte_zxros
yamaha
以上です。