Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

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

Create a Commit Script Macro to Read the Custom Syntax and Generate Related Configuration Statements

date_range 19-Nov-24
  1. At the start of the script, include the appropriate commit script boilerplate from Required Boilerplate for Commit Scripts. It is reproduced here for convenience:
    XSLT Boilerplate
    content_copy zoom_out_map
    <?xml version="1.0" standalone="yes"?>
    <xsl:stylesheet version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
        xmlns:junos="http://xml.juniper.net/junos/*/junos" 
        xmlns:xnm="http://xml.juniper.net/xnm/1.1/xnm" 
        xmlns:jcs="http://xml.juniper.net/junos/commit-scripts/1.0">
        <xsl:import href="../import/junos.xsl"/>
     
        <xsl:template match="configuration">
            <!-- ... insert your code here ... -->
        </xsl:template>
    </xsl:stylesheet>
    SLAX Boilerplate
    content_copy zoom_out_map
    version 1.2;
    ns junos = "http://xml.juniper.net/junos/*/junos";
    ns xnm = "http://xml.juniper.net/xnm/1.1/xnm";
    ns jcs = "http://xml.juniper.net/junos/commit-scripts/1.0";
    import "../import/junos.xsl";
     
    match configuration {
        /*
        * insert your code here
        */
    }
    Python Boilerplate
    content_copy zoom_out_map
    from junos import Junos_Configuration
    import jcs
    
    if __name__ == '__main__':
        # insert your code here
  2. At the position indicated by the comment “insert your code here,” include programming instructions that inspect the configuration for the apply-macro statement at a specified hierarchy level and change the configuration to include standard Junos OS syntax.

    For an example that uses both types of instructions and includes a line-by-line analysis of the XSLT syntax, see Example: Creating Custom Configuration Syntax with Commit Script Macros.

  3. Save the script with a meaningful name.
  4. Copy the script to either the /var/db/scripts/commit directory on the hard disk or the /config/scripts/commit directory on the flash drive.

    For information about setting the storage location for commit scripts, see Store and Enable Junos Automation Scripts and Store Scripts in Flash Memory.

  5. Enable the script by configuring the file filename statement at the [edit system scripts commit] hierarchy level.
    content_copy zoom_out_map
    [edit system scripts]
    user@host# set commit file filename
    
  6. If the script generates transient changes, configure the allow-transients statement.

    Configure the statement at the [edit system scripts commit] hierarchy level to enable all commit scripts to make transient changes.

    content_copy zoom_out_map
    [edit system scripts]
    user@host# set commit allow-transients
    

    Alternatively, on supported devices and releases, configure the statement at the [edit system scripts commit file filename] hierarchy level to enable only the individual script to make transient changes.

    content_copy zoom_out_map
    [edit system scripts]
    user@host# set commit file filename allow-transients
    
  7. If the script is written in Python, enable the execution of unsigned Python scripts.
    content_copy zoom_out_map
    [edit system scripts]
    user@host# set language (python | python3)
    
  8. Commit the configuration.
    content_copy zoom_out_map
    [edit system scripts]
    user@host# commit and-quit
    
footer-navigation