Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

close
keyboard_arrow_left
Junos PyEZ Developer Guide
Table of Contents Expand all
list Table of Contents
file_download PDF
keyboard_arrow_right

Use Junos PyEZ Operational Tables and Views that Parse Unstructured Output

date_range 19-Aug-22

Junos PyEZ operational (op) Tables for unstructured output extract data from the text output of a CLI command executed on a Junos device or a vty command executed on a given Flexible PIC Concentrator (FPC). After loading or importing the Table definition into your Python module, you can retrieve the Table items and extract and manipulate the data.

To retrieve information from a specific device, you must create a Table instance and associate it with the Device object representing the target device. For example:

content_copy zoom_out_map
from jnpr.junos import Device
from jnpr.junos.command.ospf_neighbor import OspfNeighborTable

with Device(host='router.example.com') as dev:
    stats = OspfNeighborTable(dev)

To use the Table in your Junos PyEZ application to execute the command and retrieve the data, call the Table’s get() method and supply any required or optional parameters. If the Table defines default arguments, for example, for the args, filters, key_items, or target parameters, the get() method uses these defaults unless you override them in the argument list.

content_copy zoom_out_map
from jnpr.junos import Device
from jnpr.junos.command.ospf_neighbor import OspfNeighborTable
from pprint import pprint
import json

with Device(host='router.example.com') as dev:
    stats = OspfNeighborTable(dev)
    stats.get()
    pprint(json.loads(stats.to_json())) 
external-footer-nav