IPv6 Support in Python Automation Scripts
Starting in Junos OS Release 19.3R1, devices running Junos OS with upgraded FreeBSD support using IPv6 in Python automation scripts, including commit, event, op, and SNMP scripts, Juniper Extension Toolkit (JET) scripts, and YANG action scripts. IPv6 support enables Python automation scripts to establish connections and perform operations using IPv6 addresses.
For example, the following op script uses Junos PyEZ to connect to the host at the specified IPv6 address and print the device hostname and information about the ge-0/0/0 interface. The script retrieves the username from the script inputs and prompts for the user’s password.
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)
To execute the script, configure the language python
or language python3
statement and the script filename.
[edit] user@host# set system scripts language python3 user@host# set system scripts op file connect-ipv6.py user@host# commit and-quit
When you execute the script, it prints the hostname of the remote device and information about the ge-0/0/0 interface.
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>