ON THIS PAGE
emit-change Template (SLAX and XSLT) and emit_change (Python)
Syntax
Python Syntax
jcs.emit_change(content, tag, format)
SLAX Syntax
call jcs:emit-change($dot=expression, $name = name($dot), $tag = "(change | transient-change)" { with $content = { ... } with $message = { expr "message"; } }
XSLT Syntax
<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 |
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 |
format |
Format of the configuration data loaded
through a Python commit script. The only supported format is |
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 |
name |
Allows you to refer to the current element or attribute.
The |
tag |
Type of change to generate. Specify |
Usage Examples
The following example demonstrates how to call the jcs:emit-change
template in an XSLT commit script:
<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:
[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:
<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:
<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:
<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 dot
can be set to that node,
as shown in the following example, where context is set to the [edit chassis]
hierarchy level:
<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:
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")