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 

['RESPONSE_RETURN', 'RETURN', 'TELNET_RETURN', '__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__enter__', '__eq__', '__exit__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_autodetect_fs', '_build_ssh_client', '_connect_params_dict', '_first_line_handler', '_lock_netmiko_session', '_modify_connection_params', '_open', '_read_channel', '_read_channel_expect', '_read_channel_timing', '_sanitize_output', '_session_locker', '_session_log_close', '_session_log_fin', '_test_channel_read', '_timeout_exceeded', '_try_session_preparation', '_unlock_netmiko_session', '_use_ssh_config', '_write_channel', '_write_session_log', 'allow_agent', 'allow_auto_change', 'alt_host_keys', 'alt_key_file', 'ansi_escape_codes', 'auth_timeout', 'banner_timeout', 'base_prompt', 'blocking_timeout', 'check_config_mode', 'check_enable_mode', 'cleanup', 'clear_buffer', 'close_session_log', 'commit', 'config_mode', 'device_type', 'disable_paging', 'disconnect', 'enable', 'encoding', 'establish_connection', 'exit_config_mode', 'exit_enable_mode', 'fast_cli', 'find_prompt', 'global_delay_factor', 'host', 'is_alive', 'keepalive', 'key_file', 'key_policy', 'normalize_cmd', 'normalize_linefeeds', 'open_session_log', 'paramiko_cleanup', 'passphrase', 'password', 'pkey', 'port', 'protocol', 'read_channel', 'read_until_pattern', 'read_until_prompt', 'read_until_prompt_or_pattern', 'remote_conn', 'remote_conn_pre', 'save_config', 'secret', 'select_delay_factor', 'send_command', 'send_command_expect', 'send_command_timing', 'send_config_from_file', 'send_config_set', 'serial_login', 'serial_settings', 'session_log', 'session_log_record_writes', 'session_preparation', 'session_timeout', 'set_base_prompt', 'set_terminal_width', 'special_login_handler', 'ssh_config_file', 'strip_ansi_escape_codes', 'strip_backspaces', 'strip_command', 'strip_prompt', 'system_host_keys', 'telnet_login', 'timeout', 'use_keys', 'username', 'verbose', 'write_channel']

>>> dir(R19)


この記事が気に入ったらサポートをしてみませんか?