mirror of
https://github.com/LibreQoE/LibreQoS.git
synced 2025-02-25 18:55:32 -06:00
Merge pull request #434 from LibreQoE/rchac-patch-9
Splynx Integration Speedup
This commit is contained in:
commit
7726c94055
@ -50,7 +50,6 @@ def getRouters(headers):
|
|||||||
for router in data:
|
for router in data:
|
||||||
routerID = router['id']
|
routerID = router['id']
|
||||||
ipForRouter[routerID] = router['ip']
|
ipForRouter[routerID] = router['ip']
|
||||||
|
|
||||||
print("Router IPs found: " + str(len(ipForRouter)))
|
print("Router IPs found: " + str(len(ipForRouter)))
|
||||||
return ipForRouter
|
return ipForRouter
|
||||||
|
|
||||||
@ -62,6 +61,10 @@ def combineAddress(json):
|
|||||||
else:
|
else:
|
||||||
return json["street_1"] + " " + json["city"] + " " + json["zip_code"]
|
return json["street_1"] + " " + json["city"] + " " + json["zip_code"]
|
||||||
|
|
||||||
|
def getAllServices(headers):
|
||||||
|
services = spylnxRequest("admin/customers/customer/0/internet-services?main_attributes%5Bstatus%5D=active", headers)
|
||||||
|
return services
|
||||||
|
|
||||||
def createShaper():
|
def createShaper():
|
||||||
net = NetworkGraph()
|
net = NetworkGraph()
|
||||||
|
|
||||||
@ -70,63 +73,70 @@ def createShaper():
|
|||||||
tariff, downloadForTariffID, uploadForTariffID = getTariffs(headers)
|
tariff, downloadForTariffID, uploadForTariffID = getTariffs(headers)
|
||||||
customers = getCustomers(headers)
|
customers = getCustomers(headers)
|
||||||
ipForRouter = getRouters(headers)
|
ipForRouter = getRouters(headers)
|
||||||
|
allServices = getAllServices(headers)
|
||||||
# It's not very clear how a service is meant to handle multiple
|
|
||||||
# devices on a shared tariff. Creating each service as a combined
|
allServicesDict = {}
|
||||||
# entity including the customer, to be on the safe side.
|
for serviceItem in allServices:
|
||||||
|
if (serviceItem['status'] == 'active'):
|
||||||
|
allServicesDict[serviceItem["id"]] = serviceItem
|
||||||
|
|
||||||
|
#It's not very clear how a service is meant to handle multiple
|
||||||
|
#devices on a shared tariff. Creating each service as a combined
|
||||||
|
#entity including the customer, to be on the safe side.
|
||||||
for customerJson in customers:
|
for customerJson in customers:
|
||||||
if customerJson['status'] == 'active':
|
if customerJson['status'] == 'active':
|
||||||
services = spylnxRequest("admin/customers/customer/" + customerJson["id"] + "/internet-services", headers)
|
if customerJson['id'] in allServicesDict:
|
||||||
for serviceJson in services:
|
serviceJson = allServicesDict[customerJson['id']]
|
||||||
if (serviceJson['status'] == 'active'):
|
#print(serviceJson)
|
||||||
combinedId = "c_" + str(customerJson["id"]) + "_s_" + str(serviceJson["id"])
|
combinedId = "c_" + str(customerJson["id"]) + "_s_" + str(serviceJson["id"])
|
||||||
tariff_id = serviceJson['tariff_id']
|
tariff_id = serviceJson['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 = ''
|
ipv4 = ''
|
||||||
ipv6 = ''
|
ipv6 = ''
|
||||||
routerID = serviceJson['router_id']
|
routerID = serviceJson['router_id']
|
||||||
# If not "Taking IPv4" (Router will assign IP), then use router's set IP
|
# If not "Taking IPv4" (Router will assign IP), then use router's set IP
|
||||||
# Debug
|
# Debug
|
||||||
taking_ipv4 = int(serviceJson['taking_ipv4'])
|
taking_ipv4 = int(serviceJson['taking_ipv4'])
|
||||||
if taking_ipv4 == 0:
|
if taking_ipv4 == 0:
|
||||||
try:
|
try:
|
||||||
ipv4 = ipForRouter[routerID]
|
ipv4 = ipForRouter[routerID]
|
||||||
except:
|
except:
|
||||||
warnings.warn("taking_ipv4 was 0 for client " + combinedId + " but router ID was not found in ipForRouter", stacklevel=2)
|
warnings.warn("taking_ipv4 was 0 for client " + combinedId + " but router ID was not found in ipForRouter", stacklevel=2)
|
||||||
ipv4 = ''
|
ipv4 = ''
|
||||||
elif taking_ipv4 == 1:
|
elif taking_ipv4 == 1:
|
||||||
ipv4 = serviceJson['ipv4']
|
ipv4 = serviceJson['ipv4']
|
||||||
|
|
||||||
# If not "Taking IPv6" (Router will assign IP), then use router's set IP
|
|
||||||
if isinstance(serviceJson['taking_ipv6'], str):
|
|
||||||
taking_ipv6 = int(serviceJson['taking_ipv6'])
|
|
||||||
else:
|
|
||||||
taking_ipv6 = serviceJson['taking_ipv6']
|
|
||||||
if taking_ipv6 == 0:
|
|
||||||
ipv6 = ''
|
|
||||||
elif taking_ipv6 == 1:
|
|
||||||
ipv6 = serviceJson['ipv6']
|
|
||||||
|
|
||||||
device = NetworkNode(
|
# If not "Taking IPv6" (Router will assign IP), then use router's set IP
|
||||||
id=combinedId+"_d" + str(serviceJson["id"]),
|
if isinstance(serviceJson['taking_ipv6'], str):
|
||||||
displayName=serviceJson["id"],
|
taking_ipv6 = int(serviceJson['taking_ipv6'])
|
||||||
type=NodeType.device,
|
else:
|
||||||
parentId=combinedId,
|
taking_ipv6 = serviceJson['taking_ipv6']
|
||||||
mac=serviceJson["mac"],
|
if taking_ipv6 == 0:
|
||||||
ipv4=[ipv4],
|
ipv6 = ''
|
||||||
ipv6=[ipv6]
|
elif taking_ipv6 == 1:
|
||||||
)
|
ipv6 = serviceJson['ipv6']
|
||||||
net.addRawNode(device)
|
|
||||||
|
device = NetworkNode(
|
||||||
|
id=combinedId+"_d" + str(serviceJson["id"]),
|
||||||
|
displayName=serviceJson["id"],
|
||||||
|
type=NodeType.device,
|
||||||
|
parentId=combinedId,
|
||||||
|
mac=serviceJson["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