netconfBulkOps is a Python script for NETCONF bulk operations (get and edit-config) implemented as a minimum viable product (MVP).
A simple inventory file is used to describe the devices. A second file, containing either the NETCONF configuration payload or a subtree-filter, will then be applied to every device in the inventory. Instead of a subtree-filter or configuraton payload a xPath can be used. The results of the bulk operation is stored in corresponding files.
netconfBulkOps is executed asynchronously using Python's concurrent.futures ThreadPoolExecutor and is therefore pretty fast.
Clone the repo
git clone https://github.com/spie-ics-ag/netconfBulkOps.git
Go to your project folder
cd netconfBulkOps
Set up a Python venv
First make sure that you have Python 3 installed on your machine. We will then be using venv to create an isolated environment with only the necessary packages.
Install virtualenv via pip
pip install virtualenv
Create the venv
python3 -m venv .venv
Activate your venv
source .venv/bin/activate
Install dependencies
pip install pip --upgrade pip install -r requirements.txt
Configure the NETCONF username and password used to connect to your devices as environment variables
export NCBO_USER=your_username export NCBO_PASSWORD=your_password
Clone the repo
git clone https://github.com/spie-ics-ag/netconfBulkOps.git
Go to your project folder
cd netconfBulkOps
Configure the NETCONF username and password used to connect to your devices as environment variables
export NCBO_USER=your_username export NCBO_PASSWORD=your_password
Build the docker image
docker build -t ncbo .
Run and enter the container
docker run -it -e NCBO_USER -e NCBO_PASS ncbo sh
In order to copy your [DEVICES]
and [FILTER]/[CONFIG]
files (see usage below) to the container you may use the docker cp command.
Create a inventory file with all devices you want to connect to. Every line in the file represents a hostname or IP address.
Example
10.90.255.235
rtr01.internal.domain.com
sw01.internal.domain.com
10.90.255.245
Create a file containing the subtree-filter you want to use (without the <filter></filter>
tags).
Example
<native xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native"> <hostname/> </native>
Start the script with the netconfBulkOps.py read [FILTER] [DEVICES]
command. FILTER
is your subtree-filter file and DEVICES
is the inventory file. If you don't specify these parameters bulk_filter.xml
is used as the default filter file and devices.txt
is used as the default inventory file.
Usage: netconfBulkOps.py read [FILTER] [DEVICES] Retrive configuration and state information from all devices in the DEVICES file according the subtree filter in the FILTER file.
After the script is completed, you'll find a file per device containing the results in the output
directory (output/out_read_[DEVICE NAME OR IP].xml
).
Start the script with the netconfBulkOps.py xpath [XPATH] [DEVICES]
command. XPATH
is your xpath-string and DEVICES
is the inventory file (devices.txt
is used as the default inventory file).
Usage: netconfBulkOps.py xpath [XPATH] [DEVICES]
Retrive configuration and state information from all devices in the
DEVICES file according the XPATH filter.
After the script is completed, you'll find a file per device containing the results in the output
directory (output/out_read_[DEVICE NAME OR IP].xml
).
Create a file containing the configuration you want to apply (outermost tag must be <config></config>
).
Example
<config> <native xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native"> <banner> <motd> <banner>Welcome to this device. Have a nice day!</banner> </motd> </banner> </native> </config>
Start the script with the netconfBulkOps.py write [CONFIG] [DEVICES]
command. CONFIG
is the file containing the configuration and DEVICES
is the inventory file. If you don't specify these parameters bulk_config.xml
is used as the default config file and devices.txt
is used as the default inventory file.
Usage: netconfBulkOps.py write [CONFIG] [DEVICES] Loads the configuration specified in the CONFIG file to the running datastore of all devices in the DEVICES file.
After the script is completed, a HTML report about the configuration results is generated. This report is available as config_report.html
in the output
directory.
Example report
You may test this script using the following DevNet sandboxes:
Owner
Contributors
Categories
Programming Languages
PythonLicense
Code Exchange Community
Get help, share code, and collaborate with other developers in the Code Exchange community.View Community