IntentNetworkAPI
Intent-based Network API - leveraging FastAPI & Cisco PyATS to power intent.
Python Code driven by FastAPI and Cisco's PyATS framework to demonstrate powering Network Automation via Intent based APIs.
Overview
This code base is a combination of a FastAPI framework and Cisco PyATS to show-case the capability of building Intent based APIs that perform specific functions within the network infrastructure. This would range from health checks, to performing specific actions via endpoints.
Use Case Description
This use case is very helpful for exploring the concept of Intent based network APIs based on FastAPI as an underlying framework and using Cisco PyATS to connect to a device, check for the prescence of a default route (0.0.0.0/0) and return a result via the call.
Python
The script is written in python using PYATS to interact with the active devices, and return the results as the response to a FastAPI call.
Output:
Once the python script is started, we utilize Postman to push the API endpoint to identify the response body.
Contacts
*Oluyemi Oshunkoya (yemi_o@outlook.com)
Solution Components
Python
Genie
PYATS
FastAPI
Prerequisites
Python3.6 and above
API Client (e.g Postman)
Step 1 - Setting up the enivronment
This can be done either by using the pre-setup docker image for PYATS or using your python environment.
Option A - Using the Docker Image
- Download and setup docker engine suitable for your Operating System
https://docs.docker.com/get-docker/
- Download the latest version of the PYATS from docker hub
$ docker pull ciscotestautomation/pyats:latest
- Run the docker image
$ docker run -it ciscotestautomation/pyats:latest /bin/bash
- Clone the repository
git clone https://github.com/yzmar4real/IntentNetworkAPI.git
- CD into the directory
- Execute the requirement.txt file to install the requirements for the project
pip3 install -r requirements.txt
Option B - Using GIT to setup the environment
- Clone the repository
git clone https://github.com/yzmar4real/IntentNetworkAPI.git
- CD into the directory
- Use the directory as a virtual environment for the project
- Start the virtual environment and install the requirements for the project
- Execute the requirement.txt file to install the requirements for the project
pip3 install -r requirements.txt
Step 2 - Defining the Testbed for devices to be audited
- Edit genie.yml file to include parameters for your devices. The default file in the example connects to Cisco's Always On IOSXE sandbox.
Step 3 - Executing the Script
- Execute the main script from console
Step 4 - Use Postman or Other Suitable Client to Trigger the API
- URL to be executed is :
http://<your_device_ip_address>:3443/v1/route_check (in the example below - its http://10.40.10.18/v1/route_check)
- Execute the API via Postman Client on the suggested port.(3443)
- Results should show as below