In this lesson, you will learn:
- How to build a Suzieq query in Python.
- About Pandas DataFrames.
- How to build Python scripts to:
- Check a NOS version at a previous point in time.
- Query the total interfaces that are down.
- Validate that OSPF is correctly operating.
- How to build a Python script with Pytest to validate NOS versions and OSPF state.
You can find the scripts and code for this lesson within the Suzieq repo under the directory: 003_suzieq_interaction_methods/001_python.
Suzieq Python Intro
Suzieq lets you interact and work with the tables and stored data in Python using the Suzieq Python library. The library exposes the various table operations (
assert etc), and filtering options (
columns etc) that we have previously seen in this course.
The first thing we need to learn is how to construct a Suzieq query from within Python. Once we know how to do this, we can apply our knowledge to some real-world examples.
Suzieq Python Fundamentals
First of all, we will need to enter our Python environment within one of our containers:
$ docker-compose exec suzieq_poller python3 Python 3.7.11 (default, Jul 22 2021, 15:59:35) [GCC 8.3.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>>
The reason that we are using this environment over creating a local environment (with
virtualenv etc), is that the Suzieq Python library requires access to the DB (Parquet files).
Note: You can locate the Parquet files outside of your local environment by using a form of remote storage, such as NFS or S3, which you can expose to your container using Docker.
Now we are in our environment, we can perform the required import:
from suzieq.sqobjects import get_sqobject
Create Table Instance
We can now create an instance by providing the table name:
interface_tbl = get_sqobject('interfaces')
To get a list of all the available tables that we can use with
get_sqobject, we can perform the following: