Junos Automation: Display Static Routes With PyEZ Table and View

All about Juniper JET Automation Framework consists lot of APIs which helps network engineer to automate their day to day operation. The framework leverages Junos PyEZ framework which is nothing but library developed for Juniper routers. In my earlier post, I have already explained how the PyEZ can be installed in your laptop and use the library to connect your first router.

In this post, I will be covering more about Junos PyEZ tables and views. Tables and Views enable you to extract operational information and configuration data from devices running Junos OS as well as configure devices running Junos OS. When you add the Table to the Junos PyEZ framework, Junos PyEZ dynamically creates a configuration class for the resource, which you can use to programmatically configure the resource on a device. Tables and Views are defined using YAML, so no complex coding is required to create your own custom Tables and Views. Tables and Views provide a simple and efficient way to extract information from complex operational command output or configuration data and map it to a Python data structure. Operational (op) Tables select items from the RPC reply of an operational command, and configuration Tables select data from specific hierarchies in the selected configuration database. Each Table item represents a record of data and has a unique key. A Table also references a Table View, which is used to map the tag names in the data to the variable property names used within the Python module.

The below OP table retrieves output of get-route-information which corresponds to the show route protocol static extensive | display xml. The table extracts the information from the output and corresponding staticView selects two fields from each get-route-information output. The OP table has item and key, item is the xpath top level hierarchy and key is the unique value under the xpath hierarchy.

rpc: get-route-information
protocol: static
extensive: True
item: route-table/rt
key: rt-destination
view: staticView

rt_destination: rt-destination
protocol_name: rt-entry/protocol-name

Now the same code has to be saved in YAML file or we can directly call the same code in python. Below is the code what need to be run on your machine. I am using Junos PyEZ docker on my laptop to test all the functionality.

PS C:lab> docker images
juniper/pyez latest 122dff90c4db 6 days ago 279MB
PS C:lab>


Share on facebook
Share on twitter
Share on linkedin

Leave a Reply

Your email address will not be published. Required fields are marked *

Become a member

Full Access to 739 Lessons. New Lessons Added Every Week!

Awesome Deal! Get 2 Months for FREE!

No Obligations. Cancel At Any Time!