Empowering Network Automation

Run in Cisco Cloud IDE

Welcome to DEVWKS-2551 Empowering Network Automation, Practice NSO with Python

On this file you can find the instructions to work during the workshop. However, you can try the exercise presented here at any time using the Cisco Cloud IDE Run it! button on the top left corner.

For reference, you can find the info shared on the workshop under the NSO Python API markdown file.

Setup the environment

Setup the environment required for the lab.

cd ~/src/DEVWKS-2551/
make

Note

If you receive an error during the setup, enter make again. If there are too many issues, reset the environment.

Scenario 1. Scripting with the NSO Python API

Examine the examples show on the ncs_scripting.py file

Run the python scripts and review the output.

python ~/src/DEVWKS-2551/scripting/ncs_scripting.py
python ~/src/DEVWKS-2551/scripting/restconf_scripting.py

Scenario 2. Run services with NSO Python API

First compile the package used.

make clean all -C ${NCS_RUN_DIR}/packages/router/src/

Reload the packages.

echo "packages reload" | ncs_cli -C -u admin

Test the package

ncs_cli -Cu admin
config

Pick any of the lines below to test the package

router core device core-rtr0 sys dns server 1.1.1.1
router core device core-rtr0 sys syslog server 1.1.1.1
router core device core-rtr0 sys syslog server 2.2.2.2
router core device core-rtr0 sys ntp server 1.1.1.1
router core device core-rtr0 sys ntp server 2.2.2.2
router distribution device dist-rtr0 sys dns server 6.6.6.6
router distribution device dist-rtr0 sys dns server 5.5.5.5
router distribution device dist-rtr0 sys syslog server 6.6.6.6
router access device dist-sw0 sys dns server 4.4.4.4
router access device dist-sw0 sys dns server 3.3.3.3
router access device dist-sw0 sys syslog server 4.4.4.4
router access device dist-sw0 sys syslog server 3.3.3.3
router access device dist-sw0 sys ntp server 4.4.4.4
router access device dist-sw0 sys ntp server 3.3.3.3

See the dry-run

commit dry-run

Commit the changes.

commit

Scenario 3. Interact with NSO programmatically

Add a new DNS server using the router package.

Use the restconf_service.py file.

python ~/src/DEVWKS-2551/scripting/restconf_service.py

Bonus. Development

This exercise was developed using the official NSO container. The compose file used for development is kept for reference and is not part of the workshop.

Useful commands

Access netsim cli device.

ncs-netsim cli-c core-rtr0 --dir ~/src/workshop/netsim
show running-config hostname

Use show commands using live-status on NSO.

devices device core-rtr0 live-status exec show running-config hostname

Redeploy the router packages for changes on python code or templates files.

echo 'packages package router redeploy' | ncs_cli -Cu admin
View code on GitHub

Code Exchange Community

Get help, share code, and collaborate with other developers in the Code Exchange community.View Community
Disclaimer:
Cisco provides Code Exchange for convenience and informational purposes only, with no support of any kind. This page contains information and links from third-party websites that are governed by their own separate terms. Reference to a project or contributor on this page does not imply any affiliation with or endorsement by Cisco.