.. # # -*- indent-tabs-mode:nil -*- # # Copyright 2011-2024, Juniper Networks, Inc. # All rights reserved. # This SOFTWARE is licensed under the LICENSE provided in the # ../Copyright file. By downloading, installing, copying, or otherwise # using the SOFTWARE, you agree to be bound by the terms of that # LICENSE. # .. default-role:: code The JUISE Project ================= The JUISE project (the JUNOS User Interface Scripting Environment) allows scripts to be written, debugged, and executed outside the normal JUNOS environment. Users can develop scripts in their desktop environment, performing the code/test/debug cycle in a more natural way. Tools for developers are available, including a debugger, a profiler, a call-flow tracing mechanism, and trace files. The JUNOS-specific extension functions are available for scripts, allowing access to JUNOS XML data using the normal jcs:invoke and jcs:execute functions. Commit scripts can be tested against a JUNOS device's configuration and the results of those script tested on that device. JUISE scripts are typically written in SLAX, an alternative syntax for XSLT. For information about SLAX, refer to github.com/Juniper/libslax. Additional reference material is available under the "JUNOS Automation" at http://juniper.net. The JUISE software can be used to execute scripts independent of a JUNOS box, allowing the use of SLAX scripts in the off-box world. Scripts can communicate with zero or more devices, allowing a centralized manipulation of multiple devices. JUISE includes a rudimentary NETCONF server, allowing JUNOS devices to invoke RPCs to unix devices. JUNOS devices can perform NETCONF or JUNOScript RPCs to a JUISE box, and invoke scripts or programs on that device. JUISE includes "mod_juise", a plug-in module for lighttpd, allowing the execution of scripts via HTTP. At this point, the portion of JUISE is completely experimental. Getting JUISE ------------- JUISE is available as an open-source project via google code using the following URL: https://github.com/Juniper/juise Refer to the ./README file for building instructions. Note that juise has a number of prerequisite software packages, including libxslt, libxml2, libpcre, libslax, and others. The "juise" Command =================== The "juise" command is the central program of the JUISE project. It is used to test, format, convert, debug, and execute scripts. The "juise" command has four distinct usage patterns, which are discussed in this section. - op script mode - commit script mode - server mode - cgi mode .. _syntax: Command Syntax -------------- The `juise` command line interface is as follows:: Usage: juise [[user]@target] [options] [script] [param value]* The `juise` command is normally invoked with the name of the script to be run, a set of options are used to tailor the execution of the script, and a set of name/value parameter pairs that are passed as parameters to the script, as they are for the JUNOS "op" command. The Target Argument ------------------- If the first non-option argument contains an `'@'` and the `--target` option is not present, the argument will be taken as the default target. This value will be used as the "local" device for configuration retrieval and for any `jcs:open()` call that does not provide an explicit target. This argument can be either "user@device" or "@device" (with the current login name used as the user name). :: juise my-login@my-router ... juise @my-router ... Commit Scripts ============== This section describes how commit scripts can be used inside juise. .. _history: Overview (Function and History) ------------------------------- Commit scripts were introduced in `JUNOS-7.2` as a means of adding custom rules to the `commit check` process, allowing customers to define additional validation rules which the incoming configuration must satisfy. Commit scripts can find and report configuration statements that do not follow these rules. Commit script can also change the configuration in two distinct ways. Normal changes are added to the candidate configuration before it is passed to the rest of the JUNOS subcomponents for validation. These changes are normal parts of the configuration data set. In contrast, transient changes are not part of the normal configuration data set, since they are not visible in the candidate configuration nor are they saved in rollback data sets. But they are exposed to JUNOS subcomponents during validation, allowing the commit script to create second order configuration information based on the first order data in the candidate configuration. The typical commit script relies heavily upon XPath to find errant configuration. They typically follow the pattern:: if (xpath/to/find/bad/config) { report bad config; } or:: for-each (some/list/that/needs/to/be/checked) { if (xpath/to/find/bad/config) { report bad config; } } Consider this example:: version 1.1; import "../import/junos.xsl"; match configuration { var $ldp = protocols/ldp; var $isis = protocols/isis; var $ospf = protocols/ospf; for-each ($isis/interface/name | $ospf/area/interface/name) { var $ifname = .; if (not($ldp/interface[name == $ifname])) { { call jcs:edit-path(); call jcs:statement(); "ldp not enabled for this interface"; } } } } This script looks for interfaces listed under [protocols isis] and [protocols ospf] to find interfaces not listed under [protocols ldp]. When such interfaces are found, an error is generated. The UI sees this error and stops the configuration from being validated. Testing Commit Scripts ---------------------- juise can be used to test commit scripts by using the `-c` option. The target device can be given with either the `--target` (`-T`) option. If no target is given and the first argument contains an `@`, then this is used as the target. :: % juise -c me@my-router my-script.slax To execute the commit script, juise tries to reproduce the environment which the script would run under JUNOS. juise starts by downloading the configuration in the same format used by on-box commit scripts, with expanded inheritance and group and change attributes. This configuration is wrapped in an input document (the `` element) to be passed to the script. The wrapper is identical to the JUNOS wrapper, complete with the `` element. The `` element is passed as input to the script, which runs normally, inspecting the configuration and generating, ``, ``, ``, ``, and `` elements as needed. The results of the script are inspected, and any and `` elements are uploaded to a `edit private` session. Any errors are reported to the user. The results of these interactions with the device are displayed in XML to aid with debugging scripts. If no errors have occurred, then any changes to the configuration can be retrieved and reported to the user, who can verify that the changes are those desired. Use the "--output-format