This example shows how you can interact with NSO through Restconf APIs using the requests
python library.
The example is designed to be executed on the NSO Playground but any local install will work as long as the specific environment variables are set.
To start experimenting with the example you can:
The example will be automatically cloned on the playground, ready to test.
Once the playground is ready you can skip to the Build the environment part. When you run the make -C $REPO_DIR build
command, it will both create netsims and spin up the NSO instance.
The script updates the DNS server configuration of a netsim device using the yang model and template created for this example. The outputs of the calls are printed to the terminal.
It performs the following steps:
sync-from
.1.1.1.1
to ex1
.2.2.2.2
to ex1
.2.2.2.2
to ex1
.3.3.3.3
to ex1
.3.3.3.3
to ex1
.During the execution the script will print the results to the terminal, and displays the existing DNS configuration.
You can edit the main.py on the playground to experiment with ex0
or ex2
or change the flow of the steps.
Take a look at script_output.log to see what the script prints.
This example uses NSO in local install mode, along with three netsim
devices (but only ex1 is used) that work with the IOS example NED.
NSO and netsim are configured automatically using a Makefile.
A simple dns-config template is created to experiment with this example. This template is created, configured and compiled automatically by the same Makefile. You can find the template details under the dns-config directory
The only thing you need to do are the steps described below, and then play with the python script.
This example is based on: $NCS_DIR/examples.ncs/development-guide/basic-automation/showcase_rc.py
For a step-by-step guide, use the README Jupyter Notebook where you can easily see the REST
operations, paths and payloads used.
The rest of the instructions below are the same to what you find on the jupyter notebook.
if you run this example outside of the playground, make sure
$NCS_DIR
points to the NSO directory. AdjustNCS_RUN_DIR
and$REPO_DIR
to your environment.
The Makefile checks all the environment variables are set, any env var missing will cause the Makefile to fail.
export NCS_RUN_DIR=~/nso-lab-rundir export REPO_DIR=~/src/nso-restconf-dns-example
Source the ncsrc
file.
source $NCS_DIR/ncsrc
The playground already has the requirements installed, run this command if you are using your own environment.
pip install -r $REPO_DIR/requirements.txt
make -C $REPO_DIR build
Everytime you build the environment, netsim & ncs are stopped, then the environment on $NCS_RUN_DIR
is deleted. This is useful to start from scratch everytime when experimenting.
python $REPO_DIR/main.py
Take a look at the output generated by the script and see the flow of actions performed.
make -C $REPO_DIR clean
This is useful when developing to find the Restconf URL or JSON payload you need to use.
ncs_cli -Cu admin devices sync-from config dns-config ex0 dns-server 1.1.1.1 dns-config ex0 dns-server 2.2.2.2 dns-config ex1 dns-server 1.1.1.1 dns-config ex2 dns-server 5.5.5.5
See what NSO will send to the devices. Commit and exit the configuration mode.
commit dry-run commit and-quit
In NSO verify config was applied on the devices.
show running-config devices device * config ip name-server
To find more restconf examples that come with NSO do:
find $NCS_DIR/examples.ncs/ -type f -name "showcase_rc.py"
Owner
Contributors
Categories
Products
Network Services Orchestrator (NSO)Programming Languages
PythonLicense
Code Exchange Community
Get help, share code, and collaborate with other developers in the Code Exchange community.View Community