mirror of
https://github.com/LibreQoE/LibreQoS.git
synced 2025-02-25 18:55:32 -06:00
Ensure UISP integration does not overwrite existing network.json
This commit is contained in:
parent
903dbc9b13
commit
061adc4bdf
@ -75,89 +75,92 @@ def createTree(sites,accessPoints,bandwidthDL,bandwidthUL,siteParentDict,siteIDt
|
|||||||
return currentNode
|
return currentNode
|
||||||
|
|
||||||
def createNetworkJSON():
|
def createNetworkJSON():
|
||||||
print("Creating network.json")
|
if os.path.isfile("network.json"):
|
||||||
bandwidthDL = {}
|
print("network.json already exists. Leaving in place.")
|
||||||
bandwidthUL = {}
|
else:
|
||||||
url = UISPbaseURL + "/nms/api/v2.1/sites?type=site"
|
print("Generating network.json")
|
||||||
headers = {'accept':'application/json', 'x-auth-token': uispAuthToken}
|
bandwidthDL = {}
|
||||||
r = requests.get(url, headers=headers)
|
bandwidthUL = {}
|
||||||
sites = r.json()
|
url = UISPbaseURL + "/nms/api/v2.1/sites?type=site"
|
||||||
url = UISPbaseURL + "/nms/api/v2.1/devices/aps/profiles"
|
headers = {'accept':'application/json', 'x-auth-token': uispAuthToken}
|
||||||
headers = {'accept':'application/json', 'x-auth-token': uispAuthToken}
|
r = requests.get(url, headers=headers)
|
||||||
r = requests.get(url, headers=headers)
|
sites = r.json()
|
||||||
apProfiles = r.json()
|
url = UISPbaseURL + "/nms/api/v2.1/devices/aps/profiles"
|
||||||
listOfTopLevelParentNodes = []
|
headers = {'accept':'application/json', 'x-auth-token': uispAuthToken}
|
||||||
if os.path.isfile("integrationUISPbandwidths.csv"):
|
r = requests.get(url, headers=headers)
|
||||||
with open('integrationUISPbandwidths.csv') as csv_file:
|
apProfiles = r.json()
|
||||||
csv_reader = csv.reader(csv_file, delimiter=',')
|
listOfTopLevelParentNodes = []
|
||||||
next(csv_reader)
|
if os.path.isfile("integrationUISPbandwidths.csv"):
|
||||||
for row in csv_reader:
|
with open('integrationUISPbandwidths.csv') as csv_file:
|
||||||
name, download, upload = row
|
csv_reader = csv.reader(csv_file, delimiter=',')
|
||||||
download = int(download)
|
next(csv_reader)
|
||||||
upload = int(upload)
|
for row in csv_reader:
|
||||||
listOfTopLevelParentNodes.append(name)
|
name, download, upload = row
|
||||||
bandwidthDL[name] = download
|
download = int(download)
|
||||||
bandwidthUL[name] = upload
|
upload = int(upload)
|
||||||
for ap in apProfiles:
|
listOfTopLevelParentNodes.append(name)
|
||||||
name = ap['device']['name']
|
bandwidthDL[name] = download
|
||||||
model = ap['device']['model']
|
bandwidthUL[name] = upload
|
||||||
apID = ap['device']['id']
|
for ap in apProfiles:
|
||||||
if model in knownAPmodels:
|
name = ap['device']['name']
|
||||||
url = UISPbaseURL + "/nms/api/v2.1/devices/airmaxes/" + apID + '?withStations=false'
|
model = ap['device']['model']
|
||||||
headers = {'accept':'application/json', 'x-auth-token': uispAuthToken}
|
apID = ap['device']['id']
|
||||||
r = requests.get(url, headers=headers)
|
if model in knownAPmodels:
|
||||||
thisAPairmax = r.json()
|
url = UISPbaseURL + "/nms/api/v2.1/devices/airmaxes/" + apID + '?withStations=false'
|
||||||
downloadCap = int(round(thisAPairmax['overview']['downlinkCapacity']/1000000))
|
headers = {'accept':'application/json', 'x-auth-token': uispAuthToken}
|
||||||
uploadCap = int(round(thisAPairmax['overview']['uplinkCapacity']/1000000))
|
r = requests.get(url, headers=headers)
|
||||||
# If operator already included bandwidth definitions for this ParentNode, do not overwrite what they set
|
thisAPairmax = r.json()
|
||||||
if name not in listOfTopLevelParentNodes:
|
downloadCap = int(round(thisAPairmax['overview']['downlinkCapacity']/1000000))
|
||||||
print("Found " + name)
|
uploadCap = int(round(thisAPairmax['overview']['uplinkCapacity']/1000000))
|
||||||
listOfTopLevelParentNodes.append(name)
|
# If operator already included bandwidth definitions for this ParentNode, do not overwrite what they set
|
||||||
bandwidthDL[name] = downloadCap
|
if name not in listOfTopLevelParentNodes:
|
||||||
bandwidthUL[name] = uploadCap
|
print("Found " + name)
|
||||||
for site in sites:
|
listOfTopLevelParentNodes.append(name)
|
||||||
name = site['identification']['name']
|
bandwidthDL[name] = downloadCap
|
||||||
if name not in excludeSites:
|
bandwidthUL[name] = uploadCap
|
||||||
# If operator already included bandwidth definitions for this ParentNode, do not overwrite what they set
|
for site in sites:
|
||||||
if name not in listOfTopLevelParentNodes:
|
name = site['identification']['name']
|
||||||
print("Found " + name)
|
if name not in excludeSites:
|
||||||
listOfTopLevelParentNodes.append(name)
|
# If operator already included bandwidth definitions for this ParentNode, do not overwrite what they set
|
||||||
bandwidthDL[name] = 1000
|
if name not in listOfTopLevelParentNodes:
|
||||||
bandwidthUL[name] = 1000
|
print("Found " + name)
|
||||||
with open('integrationUISPbandwidths.csv', 'w') as csvfile:
|
listOfTopLevelParentNodes.append(name)
|
||||||
wr = csv.writer(csvfile, quoting=csv.QUOTE_ALL)
|
bandwidthDL[name] = 1000
|
||||||
wr.writerow(['ParentNode', 'Download Mbps', 'Upload Mbps'])
|
bandwidthUL[name] = 1000
|
||||||
for device in listOfTopLevelParentNodes:
|
with open('integrationUISPbandwidths.csv', 'w') as csvfile:
|
||||||
entry = (device, bandwidthDL[device], bandwidthUL[device])
|
wr = csv.writer(csvfile, quoting=csv.QUOTE_ALL)
|
||||||
wr.writerow(entry)
|
wr.writerow(['ParentNode', 'Download Mbps', 'Upload Mbps'])
|
||||||
url = UISPbaseURL + "/nms/api/v2.1/devices?role=ap"
|
for device in listOfTopLevelParentNodes:
|
||||||
headers = {'accept':'application/json', 'x-auth-token': uispAuthToken}
|
entry = (device, bandwidthDL[device], bandwidthUL[device])
|
||||||
r = requests.get(url, headers=headers)
|
wr.writerow(entry)
|
||||||
accessPoints = r.json()
|
url = UISPbaseURL + "/nms/api/v2.1/devices?role=ap"
|
||||||
siteIDtoName = {}
|
headers = {'accept':'application/json', 'x-auth-token': uispAuthToken}
|
||||||
siteParentDict = {}
|
r = requests.get(url, headers=headers)
|
||||||
sitesWithParents = []
|
accessPoints = r.json()
|
||||||
topLevelSites = []
|
siteIDtoName = {}
|
||||||
for site in sites:
|
siteParentDict = {}
|
||||||
siteIDtoName[site['id']] = site['identification']['name']
|
sitesWithParents = []
|
||||||
try:
|
topLevelSites = []
|
||||||
siteParentDict[site['id']] = site['identification']['parent']['id']
|
for site in sites:
|
||||||
sitesWithParents.append(site['id'])
|
siteIDtoName[site['id']] = site['identification']['name']
|
||||||
except:
|
try:
|
||||||
siteParentDict[site['id']] = None
|
siteParentDict[site['id']] = site['identification']['parent']['id']
|
||||||
if site['identification']['name'] not in excludeSites:
|
sitesWithParents.append(site['id'])
|
||||||
topLevelSites.append(site['id'])
|
except:
|
||||||
tLname = siteIDtoName[topLevelSites.pop()]
|
siteParentDict[site['id']] = None
|
||||||
topLevelNode = {
|
if site['identification']['name'] not in excludeSites:
|
||||||
tLname :
|
topLevelSites.append(site['id'])
|
||||||
{
|
tLname = siteIDtoName[topLevelSites.pop()]
|
||||||
"downloadBandwidthMbps": bandwidthDL[tLname],
|
topLevelNode = {
|
||||||
"uploadBandwidthMbps": bandwidthUL[tLname],
|
tLname :
|
||||||
|
{
|
||||||
|
"downloadBandwidthMbps": bandwidthDL[tLname],
|
||||||
|
"uploadBandwidthMbps": bandwidthUL[tLname],
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
tree = createTree(sites,apProfiles, bandwidthDL, bandwidthUL, siteParentDict,siteIDtoName,sitesWithParents,topLevelNode)
|
||||||
tree = createTree(sites,apProfiles, bandwidthDL, bandwidthUL, siteParentDict,siteIDtoName,sitesWithParents,topLevelNode)
|
with open('network.json', 'w') as f:
|
||||||
with open('network.json', 'w') as f:
|
json.dump(tree, f, indent=4)
|
||||||
json.dump(tree, f, indent=4)
|
|
||||||
|
|
||||||
def createShaper():
|
def createShaper():
|
||||||
print("Creating ShapedDevices.csv")
|
print("Creating ShapedDevices.csv")
|
||||||
|
Loading…
Reference in New Issue
Block a user