Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

Announcement: Try the Ask AI chatbot for answers to your technical questions about Juniper products and solutions.

close
header-navigation
keyboard_arrow_up
close
keyboard_arrow_left
Automation Scripting User Guide
Table of Contents Expand all
list Table of Contents
file_download PDF
{ "lLangCode": "en", "lName": "English", "lCountryCode": "us", "transcode": "en_US" }
English
keyboard_arrow_right

emit-change Template (SLAX and XSLT) and emit_change (Python)

date_range 13-Feb-21

Syntax

Python Syntax

content_copy zoom_out_map
jcs.emit_change(content, tag, format)

SLAX Syntax

content_copy zoom_out_map
call jcs:emit-change($dot=expression, $name = name($dot), $tag = "(change | transient-change)" {
    with $content = {
        ...
     }
    with $message = {
        expr "message";
     }
}

XSLT Syntax

content_copy zoom_out_map
<xsl:call-template name="jcs:emit-change">
    <xsl:with-param name="content">
        ...
    </xsl:with-param>
    <xsl:with-param name="dot" select="expression"/>
    <xsl:with-param name="message">
        <xsl:text>message</xsl:text>
    </xsl:with-param>
    <xsl:with-param name="name" select="name($dot)"/>
    <xsl:with-param name="tag" select="'(change | transient-change)'"/>
</xsl:call-template>

Description

Generate a persistent or transient change to the configuration.

Parameters

content

Content of the persistent or transient change. In SLAX and XSLT scripts, this is relative to dot. Python scripts must include the full configuration path representing all levels of the configuration hierarchy formatted as an XML string.

dot

XPath expression specifying the hierarchy level at which the change will be made. The default location is the position in the XML hierarchy that the script is currently evaluating. You can alter the default when you call the template by including a valid XPath expression either for the dot parameter in SLAX scripts or for the select attribute of the dot parameter in XSLT scripts.

format

Format of the configuration data loaded through a Python commit script. The only supported format is xml.

message

Warning message displayed in the CLI notifying the user that the configuration has been changed. The message parameter automatically includes the edit path, which defaults to the current location in the XML hierarchy. To change the default edit path, specify a valid XPath expression either for the dot parameter in SLAX scripts or for the select attribute of the dot parameter in XSLT scripts.

name

Allows you to refer to the current element or attribute. The name() XPath function returns the name of an element or attribute. The name parameter defaults to the value name($dot), which is the name of the element in dot (which in turn defaults to “ . ”, which is the current element).

tag

Type of change to generate. Specify 'change' to generate a persistent change, or specify 'transient-change' to generate a transient change. If you omit this parameter in SLAX and XSLT scripts, the jcs:emit-change template defaults to generating a persistent change.

Usage Examples

The following example demonstrates how to call the jcs:emit-change template in an XSLT commit script:

content_copy zoom_out_map
<xsl:template match="configuration">
    <xsl:for-each select="interfaces/interface/unit[family/iso]">
        <xsl:if test="not(family/mpls)">
            <xsl:call-template name="jcs:emit-change">
                <xsl:with-param name="message">
                    <xsl:text>Adding 'family mpls' to ISO-enabled interface</xsl:text>
                </xsl:with-param>
                <xsl:with-param name="content">
                    <family>
                        <mpls/>
                    </family>
                </xsl:with-param>
            </xsl:call-template>
        </xsl:if>
    </xsl:for-each>
</xsl:template>

When you commit a configuration that includes one or more interfaces that have IS-IS enabled but do not have the family mpls statement included at the [edit interfaces interface-name unit logical-unit-number] hierarchy level, the jcs:emit-change template adds the family mpls statement to the configuration and generates the following CLI output:

content_copy zoom_out_map
[edit]
user@host# commit
[edit interfaces interface so-1/2/3 unit 0]
    warning: Adding 'family mpls' to ISO-enabled interface
[edit interfaces interface so-1/2/3 unit 0]
    warning: Adding ISO-enabled interface so-1/2/3.0 to [protocols mpls]
[edit interfaces interface so-1/3/2 unit 0]
    warning: Adding 'family mpls' to ISO-enabled interface
[edit interfaces interface so-1/3/2 unit 0]
    warning: Adding ISO-enabled interface so-1/3/2.0 to [protocols mpls]
commit complete

The content parameter of the jcs:emit-change template provides a simpler method for specifying a change to the configuration. For example, consider the following code:

content_copy zoom_out_map
<xsl:with-param name="content">
    <family>
        <mpls/>
    </family>
</xsl:with-param>

In SLAX and XSLT scripts, the jcs:emit-change template converts the content parameter into a <change> request. The <change> request inserts the provided partial configuration content into the complete hierarchy of the current context node. Thus, the jcs:emit-change template changes the hierarchy information in the content parameter into the following code:

content_copy zoom_out_map
<change>
    <interfaces>
        <interface>
            <name><xsl:value-of select="name"/></name>
            <unit>
                <name><xsl:value-of select="unit/name"/></name>
                <family>
                    <mpls/>
                </family>
            </unit>
        </interface>
    </interfaces>
</change>

If a transient change is required, the tag parameter can be passed in as 'transient-change', as shown here:

content_copy zoom_out_map
<xsl:with-param name="tag" select="'transient-change'"/>

The extra quotation marks are required to allow XSLT to distinguish between the string "transient-change" and the contents of a node named "transient-change". If the change is relative to a node other than the context node, the parameter dotcan be set to that node, as shown in the following example, where context is set to the [edit chassis] hierarchy level:

content_copy zoom_out_map
<xsl:for-each select="interfaces/interface/unit">
    ...
    <xsl:call-template name="jcs:emit-change">
        <xsl:with-param name="dot" select="chassis"/>
            ...

The following Python commit script generates a persistent change to the configuration:

content_copy zoom_out_map
import jcs

if __name__ == '__main__':
    script = "system-check.py"
    change_xml = """<system><scripts><op>
                    <file><name>{0}</name></file></op>
                    </scripts></system>""".format(script)
    jcs.emit_change(change_xml, "change", "xml")
footer-navigation