Getting Started
This guide provides an example usage of the API based on user scenarios. The examples provided in the guide are for demonstration purpose which can be used as a reference for external systems integration with CNC. The Scenarios and examples in this guide demonstrates activate geo mode, get geo inventory, and get geo mode status API execution for geo redundancy feature.
Prerequisites
Before using any examples provided in this guide, it is expected that the user has set up the CNC with corresponding release version, deploy a geo redundacny setup (active, standby, and arbiter clusters).
Download and set up example scripts
Follow these instructions to set up the scripts to execute agaist the target CNC setup.
- Download cnc-geo-redundancy-api-examples.tar.gz and unzip in user home directory for the example scripts used in this guide.
- Edit cnc-geo-redundancy-api-examples/env file to update the target CNC server host, port and user credentials
- Invoke the get-cnc-jwt.sh to obtain the jwt for authenticating the api calls
- Invoke each usecase script after optionally updating the input files according to the cnc environemnt.
Authentication and Authorization
Accessing the CNC NB API requires Authentication and Authorization. CNC uses a JWT based authentication which can be obtained using two-step process. Authorization of each API is controlled by API level access control as well as Role Based Access Control (RBAC) defined and configured in CNC.
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 necessary to run the use case scripts.
- To learn the CNC Server host, port and user credentials - in
cnc-geo-redundancy-api-examples/env
. - To reuse the API endpoints root contexts - in
cnc-geo-redundancy-api-examples/cnc-api-commons.sh
.
# Standard CNC URL ROOT CONTEXTS
# Crosscluster API Endpoint Root Context
export CNC_GEO_REDUNDANCY_API_CTX="https://$CNC_HOST:$CNC_PORT/crosswork/platform/v2/georedundancy"