Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Howto examples: https://cnaas-nms.readthedocs.io/en/latest/howto/index.html

Reference documentation: https://cnaas-nms.readthedocs.io/en/latest/apiref/index.html

Browsable API documentation: https://${CNAASURL}/api/doc/ (see customer documentation)


Authentication:

  1. Go to WebUI and "Copy JWT" in top right corner under profile, use Authorization header with contents "Bearer <copied-jwt-token>"
  2. Add a new OAuth client and use client credentials auth for long-running scripts

Getting started

CNaaS NMS exposes a standard REST-like JSON API. In these examples we will use curl to do some basic management operations.

List devices

curl http://10.0.1.5:5000/api/v1.0/device
curl http://10.0.1.5:5000/api/v1.0/device?filter=hostname,ex2300-top
curl http://10.0.1.5:5000/api/v1.0/device?filter=device_type,ACCESS

Update settings for devices

Clone your settings repository in to a local directory. In this example we will use the CNaaS provided example setting repository from github:

git clone https://github.com/SUNET/cnaas-nms-settings
cd cnaas-nms-settings
vim access/base_system.yml
<do some changes, save file>
git commit -a -m "Updated setting for XYZ for access devices"
git push

Tell the NMS API to fetch latest updates from the settings repo and try a sync to devices with dry_run to preview changes:

curl http://10.0.1.5:5000/api/v1.0/repository/settings -d '{"action": "refresh"}' -X PUT -H "Content-Type: application/json"
curl http://10.0.1.5:5000/api/v1.0/device_syncto -d '{"hostname": "ex2300-top", "dry_run": true}' -X POST -H "Content-Type: application/json"
curl http://10.0.1.5:5000/api/v1.0/job?limit=1

The API call to device_syncto will start a job running in the background on the API server. To show the progress/output of the job run the last command (/job) until you get a finished result.

Zero-touch provisioning of access switch

Power on switch, wait for it to boot using DHCP. List new devices that has booted using CNaaS startup config:

curl http://10.0.1.5:5000/api/v1.0/device?filter=state,DISCOVERED

If the device serial/MAC matches with a device you want to provision, call the API to initialize the device with a specified hostname and device type:

curl http://10.0.1.5:5000/api/v1.0/device_init/20 -d '{"hostname": "ex2300-top", "device_type": "ACCESS"}' -X POST -H "Content-Type: application/json"

Check job status to see progress, there should be two jobs running after each other, step1 and step2.

...