Getting Started

This guide provides developers with scenarios and examples to demonstrate workflows and the sequence of API execution for Inventory Retrieval, Collection, and Job-related operations.

Prerequisites

Before using the examples, set up CNC with the required release, applications, and NSO with onboarded devices. For details, refer to the CNC Installation and Administration guides.

Download and Set Up Example Scripts

Follow these instructions to set up the scripts to execute against the target CNC setup.

  1. Download the example scripts using the link cnc-inventory-api-examples.tar.gz and unzip in user home directory.
  2. Configure the environment variables in the cnc-inventory-api-examples/env file by updating the target Crosswork Network Controller server host, port, and user credentials.
  3. Obtain the JWT by running the get-cnc-jwt.sh script to authenticate API calls.
  4. Run the use-case scripts for desired operations, updating the input files as needed.

Authentication and Authorization

Accessing the CNC Northbound (NB) API requires both authentication and authorization. CNC uses JWT-based authentication, acquired through a two-step process. API level access control and Role-Based Access Control (RBAC) defined and configured in CNC manage the authorization of each API.

Script Details

get_jwt() {
    # Getting a JWT to use in CNC API authentication is a two-step process:
    # Step 1. Get the Ticket Granting Ticket (TGT)
    # Step 2. Use the TGT to get the JWT
 
    # Step 1. Invoke this url with the username,password in the post payload
    export CNC_API_TGT_URL="https://$CNC_HOST:$CNC_PORT/crosswork/sso/v1/tickets"
    response=$(curl $CURL_OPTS -X POST $CNC_API_TGT_URL \
    -H 'Content-Type: application/x-www-form-urlencoded' \
    -H 'Accept: text/plain' \
    -d "username=${CNC_USER}&password=${CNC_PASSWORD}" \
    )

    # Step 2: Invoke the JWT url with the JWT and forward the service url in the POST payload
    export CNC_API_JWT_URL="https://$CNC_HOST:$CNC_PORT/crosswork/sso/v2/tickets/jwt"
    response=$(curl $CURL_OPTS -X POST $CNC_API_JWT_URL \
    -H 'Content-Type: application/x-www-form-urlencoded' \
    -d "tgt=$response&service=https://$CNC_HOST:$CNC_PORT/app-dashboard" \
    )
 
    # Step 3. Only for the purpose of the example: store it in ~/.cnc-jwt file
    echo $response > $CNC_JWT_FILE
 
}
get_jwt

Example Script Environment Variables

The example scripts define a set of environment variables that are required to run use-case scripts. These variables include CNC server information (host, port, credentials) and root contexts for API endpoints. Ensure that the environment variables are correctly configured before running the scripts.

  1. CNC Server information (host, port, and user credentials) - cnc-inventory-api-examples/env
  2. To reuse root contexts for the API endpoints - cnc-inventory-api-examples/cnc-api-commons.sh
# Standard CNC URL ROOT CONTEXTS
# Inventory API Endpoint Root Context
export CNC_INVENTORY_API_CTX="https://$CNC_HOST:$CNC_PORT/crosswork/inventory/v1/networkelement"
# Job API Endpoint Root Context
export CNC_INVENTORY_JOB_API_CTX="https://$CNC_HOST:$CNC_PORT/crosswork/rs/json/jobSchedulerServiceInv/v1"