O'Reilly logo

JUNOS Automation Cookbook by Adam Chappell

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How it works...

The node-list constructed in the for-each control statement is reduced when the expression is followed by square brackets. The square brackets contain the predicate function—a functional expression that must evaluate positively if the node is to be considered within the code block of the for-each control statement.

Using the second example, it's possible to filter out the extraneous Loopback interfaces displayed in our simple JUNOS virtual environment:

 adamc@router> op show-int-xpath     Interface Status    Local IP Addr           Subnet Description     em0.0     up     10.0.201.201      10.0.201/24 Management     gre.0     up          3.0.1.1         3.0.1/24      lo0.0     up         2.0.0.56                  Loopback

This is a very simple example of how to use XPath predicates to manipulate the structured data ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required