I'm using a program built in python 3 that figures out which VIP (Virtual IP) subnet I should use and which load balancer the VIP should match with. The program will ask you what the IP address is of one of the pool members. Based on that, it will tell you which subnet you will need an IP address for from the VIP and which load balancer to build the VIP on. An edited example of a simple working script is ran on a linux box shown below:
from netaddr import IPNetwork, IPAddress, IPSet
global subnet
global loadbalancer
member = IPAddress(input("What is the IP address of one of the nodes? "))
# Lists for each LB pair containing the node subnets.
loadbalancer1_node_IPs = IPSet([IPNetwork('1.1.1.0/22'), IPNetwork('2.2.2.0/22'), IPNetwork('3.3.3.0/22')])
loadbalancer2_node_IPs = IPSet([IPNetwork('4.4.4.0/23'), IPNetwork('2.2.2.0/23'), IPNetwork('3.3.3.0/23')])
# Provides the LB the VIP is to be built on based on node IP address.
if IPAddress(member) in loadbalancer1_node_IPs:
loadbalancer = "The LB pair you need to build this VIP on is loadbalancer1_node_IPs"
subnet = "You need a VIP ip from subnet 1.1.1.0/22, 2.2.2.0/22, or 3.3.3.0/22"
elif IPAddress(member) in loadbalancer2_node_IPs:
loadbalancer = "The LB pair you need to build this VIP on is loadbalancer2_node_IPs"
subnet = "You need a VIP ip from subnet 4.4.4.0/23, 2.2.2.0/23, or 3.3.3.0/23"
print(loadbalancer)
print(subnet)
exit(input("Press Enter to exit."))
This scripts work fine using the cli on linux. My goal now is to use the python package PySimpleGUI to build a GUI that outputs the results. I am trying to combine the code above with the below code for PySimpleGUI:
import PySimpleGUI as sg
form = sg.FlexForm('F5 Load Balancer VIP IP and LB selector')
layout = [ [sg.Text('What is the IP address of one of the nodes'), sg.InputText()],
[sg.OK()] ]
button, (name,) = form.Layout(layout).Read()
I am having trouble getting a basic output of the results. I tried using
window = sg.Window('Test').Layout(layout)
and updating it with
window.FindElement('loadbalancer').Update(loadbalancer)
but the window displays the error
"Error creating layout. The layout specified has already been used.".
Any assistance is appreciated. Thank you.