Python Network Looking Glass
Download either source or release file and put somewhere on your filesystem.
Poetry is used to build the virtual environment although any other venv tools can be used to build it. Pipx is a good way to install poetry although you can use any of the install methods listed here
poetry install --nodev
npm install
Copy the examples/env.example to .env
in lg
root folder (not in the package folder.)
Make sure to change the SECRET_KEY
and CSRF_SECRET
in the .env
file
and also set DEBUG=False
for a production environment.
Copy the examples/config.yml.example to config.yml in the lg root folder (not in the package folder.) The path to this file can be changed by changing CONFIG_FILE in the .env file.
The config file contains the list of cities, devices and cli commands to run on each device type.
Any device type supported by scrapli is supported by the looking glass. To find all the device types look here
Every location needs a device (hostname), the device type, the full name of the location, a region and a source interface or ip address (for traceroute and ping commands).
locations:
AMS:
name: Amsterdam
region: Western Europe
device: router.ams.example.net
type: cisco_iosxr
source: loopback999
The config.yml file also contains the commands to run on each device type. In each command the string IPADDRESS is substituted for the IP Address or CIDR the user enters on the form and SOURCE is substiuted for the source in the location configuration. IOS-XR and JunOS commands are in the example but you can add more support for other devices provided netmiko supports that device type.
Community maps convert the community output in the bgp command to be more human friendly. Copy examples/communities.txt to the mapsdb folder. This is then read at start up and saved to a sqlite database for access. Making any changes to the communities.txt file requires a server restart.
Change the group permissions of the mapsdb folder to the group of your web server and add group sticky bit. Make the .env file readable to the web server.
chgrp www-data mapsdb .env
chmod g+s mapsdb
Run the helper app directly. Use poetry or another virtual environment.
poetry shell
python3 app.py
With uvicorn.
poetry shell
uvicorn --reload --log-level debug --port 8010 lg:app
With gunicorn through the uvicorn worker class, this will use gunicorn
default listen address and port. Use -b <LISTEN>:<PORT>
to change that.
gunicorn -k lg.workers.CustomWorker lg:app
Create a systemd unit file to start the lg service at startup. An example unit file examples/lg.service can be used and edited as needed.
cp examples/lg.service /etc/systemd/system/lg.service
Edit the file and change the following as needed WorkingDirectory
,
User
, Group
. Also alter PATH
and VIRTUAL_ENV
Environment variables to match your install location.
Make the log directory used by the service (gunicorn logs). Set LOG_DIR
in
the .env
file to change this if required and change the username to the
same user and group as in the unit file.
mkdir /var/log/lg/
chown www-data.www-data /var/log/lg/
By default it runs on port 8010 and listens only on localhost. Change
this in the .env
file.
Finally enable the service
systemctl daemon-reload
systemctl enable lg.service
systemctl start lg.service
A reverse proxy via Nginix is optional but recommeded step. If the pages are
served under a sub path modify the ROOT_PATH
in .env
to match for example ROOT_PATH=/lg
See examples/nginx.conf and examples/nginx-subpath.conf configuration for a base to get started.