Junos automation requires a communication method so that scripts can instruct Junos to perform desired actions. For example, the Hello World script causes Junos to display “Hello World!” on the console. In the Hello World script from the second chapter, the
<output> element within the result tree provides this request.
Understanding the result tree:
The result tree is a XML data structure created by the processing of the script and delivered to the script engine after the script terminates. During operation, the script specifies the XML elements to include in the result tree. Once the script has finished, Junos follows the instructions of the completed result tree.
Writing to the result tree:
XML elements are simply embedded within the SLAX script in the abbreviated XML format. When the script engine arrives at a line that consists of a XML element it automatically attaches that element into the result tree.
<op-script-results> is an XML element with a child element of
<output>. When the script engine begins executing the script it reaches this XML data structure, recognizes these as XML elements, and writes them to the result tree as:
<output> "Hello World!";
The parent element in the example above is
<op-script-results>. This is always the top-level element in an op script result tree. This element indicates to Junos that instructions are coming from an op script. There is no action performed by the
<op-script-results> element, it simply contains the child elements. It is the child elements that provide instructions for Junos to process.
<output> element is the most common element found in the result tree of op scripts. As the name implies, it outputs an associated string. Specifically, it instructs Junos to display the string to the console followed by a line-feed. A script can include multiple
<output> elements as shown in the code to the right, which prints two lines on output in the console when run.