Getting Started

This guide provides an example usage of the API based on user scenarios. The examples in the guide demonstrate how to integrate external systems with CNC and serve as a reference. The Scenarios and examples in this guide demonstrates API execution for Topology - Retrieval operations.

Prerequisites

Before using the examples, ensure that CNC is set up with the required release, applications, SR-PCE, and onboarded devices.

Download and set up example scripts

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

  1. Download cnc-topology-api-examples.tar.gz and unzip it in the user home directory to access the example scripts referenced in this guide.
  2. Edit cnc-topology-api-examples/env file to update the target CNC server host, port, and user credentials.
  3. Invoke the get-cnc-jwt.sh to obtain the jwt for authenticating the API calls.
  4. Invoke each use case script.

Authentication and Authorization

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

Script Details

get_jwt() {
    # getting 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 forwarding 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 example purpose. store it in ~/.cnc-jwt file
    echo $response > $CNC_JWT_FILE
 
}
get_jwt

Example Script Environment Variables

The example script defines a set of environment variables that are needed to run the use case scripts.

  1. To learn the CNC Server host, port and user credentials - in cnc-topology-api-examples/env

  2. To reuse the API endpoints root contexts - in cnc-topology-api-examples/cnc-api-commons.sh

# standard CNC NBI URL ROOT CONTEXT
export CNC_TOPOLOGY_API_CTX="https://$CNC_HOST:$CNC_PORT/crosswork/nbi/topology/v3/restconf/data"