目的
TextFSMを使用して出力させたい。
環境
◇対象機器
機種:Canalyst 3560E-UNIVERSALK9-M
バージョン:15.2(4)E1
◇以下のURLからntc-templatesはダウンロード済み。
https://github.com/networktocode/ntc-templates
解凍したntc-templatesはユーザディレクトリに格納済み。
◇textfsmもインストール済み。
以下pip listの出力結果。
Package Version ------------ ------- bcrypt 3.1.7 cffi 1.14.0 cryptography 2.8 future 0.18.2 netmiko 3.0.0 paramiko 2.7.1 pycparser 2.19 PyNaCl 1.3.0 pyserial 3.4 scp 0.13.2 six 1.14.0 textfsm 1.1.0
想定結果
sh ip intの結果がリストの形で出力される。
現状
以下のエラーが表示される。
Traceback (most recent call last): File "python-ssh2.py", line 18, in <module> output = net_connect.send_command("sh ip int", use_textfsm=True) File "ファイルのパスnetmiko\base_connection.py", line 1424, in send_command template=textfsm_template, File "ファイルのパス\netmiko\utilities.py", line 276, in get_structured_data template_dir = get_template_dir() File "ファイルのパス\netmiko\utilities.py", line 229, in get_template_dir raise ValueError(msg) ValueError: Valid ntc-templates not found, please install https://github.com/networktocode/ntc-templates and then set the NET_TEXTFSM environment variable to point to the ./ntc-templates/templates directory.
コード
from netmiko import ConnectHandler from pprint import pprint my_device = { "device_type": "cisco_ios", 'ip':'IPアドレス', 'username':'アカウント', 'password':'ログインパスワード', 'secret':'特権パスワード', } net_connect = ConnectHandler(**my_device) net_connect.enable() output = net_connect.send_command("sh ip int", use_textfsm=True) pprint(output)
エラー文に記載されていた以下2つのファイルを確認してはいるのですが、原因が掴めず。。。
対象行をピックアップしました。
base_connection.py
※1424行目
# If both TextFSM and Genie are set, try TextFSM then Genie if use_textfsm: structured_output = get_structured_data( output, platform=self.device_type, command=command_string.strip(), template=textfsm_template, ←1424行目 )
utilities.py
※229行目
raise ValueError(msg) ←229行目 return os.path.abspath(template_dir)
※276行目
if template is None: if attrs == {}: raise ValueError( "Either 'platform/command' or 'template' must be specified." ) template_dir = get_template_dir() ←276行目 index_file = os.path.join(template_dir, "index") textfsm_obj = clitable.CliTable(index_file, template_dir) return _textfsm_parse(textfsm_obj, raw_output, attrs) else: template_path = Path(os.path.expanduser(template)) template_file = template_path.name template_dir = template_path.parents[0] # CliTable with no index will fall-back to a TextFSM parsing behavior textfsm_obj = clitable.CliTable(template_dir=template_dir) return _textfsm_parse( textfsm_obj, raw_output, attrs, template_file=template_file )
グエー(_)
一体何が原因ナンダー(_)
どなたかお助けくださいー(T_T)
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。