Use Junos PyEZ Operational Tables and Views that Parse Unstructured Output
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:
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.
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()))