#

Monday, June 30, 2025

When retrieving show command outputs, both Scrapli and NAPALM libraries can do pretty much the same thing but Scapli is sending the exact command where NAPALM is using a common command to get the same type of information from different platforms. As an example, NAPALM getter like "get_bgp_neighbors" will retrieve the bgp neighbor information from Cisco, Juniper or any other platform which NAPALM supports.

Following table are the platforms which NAPALM supports at the moment.


First we have to install NAPALM library in our environment, mine is Ubuntu.

python3 -m pip install napalm

Following code gets the device details of the device and print it with the default format.





Part of the output will be something like the following..





Converting Results to a Structured Data Format

For this we need to import the "rich" library. If your system does not have it yet, it can be installed by the following commands.

pip install --user rich
pip install rich

Now by using the following additions to the code will provide a more readable output.





It is just importing the rich library and the result is printed as "rprint" instead of normal "print".

If you need to get a specific information our from the above output, it can be done like in the following.


Above outputs the serial number of the device like the following.




If there are multiple devices in a list it's just modifying the list "DEVICES" like the following.




Wednesday, June 25, 2025

Scrapli is a widely used library in Python for network related work. In this post let's see how it can be used to do very simple taks. Following link gives more information on Scrapli as it is the official site.

https://carlmontanari.github.io/scrapli/

First of all installing Scrapli..

python3 -m pip install scrapli

Following is the router I used to access in EVE-NG and the IP address of E0/0 interface is 192.168.1.13


Note that interface is bridged to the physical port of the VM and it is in the same LAN as my Devnet PC (Ubuntu)
















I had to change the ssh_config file of Ubuntu to match the older Ciphers like the following and auth_secondary which is the enable password needed to be configured in order to access the devices in EVE-NG.

Following white colored text were the text I needed to add.




















Following was the output..





Converting Results to a Structured Data Format

This can be using one of the following solutions.

1. Text fsm
2. Genie

I will perform the following example by Textfsm. For that we need to install Textfsm templates to Scrapli library.

use following command in cli;

python3 -m pip install scrapli[textfsm]

Following code will get the "show version" output to the "JSON" structured format.


Output:-

















Configuring Devices with Scrapli

Following example will configure ospf process and ospf router id using Scrapli.














When this code is run, configured commands will be shown as the output as per the last line also.
Note that the commands are sent as a list and will be configured as line by line and no need to send "configure terminal" command as it will be taken care by the library.






If the Config commands are in a file;















Output will show the commands which were in the file;