実現したいこと
- YAMAHAのRTX1200にPythonライブラリであるnetmikoを用いてconfigを適用する。
現状
CISCO機器に対してはenable()で特権モードになりconfigを適用できるが、YAMAHA機器ではenable()で特権モードになった後から進まない。
発生している問題・エラーメッセージ
enable()でエラーが出ています。
Traceback (most recent call last): File "C:\Users\user\netmiko\yamaha2.py", line 29, in <module> net_connect.enable() File "C:\Users\user\anaconda3\lib\site-packages\netmiko\yamaha\yamaha.py", line 28, in enable return super().enable( File "C:\Users\user\anaconda3\lib\site-packages\netmiko\base_connection.py", line 2008, in enable output += self.read_until_prompt() File "C:\Users\user\anaconda3\lib\site-packages\netmiko\base_connection.py", line 812, in read_until_prompt return self.read_until_pattern( File "C:\Users\user\anaconda3\lib\site-packages\netmiko\base_connection.py", line 721, in read_until_pattern raise ReadTimeout(msg) netmiko.exceptions.ReadTimeout: Pattern not detected: '>' in output. Things you might try to fix this: 1. Adjust the regex pattern to better identify the terminating string. Note, in many situations the pattern is automatically based on the network device's prompt. 2. Increase the read_timeout to a larger value. You can also look at the Netmiko session_log or debug log for more information.
セッションログ
RTX1200 Rev.10.01.78 (Wed Nov 13 16:29:42 2019) Copyright (c) 1994-2019 Yamaha Corporation. All Rights Reserved. Copyright (c) 1991-1997 Regents of the University of California. Copyright (c) 1995-2004 Jean-loup Gailly and Mark Adler. Copyright (c) 1998-2000 Tokyo Institute of Technology. Copyright (c) 2000 Japan Advanced Institute of Science and Technology, HOKURIKU. Copyright (c) 2002 RSA Security Inc. All rights reserved. Copyright (c) 1997-2010 University of Cambridge. All rights reserved. Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura, All rights reserved. Copyright (c) 1995 Tatu Ylonen , Espoo, Finland All rights reserved. Copyright (c) 1998-2004 The OpenSSL Project. All rights reserved. Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) All rights reserved. Copyright (c) 2006 Digital Arts Inc. All Rights Reserved. Copyright (C) 1994-2012 Lua.org, PUC-Rio. Copyright (c) 1988-1992 Carnegie Mellon University All Rights Reserved. Copyright (C) 2004-2007 Diego Nehab. All rights reserved. Copyright (c) 2005 JSON.org 00:a0:de:69:82:9d, 00:a0:de:69:82:9e, 00:a0:de:69:82:9f Memory 128Mbytes, 3LAN, 1BRI > > > console lines infinity > ********istrator Password: #
netmikoのログ
RTX1200 Rev.10.01.78 (Wed Nov 13 16:29:42 2019) Copyright (c) 1994-2019 Yamaha Corporation. All Rights Reserved. Copyright (c) 1991-1997 Regents of the University of California. Copyright (c) 1995-2004 Jean-loup Gailly and Mark Adler. Copyright (c) 1998-2000 Tokyo Institute of Technology. Copyright (c) 2000 Japan Advanced Institute of Science and Technology, HOKURIKU. Copyright (c) 2002 RSA Security Inc. All rights reserved. Copyright (c) 1997-2010 University of Cambridge. All rights reserved. Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura, All rights reserved. Copyright (c) 1995 Tatu Ylonen , Espoo, Finland All rights reserved. Copyright (c) 1998-2004 The OpenSSL Project. All rights reserved. Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) All rights reserved. Copyright (c) 2006 Digital Arts Inc. All Rights Reserved. Copyright (C) 1994-2012 Lua.org, PUC-Rio. Copyright (c) 1988-1992 Carnegie Mellon University All Rights Reserved. Copyright (C) 2004-2007 Diego Nehab. All rights reserved. Copyright (c) 2005 JSON.org 00:a0:de:69:82:9d, 00:a0:de:69:82:9e, 00:a0:de:69:82:9f Memory 128Mbytes, 3LAN, 1BRI > > DEBUG:netmiko:Pattern found: ([>#]) RTX1200 Rev.10.01.78 (Wed Nov 13 16:29:42 2019) Copyright (c) 1994-2019 Yamaha Corporation. All Rights Reserved. Copyright (c) 1991-1997 Regents of the University of California. Copyright (c) 1995-2004 Jean-loup Gailly and Mark Adler. Copyright (c) 1998-2000 Tokyo Institute of Technology. Copyright (c) 2000 Japan Advanced Institute of Science and Technology, HOKURIKU. Copyright (c) 2002 RSA Security Inc. All rights reserved. Copyright (c) 1997-2010 University of Cambridge. All rights reserved. Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura, All rights reserved. Copyright (c) 1995 Tatu Ylonen , Espoo, Finland All rights reserved. Copyright (c) 1998-2004 The OpenSSL Project. All rights reserved. Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) All rights reserved. Copyright (c) 2006 Digital Arts Inc. All Rights Reserved. Copyright (C) 1994-2012 Lua.org, PUC-Rio. Copyright (c) 1988-1992 Carnegie Mellon University All Rights Reserved. Copyright (C) 2004-2007 Diego Nehab. All rights reserved. Copyright (c) 2005 JSON.org 00:a0:de:69:82:9d, 00:a0:de:69:82:9e, 00:a0:de:69:82:9f Memory 128Mbytes, 3LAN, 1BRI > DEBUG:netmiko:read_channel: DEBUG:netmiko:Clear buffer detects data in the channel DEBUG:netmiko:read_channel: DEBUG:netmiko:write_channel: b'\n' DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: > DEBUG:netmiko: Parenthesis found in pattern. pattern: (\#|>) This can be problemtic when used in read_until_pattern(). You should ensure that you use either non-capture groups i.e. '(?:' or that the parenthesis completely wrap the pattern '(pattern)' DEBUG:netmiko:Pattern found: (\#|>) > DEBUG:netmiko:read_channel: DEBUG:netmiko:Clear buffer detects data in the channel DEBUG:netmiko:read_channel: DEBUG:netmiko:[find_prompt()]: prompt is > DEBUG:netmiko:In disable_paging DEBUG:netmiko:Command: console lines infinity DEBUG:netmiko:write_channel: b'console lines infinity\n' DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: console DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: lines infinity DEBUG:netmiko:Pattern found: (console\ lines\ infinity) console lines infinity DEBUG:netmiko:console lines infinity DEBUG:netmiko:Exiting disable_paging DEBUG:netmiko:read_channel: > DEBUG:netmiko:Clear buffer detects data in the channel DEBUG:netmiko:read_channel: DEBUG:netmiko:write_channel: b'********istrator\n' DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: ********istrator DEBUG:netmiko:Pattern found: (********istrator) ********istrator DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: Password: DEBUG:netmiko:Pattern found: ((?:>|Password)) Password DEBUG:netmiko:write_channel: b'********\n' DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: # DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel:
該当のソースコード
ネット上に公開されているものを少し改変しました。
Python
1from __future__ import print_function, unicode_literals 2 3# Netmiko is the same as ConnectHandler 4from netmiko import Netmiko 5from getpass import getpass 6 7import datetime 8import logging 9 10logging.basicConfig(filename='netmiko_global.log', level=logging.DEBUG) 11logger = logging.getLogger("netmiko") 12 13now = datetime.datetime.today() 14filename = now.strftime('%Y%m%d_%H%M%S') + '.log' 15 16device = { 17 "host": "xxx.xxx.xxx.xxx", 18 "username": "xxx", 19 "password": "xxx", 20 "secret": "xxx", 21 "port": "xxx", 22 "global_delay_factor": 2, 23 "device_type": "yamaha", 24 "session_log": filename, 25} 26 27# connect 28net_connect = Netmiko(**device) 29net_connect.enable() 30 31#send show command (before) 32output = net_connect.send_command("show status lan1") 33print('---------------before log---------------', output, sep='\n') 34 35# change ip address 36config_commands = ['ip lan1 address 10.10.1.1/24','save','exit'] 37output = net_connect.send_config_set(config_commands) 38print('---------------change config---------------', output, sep='\n') 39 40# send show command (after) 41output = net_connect.send_command("show status lan1") 42print('---------------after log---------------', output, sep='\n') 43 44# save config 45output = net_connect.save_config() 46print('---------------save config---------------', output, sep='\n') 47 48# disconnect 49net_connect.disconnect()
試したこと
Netmikoの再インストール。
補足情報
Netmiko Version 4.2.0
Python 3.10.9
Windows11
原因が全く分からないので、アドレスお願いします。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。