Workflow to Run Precommit Scripts
The following image shows a workflow diagram representing the steps involved in using a precommit script:
Complete the following tasks to provision precommit scripts:
-
Download the script—Store the precomit script on a remote server or copy to the harddisk of the router. Add the precommit script from the server to the script management repository (hardisk:/mirror/script-mgmt) on the router using the script add precommit command.
-
Validate the script—Configure the script integrity and authenticity using the script precommit script checksum command. A script cannot be used unless the checksum is configured.
-
Activate the script—Activate the precommit script using script precommit script activate command to validate the configuration from a commit operation. The script ensures that the configuration changes comply with the predefined conditions in the script, and uncover potential errors, if any.
Note
A precommit script is invoked automatically when you commit a configuration change to modify the router configuration. You can view the result from the script execution on the console.
Download the Script to the Router
Script Type | Download Location |
---|---|
precommit |
harddisk:/mirror/script-mgmt/precommit |
config |
harddisk:/mirror/script-mgmt/config |
exec |
harddisk:/mirror/script-mgmt/exec |
process |
harddisk:/mirror/script-mgmt/process |
eem |
harddisk:/mirror/script-mgmt/eem |
-
Method 1: Add script from a server
-
Method 2: Copy script from external repository to harddisk using scp or copy command
In this section, you learn how to add precommit-bgp.py
script to the script management repository.
Before you begin
To manage the scripts, you must add the scripts to the script management repository on the router. A subdirectory is created for each script type. By default, this repository stores the downloaded scripts in the appropriate subdirectory based on script type.
Procedure
Step 1 |
Add the script to the script management repository on the router using one of the two options:
|
||
Step 2 |
Verify that the script is downloaded to the script management repository on the router. Example:
precommit-bgp.py is copied to harddisk:/mirror/script-mgmt/precommit directory on the router.
|
Configure Checksum for Precommit Script
Every script is associated with a checksum hash value. This value ensures the integrity of the script, and that the script is not tampered with. The checksum is a string of numbers and letters that act as a fingerprint for script. The checksum of the script is compared with the configured checksum. If the values do not match, the script is not run and a syslog warning message is displayed.
It is mandatory to configure the checksum to run the script.
Note |
Precommit scripts support SHA256 checksum. |
Procedure
Step 1 |
Retrieve the SHA256 checksum hash value for the script. Ideally this action would be performed on a trusted device, such as the system on which the script was created. This minimizes the possibility that the script is tampered with. However, if the router is secure, you can retrieve the checksum hash value from the IOS XR Linux bash shell. Example:
Make note of the checksum value. |
Step 2 |
View the status of the script. Example:
The You can view the details of the specific script using the show script status name script detail command. |
Step 3 |
Configure the checksum and set the priority. Example:
If you are configuring multiple scripts, the system decides an appropriate order to run the scripts. However, you can control the order in which scripts execute using a priority value. For more information on configuring the priority value, see Control Priority When Running Multiple Scripts. |
Step 4 |
Verify the status of the script. Example:
The status |
Activate Precommit Scripts
Note |
If the precommit script rejects one or more items in the configuration change, the entire configuration is rejected before committing the change. |
Before you begin
Procedure
Step 1 |
Activate the precommit script for the configuration validation to take effect. Example:
|
Step 2 |
Commit the changes and verify that the precommit script is automatically initiated. You can choose to perform one of the following options based on the requirement:
An execution report from the script is displayed on the console. If the script displays an error message, rectify the error and rerun the commit operation. If there are no validation errors, the commit operation is successful indicating that the configuration change is valid. |