Virtual servers are an integral part of modern web application deployment. They provide a layer of abstraction between the application and the underlying infrastructure, allowing for flexible routing and load balancing.
In this blog post, I will explore how to create a graphical representation of a virtual server using Python Flask, Pyvis libraries, and the IControl REST F5 API. This graphical representation will provide a visual representation of the virtual server, including the pools and the pool members(servers) it is connected to, and also the URI.
The app has 2 main files:
- F5_VIP_grapher.py
- app.py
F5_VIP_grapher.py
This file is for getting the data from the F5 device and then building the graphical representation. It is using IControl REST API calls to get the VIP (it uses the name of the VIP as an argument), the pools, pool members, then the irule names, and lastly the irules content. Based on this info it will draw, using pyvis library, the connections between the VIP, pool, and pool members. The result is saved as an html file. Because I wanted to represent also the state of the Virtual server, pool, and nodes, there are also functions to get these data.
app.py
This file is for building the webpage of the app. It is using Flask and for CSS, Materialize. This is just a simple web page as I did not want to spend too much time on this. You only have to type the VIP name and “Submit”. To make things easier, I have containerized the whole app using Docker.
As an example let’s take an SSL VIP with a default pool (pool1) and 2 irules (As irules can be really complex, this is mainly for irules with “if” and “switch” clauses) :
{
"name": "example_rule_1",
"apiAnonymous": "when HTTP_REQUEST { \n if { ([HTTP::host] == \"www.xyzabc.com\") and ([string tolower [HTTP::uri]] contains \"test\") }{
log local0. \"for test \"
pool pool21 }
elseif {([string tolower [HTTP::uri]] contains \"test1\")}
{ pool pool1 }
else { pool pool11 }\n }"
},
{
"name": "example_rule_11",
"apiAnonymous": "when HTTP_REQUEST { \n if { ([HTTP::host] == \"www.xyzabc.com\") and ([string tolower [HTTP::uri]] contains \"/test_abc\") }
{ \n pool pool21 } \n }"
}
Here is the graphical representation of an SSL virtual server:
The same virtual server, after disabling pool1 members:
Conclusion
I always prefer having a graphical representation because it helps me to understand faster and easier almost anything. And in this particular case, having a representation of a Virtual Server makes it easier to understand where traffic will go.
Source code: https://github.com/czirakim/F5_VIP_graph