Scrapli and Flask – Part 5: Additional Device Details

In version2, I have made several changes to continue with this project

  • Added device details page for each device
  • Refresh database button for upto date device details
  • Refresh button for each device
  • Notification if the last refresh of device data is greater than 200 seconds
  • Also added is a device base template cofig generator. More details can be found in part 6

Code for the this current version2 can be found in GitHub

Making the Details Pages

This was quite a simple process to create the new individual pages for the network devices

I first needed to create a view that was expecting a variable of the hostname

The links on the page are created in the HTML template of the inventory page. I added them to the hostname of each device

Lastly a detail.html page is created that is reused for each device

Gathering Show Commands

For the details page there are two additional commands that are run.
Show run
Show interface or show interfaces – depending on IOS or NXOS

The commands are all part of the same background process so we can technically add more. These commands are run and then parsed for specifics that I want. I have collected the show run, to output as raw output and also basic port details.
Multi threading is working on these commands also. I made some modifications so that from the views.py I am sending a string that is used to reference what I want to run from the threading function.
This allows all commands to be performed through the threading function in a repeatable and neat way.

Views.py

background_processes.py

Refreshing All Devices or a Single Device

There are two options to pull all the device details into the database. Either refresh a single device, or refresh all. The single device may be refreshed from the device details page. If the device is new and there isn’t any details in the database the user is told. The time that the refresh has been performed is added to the database. This will be used later to determine if the past refresh of all devices was performed with 20 seconds of each other.
This is just a way to tell the user if what is in the database is recent.

Inventory HTML Page

Views.py – Calculates the time difference in seconds between the rows inthe database

Leave a Comment

Your email address will not be published. Required fields are marked *