mirror of
https://github.com/LibreQoE/LibreQoS.git
synced 2025-02-20 11:48:32 -06:00
Update integrationSplynx.py
This commit is contained in:
parent
7726c94055
commit
e2b9474d96
@ -65,6 +65,27 @@ def getAllServices(headers):
|
|||||||
services = spylnxRequest("admin/customers/customer/0/internet-services?main_attributes%5Bstatus%5D=active", headers)
|
services = spylnxRequest("admin/customers/customer/0/internet-services?main_attributes%5Bstatus%5D=active", headers)
|
||||||
return services
|
return services
|
||||||
|
|
||||||
|
def getAllIPs(headers):
|
||||||
|
ipv4ByCustomerID = {}
|
||||||
|
ipv6ByCustomerID = {}
|
||||||
|
allIPv4 = spylnxRequest("admin/networking/ipv4-ip?main_attributes%5Bis_used%5D=1", headers)
|
||||||
|
allIPv6 = spylnxRequest("admin/networking/ipv6-ip", headers)
|
||||||
|
for ipv4 in allIPv4:
|
||||||
|
#print(ipv4)
|
||||||
|
if ipv4['customer_id'] not in ipv4ByCustomerID:
|
||||||
|
ipv4ByCustomerID[ipv4['customer_id']] = []
|
||||||
|
temp = ipv4ByCustomerID[ipv4['customer_id']]
|
||||||
|
temp.append(ipv4['ip'])
|
||||||
|
ipv4ByCustomerID[ipv4['customer_id']] = temp
|
||||||
|
for ipv6 in allIPv6:
|
||||||
|
if ipv6['is_used'] == 1:
|
||||||
|
if ipv6['customer_id'] not in ipv6ByCustomerID:
|
||||||
|
ipv6ByCustomerID[ipv6['customer_id']] = []
|
||||||
|
temp = ipv6ByCustomerID[ipv6['customer_id']]
|
||||||
|
temp.append(ipv6['ip'])
|
||||||
|
ipv6ByCustomerID[ipv6['customer_id']] = temp
|
||||||
|
return (ipv4ByCustomerID, ipv6ByCustomerID)
|
||||||
|
|
||||||
def createShaper():
|
def createShaper():
|
||||||
net = NetworkGraph()
|
net = NetworkGraph()
|
||||||
|
|
||||||
@ -74,11 +95,16 @@ def createShaper():
|
|||||||
customers = getCustomers(headers)
|
customers = getCustomers(headers)
|
||||||
ipForRouter = getRouters(headers)
|
ipForRouter = getRouters(headers)
|
||||||
allServices = getAllServices(headers)
|
allServices = getAllServices(headers)
|
||||||
|
ipv4ByCustomerID, ipv6ByCustomerID = getAllIPs(headers)
|
||||||
|
|
||||||
allServicesDict = {}
|
allServicesDict = {}
|
||||||
for serviceItem in allServices:
|
for serviceItem in allServices:
|
||||||
if (serviceItem['status'] == 'active'):
|
if (serviceItem['status'] == 'active'):
|
||||||
allServicesDict[serviceItem["id"]] = serviceItem
|
if serviceItem["customer_id"] not in allServicesDict:
|
||||||
|
allServicesDict[serviceItem["customer_id"]] = []
|
||||||
|
temp = allServicesDict[serviceItem["customer_id"]]
|
||||||
|
temp.append(serviceItem)
|
||||||
|
allServicesDict[serviceItem["customer_id"]] = temp
|
||||||
|
|
||||||
#It's not very clear how a service is meant to handle multiple
|
#It's not very clear how a service is meant to handle multiple
|
||||||
#devices on a shared tariff. Creating each service as a combined
|
#devices on a shared tariff. Creating each service as a combined
|
||||||
@ -86,57 +112,62 @@ def createShaper():
|
|||||||
for customerJson in customers:
|
for customerJson in customers:
|
||||||
if customerJson['status'] == 'active':
|
if customerJson['status'] == 'active':
|
||||||
if customerJson['id'] in allServicesDict:
|
if customerJson['id'] in allServicesDict:
|
||||||
serviceJson = allServicesDict[customerJson['id']]
|
servicesForCustomer = allServicesDict[customerJson['id']]
|
||||||
#print(serviceJson)
|
for service in servicesForCustomer:
|
||||||
combinedId = "c_" + str(customerJson["id"]) + "_s_" + str(serviceJson["id"])
|
combinedId = "c_" + str(customerJson["id"]) + "_s_" + str(service["id"])
|
||||||
tariff_id = serviceJson['tariff_id']
|
tariff_id = service['tariff_id']
|
||||||
customer = NetworkNode(
|
customer = NetworkNode(
|
||||||
type=NodeType.client,
|
type=NodeType.client,
|
||||||
id=combinedId,
|
id=combinedId,
|
||||||
displayName=customerJson["name"],
|
displayName=customerJson["name"],
|
||||||
address=combineAddress(customerJson),
|
address=combineAddress(customerJson),
|
||||||
customerName=customerJson["name"],
|
customerName=customerJson["name"],
|
||||||
download=downloadForTariffID[tariff_id],
|
download=downloadForTariffID[tariff_id],
|
||||||
upload=uploadForTariffID[tariff_id],
|
upload=uploadForTariffID[tariff_id],
|
||||||
)
|
)
|
||||||
net.addRawNode(customer)
|
net.addRawNode(customer)
|
||||||
|
|
||||||
ipv4 = ''
|
|
||||||
ipv6 = ''
|
|
||||||
routerID = serviceJson['router_id']
|
|
||||||
# If not "Taking IPv4" (Router will assign IP), then use router's set IP
|
|
||||||
# Debug
|
|
||||||
taking_ipv4 = int(serviceJson['taking_ipv4'])
|
|
||||||
if taking_ipv4 == 0:
|
|
||||||
try:
|
|
||||||
ipv4 = ipForRouter[routerID]
|
|
||||||
except:
|
|
||||||
warnings.warn("taking_ipv4 was 0 for client " + combinedId + " but router ID was not found in ipForRouter", stacklevel=2)
|
|
||||||
ipv4 = ''
|
|
||||||
elif taking_ipv4 == 1:
|
|
||||||
ipv4 = serviceJson['ipv4']
|
|
||||||
|
|
||||||
|
|
||||||
# If not "Taking IPv6" (Router will assign IP), then use router's set IP
|
ipv4 = []
|
||||||
if isinstance(serviceJson['taking_ipv6'], str):
|
ipv6 = []
|
||||||
taking_ipv6 = int(serviceJson['taking_ipv6'])
|
routerID = service['router_id']
|
||||||
else:
|
|
||||||
taking_ipv6 = serviceJson['taking_ipv6']
|
# If not "Taking IPv4" (Router will assign IP), then use router's set IP
|
||||||
if taking_ipv6 == 0:
|
taking_ipv4 = int(service['taking_ipv4'])
|
||||||
ipv6 = ''
|
if taking_ipv4 == 0:
|
||||||
elif taking_ipv6 == 1:
|
if routerID in ipForRouter:
|
||||||
ipv6 = serviceJson['ipv6']
|
ipv4 = [ipForRouter[routerID]]
|
||||||
|
|
||||||
device = NetworkNode(
|
elif taking_ipv4 == 1:
|
||||||
id=combinedId+"_d" + str(serviceJson["id"]),
|
ipv4 = [service['ipv4']]
|
||||||
displayName=serviceJson["id"],
|
if len(ipv4) == 0:
|
||||||
type=NodeType.device,
|
#Only do this if single service for a customer
|
||||||
parentId=combinedId,
|
if len(servicesForCustomer) == 1:
|
||||||
mac=serviceJson["mac"],
|
if customerJson['id'] in ipv4ByCustomerID:
|
||||||
ipv4=[ipv4],
|
ipv4 = ipv4ByCustomerID[customerJson['id']]
|
||||||
ipv6=[ipv6]
|
|
||||||
)
|
if len(ipv4) == 0:
|
||||||
net.addRawNode(device)
|
print(service)
|
||||||
|
|
||||||
|
# If not "Taking IPv6" (Router will assign IP), then use router's set IP
|
||||||
|
if isinstance(service['taking_ipv6'], str):
|
||||||
|
taking_ipv6 = int(service['taking_ipv6'])
|
||||||
|
else:
|
||||||
|
taking_ipv6 = service['taking_ipv6']
|
||||||
|
if taking_ipv6 == 0:
|
||||||
|
ipv6 = []
|
||||||
|
elif taking_ipv6 == 1:
|
||||||
|
ipv6 = [service['ipv6']]
|
||||||
|
|
||||||
|
device = NetworkNode(
|
||||||
|
id=combinedId+"_d" + str(service["id"]),
|
||||||
|
displayName=service["id"],
|
||||||
|
type=NodeType.device,
|
||||||
|
parentId=combinedId,
|
||||||
|
mac=service["mac"],
|
||||||
|
ipv4=ipv4,
|
||||||
|
ipv6=ipv6
|
||||||
|
)
|
||||||
|
net.addRawNode(device)
|
||||||
|
|
||||||
net.prepareTree()
|
net.prepareTree()
|
||||||
net.plotNetworkGraph(False)
|
net.plotNetworkGraph(False)
|
||||||
|
Loading…
Reference in New Issue
Block a user