Retrieve a List of Images from the Crosswork Network Controller Server"

This guide explains how to retrieve a list of software images stored on the CNC SWIM server. These images can be used in various SWIM operations, such as distribution and activation.

The operation in the following API references is used in this example.

Prerequisites

Before running this example, ensure that you have obtained an access token. Refer to the 'Getting Started' section of the CNC SWIM API documentation for instructions on obtaining the token.

Retrieve the List of Images on the CNC Server

To retrieve the list of images stored on the CNC server, run the image_query.sh script from the example directory. The results will be stored in the output file specified in the script.

Navigate to the cnc-swim-api-examples directory and run the image_query.sh script using the following command:

cd cnc-swim-api-examples;./image_query.sh

Script Details

Upon successful execution, the uploaded images in CNC are returned and the output is saved to the images.json file in the output directory.

#!/bin/bash
# Import common API functions and environment variables
. ./cnc-api-common.sh

image_query() {
    # 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 : Find the device count on CNC server and store the output in CNC_API_OUTPUT file
    CNC_API_URL=$CNC_SWIM_API_CTX/images
    CNC_API_OUTPUT="$PRJ/output/images.json"
    
    # Step 3: Send a GET request to retrieve the list of images and store the response in the output file.
    http_get $CNC_API_URL $CNC_API_OUTPUT
}
image_query