Schedule a SWIM Commit Job for Cisco XR Devices
Scenario Overview
This use case demonstrates how to schedule a SWIM (Software Image Management) job to commit new changes on Cisco XR devices. This process is typically performed after updating the software image on the device to ensure the changes are applied successfully.
The operation in the following API references is used in this example.
Prerequisites
Before running this example, ensure you have obtained an access token. For instructions on obtaining the token, refer to the 'Getting Started' section.
Schedule Commit Job for Given XR Device
Update the device ID in the xr_device_commit.json
input file as required, and run the device_commit.sh
script from the example directory.
cd cnc-swim-api-examples;./device_commit.sh
Script Details
This script reads input from the xr_device_commit.json file located in the input directory. Upon successful execution, a new commit job is scheduled and the output of job status is saved to the xr_device_commit_schedule_status.json file in the output directory.
#!/bin/bash
. ./cnc-api-common.sh
image_commit() {
# Step 1: Ensure the CNC JWT is obtained by running the get-cnc-jwt.sh script.
# Read the JWT from the file and export it as the AUTH_TOKEN_HDR environment variable.
export_jwt
# Step 2: Define the API URL, input file, and output file.
CNC_API_URL=$CNC_SWIM_API_CTX/commit
CNC_API_INPUT="@$PRJ/input/xr_device_commit.json"
CNC_API_OUTPUT="$PRJ/output/xr_device_commit_schedule_status.json"
# Step 3: Replace the `jobName` field in the input JSON with a unique name using a timestamp.
# The `jq` command modifies the input file safely.
jq --arg ts "$(date +%s)" '.swimCommitJobDTO.activateDeviceImageDetailsListDTO.jobDto.jobName = "Job_Commit_Operations_" + $ts' input/xr_device_commit.json > temp.json && mv temp.json input/xr_device_commit.json
# Step 4: Send the POST request to schedule the commit job and store the response in the output file.
http_post $CNC_API_URL $CNC_API_INPUT $CNC_API_OUTPUT
}
image_commit