Home - leofurtadonyc/Network-Automation GitHub Wiki
Welcome to the Network-Automation wiki!
About this repository
These are collections of small Python projects and scripts designed explicitly for network automation. They encompass straightforward yet extremely useful tasks, providing an ideal opportunity for those keen on learning and experimenting with network automation using Python.
I recommend that you take a look at NetProvisionCLI and its benefits for your ISP organization. It incorporates various ideas from different scripts and concepts found in this repository and provides more extensive and enhanced features. NetProvisionCLI is the primary project of this repository, and it may almost replace everything else available here.
Other than NetProvisionCLI, the other pieces available here can be handy for those just beginning their journey in network automation or for those looking for a toolkit to help automate their day-to-day tasks. Each script has been crafted to perform specific network automation tasks and can be easily modified to suit your particular needs.
Getting started: For those who are new to network automation with Python
It's essential that you operate these scripts within a Python virtual environment to ensure they don't interfere with your existing Python environment. This can be quickly done using the python3 -m venv name_environment
command, which creates a new isolated Python environment. Use the source name_environment/bin/activate
command to activate this environment.
Alternatively, you can use Pyenv, Pipenv, Poetry, Conda, or any other Python environment management tool you prefer. These tools provide additional features, such as dependency management and package isolation, that can make your work even more accessible.
Here are some easy steps to set up your Python virtual environment on a Mac or Linux computer:
- Create a new 'sandbox' directory using the
mkdir sandbox
command (or use another name as you see fit). - Navigate to the newly created directory using the
cd sandbox
command. - Create a new Python virtual environment named 'network-automation-env' using the
python3 -m venv network-automation-env
command. - Activate the virtual environment using the
source network-automation-env/bin/activate
command. - Clone the GitHub repository using the
git clone https://github.com/leofurtadonyc/Network-Automation.git
command. - Upgrade your pip version using the
pip3 install --upgrade pip
command. - Install all the necessary dependencies using the
pip3 install -r Network-Automation/requirements.txt
command.
In case you don't want to use venv
, you can use pyenv
instead to work on this Python project. If you are new to Pyenv, follow these steps:
sudo apt-get update
sudo apt-get install -y make build-essential libssl-dev zlib1g-dev \
libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev \
libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev python-openssl git
curl https://pyenv.run | bash
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(pyenv init --path)"' >> ~/.bashrc
echo 'eval "$(pyenv init -)"' >> ~/.bashrc
echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bashrc
source ~/.bashrc
Then, install Python through Pyenv. I recommend 3.11 or later:
pyenv install 3.12.3
Next:
pyenv virtualenv 3.12.3 network-automation-venv
pyenv activate network-automation-venv
Lastly:
pip install -r Network-Automation/requirements.txt
On Windows 11:
- Create a new 'sandbox' directory using the
mkdir sandbox
command (or use another name as you see fit). - Navigate to the newly created directory using the
cd sandbox
command. python -m venv network-automation-env.
.\network-automation-env\Scripts\activate
.git clone https://github.com/leofurtadonyc/Network-Automation.git
(you may need Git. Tip:winget install --id Git.Git -e --source winget
)pip install --upgrade pip
(if needed)pip install -r .\Network-Automation\requirements.txt
Then:
- Experiment with it! Look through all the folders, as they contain separate scripts. You may find some redundancy across the folder, but see what each script accomplishes for yourself.
- Some folders may contain more than a single script. They can contain several scripts and different types of files, such as YAML, JSON, and Jinja2 templates.
Dependencies
While a requirements.txt
file for managing Python dependencies has been included, there may be issues depending on your operating system. Non-Python dependencies also exist, so ensure BGPq4 and Whois are installed if your computer doesn't already have them.
Disclamer
Please be careful when using these scripts, as they could accidentally deploy running configurations to your production network devices. I strongly suggest testing these scripts in a lab environment like EVE-NG, PNETLab, NetLab, or similar platforms.
I am always open to suggestions, tips, code reviews, or any other feedback you might have. Feel free to reach out to me at any time!
Repository structure
This section aims to explain each folder present in this repository and its intended purpose. Each folder contains a single script or a group of scripts, (possibly) along with other file types like YAML, JSON, Jinja2 templates, and output examples. Scripts in one folder are independent and do not rely on scripts or files in other folders, as I have maintained each "project" separately.
It is important to note that the concept of independence being referred to here is not related to code modularity as seen in real-life projects. Instead, it simply signifies different ideas or modifications that have been kept separate from each other.
- ChatNOC: An agent designed to answer common Network Operations questions about their environment, including network control plane status, reachability testing (ping, traceroute), device healthy monitoring, customer service health monitoring, and routing analysis through RIB and BGP Local-RIB tables—along with other capabilities I plan to add.
- NetProvisionCLI: This is a rebranded customer service provisioning tool, derived from smaller projects previously found in this repository.
- generate-customer-routingpolicies: A mix of scripts and other file types is used. Given the required ASN, AS-SET, and CUSTOMER_NAME arguments, the main script invokes the other scripts to generate IPv4/IPv6 prefix lists, AS-Path lists, and routing policies in various syntaxes/vendors.
- general-purpose-scripts: Scripts to serve various purposes in working with computer networks; handy for learning and experimenting network automation with Python.