Python 自動化スクリプトでの IPv6 サポート
Junos OS リリース 19.3R1 以降、コミット、イベント、op、SNMP スクリプト、Juniper Extension Toolkit(JET)スクリプト、YANG アクション スクリプトなど、Python 自動化スクリプトで IPv6 を使用した Junos OS とアップグレードされた FreeBSD のサポートを実行しているデバイス。IPv6 のサポートにより、Python 自動化スクリプトで接続を確立し、IPv6 アドレスを使用して操作を実行できます。
例えば、以下のopスクリプトでは、Junos PyEZを使用して、指定されたIPv6アドレスのホストに接続し、デバイスのホスト名とge-0/0/0インターフェイスに関する情報を印刷します。このスクリプトは、スクリプト入力からユーザー名を取得し、ユーザーのパスワードを入力するよう求めます。
from jnpr.junos import Device
from lxml import etree
from junos import Junos_Context
import jcs
user = Junos_Context['user-context']['user']
password = jcs.get_secret('Enter user password: ')
try:
with Device(host='2001:db8::2', user=user, password=password) as dev:
print (dev.facts['hostname'])
int_info = dev.rpc.get_interface_information({'format':'text'},
interface_name='ge-0/0/0', terse=True)
print (etree.tostring(int_info, encoding='unicode'))
except Exception as err:
print (err)
スクリプトを実行するには、 または language python3 ステートメントとスクリプトファイル名を設定language pythonします。
[edit] user@host# set system scripts language python3 user@host# set system scripts op file connect-ipv6.py user@host# commit and-quit
このスクリプトを実行すると、リモートデバイスのホスト名とge-0/0/0インターフェイスに関する情報が印刷されます。
user@host> op connect-ipv6.py
Enter user password:
r2
<output>
Interface Admin Link Proto Local Remote
ge-0/0/0 up up
ge-0/0/0.0 up up inet6 2001:db8::2/32
fe80::5668:a3ff:fe16:79ef/64
multiservice
</output>