ConnectHandlerメソッドメモ
あまりにもたくさんある(下記参照)ので網羅はできないけど、検証したものは記録として残しておく。
.is_alive(), .find_prompt(), .send_config_set()
>>> from netmiko import ConnectHandler
>>> R19 = ConnectHandler(ip = "192.168.122.19", username = "admin", password = "admin", device_type = "cisco_xe")
>>> check = R19.is_alive()
>>> print(check)
True
>>> R19.disconnect()
>>> check = R19.is_alive()
>>> print(check)
False
>>> R19.establish_connection()
>>> check = R19.is_alive()
>>> print(check)
True
>>> print(R19.find_prompt())
R19#
>>> Loopback1 = ["int lo1", "ip add 1.1.1.1 255.255.255.255", "ip o 1 area 1"]
>>> R19.send_config_set(Loopback1)
'\nR19#config term\nEnter configuration commands, one per line. End with CNTL/Z.\nR19(config)#int lo1\nR19(config-if)#ip add 1.1.1.1 255.255.255.255\nR19(config-if)#ip o 1 area 1\nR19(config-if)#end\nR19#'
>>>
R19#sh ip int bri
Interface IP-Address OK? Method Status Protocol
GigabitEthernet0/0 10.19.21.19 YES NVRAM up up
GigabitEthernet0/1 10.19.29.19 YES NVRAM up up
GigabitEthernet0/2 10.19.20.19 YES NVRAM up up
GigabitEthernet0/3 unassigned YES NVRAM administratively down down
GigabitEthernet0/4 unassigned YES NVRAM administratively down down
GigabitEthernet0/5 100.3.19.19 YES NVRAM up up
GigabitEthernet0/6 100.6.19.19 YES NVRAM up up
GigabitEthernet0/7 unassigned YES NVRAM administratively down down
Loopback0 150.19.19.19 YES NVRAM up up
Loopback1 1.1.1.1 YES manual up up
この記事が気に入ったらサポートをしてみませんか?