Not tested - but the integrationUISP.py file has been ported. Testing required.

This commit is contained in:
Herbert Wolverson
2023-12-14 09:51:17 -06:00
parent fb638ea439
commit c5cd1fdf6d
4 changed files with 82 additions and 42 deletions

View File

@@ -5,35 +5,16 @@ import os
import csv
from datetime import datetime, timedelta
from integrationCommon import isIpv4Permitted, fixSubnet
try:
from ispConfig import uispSite, uispStrategy, overwriteNetworkJSONalways
except:
from ispConfig import uispSite, uispStrategy
overwriteNetworkJSONalways = False
try:
from ispConfig import uispSuspendedStrategy
except:
uispSuspendedStrategy = "none"
try:
from ispConfig import airMax_capacity
except:
airMax_capacity = 0.65
try:
from ispConfig import ltu_capacity
except:
ltu_capacity = 0.90
try:
from ispConfig import usePtMPasParent
except:
usePtMPasParent = False
from liblqos_python import uisp_site, uisp_strategy, overwrite_network_json_always, uisp_suspended_strategy, \
airmax_capacity, ltu_capacity, use_ptmp_as_parent, uisp_base_url, uisp_auth_token, \
generated_pn_download_mbps, generated_pn_upload_mbps
def uispRequest(target):
# Sends an HTTP request to UISP and returns the
# result in JSON. You only need to specify the
# tail end of the URL, e.g. "sites"
from ispConfig import UISPbaseURL, uispAuthToken
url = UISPbaseURL + "/nms/api/v2.1/" + target
headers = {'accept': 'application/json', 'x-auth-token': uispAuthToken}
url = uisp_base_url() + "/nms/api/v2.1/" + target
headers = {'accept': 'application/json', 'x-auth-token': uisp_auth_token()}
r = requests.get(url, headers=headers, timeout=60)
return r.json()
@@ -41,7 +22,6 @@ def buildFlatGraph():
# Builds a high-performance (but lacking in site or AP bandwidth control)
# network.
from integrationCommon import NetworkGraph, NetworkNode, NodeType
from ispConfig import generatedPNUploadMbps, generatedPNDownloadMbps
# Load network sites
print("Loading Data from UISP")
@@ -60,8 +40,8 @@ def buildFlatGraph():
customerName = ''
name = site['identification']['name']
type = site['identification']['type']
download = generatedPNDownloadMbps
upload = generatedPNUploadMbps
download = generated_pn_download_mbps()
upload = generated_pn_upload_mbps()
if (site['qos']['downloadSpeed']) and (site['qos']['uploadSpeed']):
download = int(round(site['qos']['downloadSpeed']/1000000))
upload = int(round(site['qos']['uploadSpeed']/1000000))
@@ -92,7 +72,7 @@ def buildFlatGraph():
net.prepareTree()
net.plotNetworkGraph(False)
if net.doesNetworkJsonExist():
if overwriteNetworkJSONalways:
if overwrite_network_json_always():
net.createNetworkJson()
else:
print("network.json already exists and overwriteNetworkJSONalways set to False. Leaving in-place.")
@@ -156,8 +136,8 @@ def findApCapacities(devices, siteBandwidth):
if device['identification']['type'] == 'airMax':
download, upload = airMaxCapacityCorrection(device, download, upload)
elif device['identification']['model'] == 'LTU-Rocket':
download = download * ltu_capacity
upload = upload * ltu_capacity
download = download * ltu_capacity()
upload = upload * ltu_capacity()
if device['identification']['model'] == 'WaveAP':
if (download < 500) or (upload < 500):
download = 2450
@@ -188,8 +168,8 @@ def airMaxCapacityCorrection(device, download, upload):
upload = upload * 0.50
# Flexible frame
elif dlRatio == None:
download = download * airMax_capacity
upload = upload * airMax_capacity
download = download * airmax_capacity()
upload = upload * airmax_capacity()
return (download, upload)
def findAirfibers(devices, generatedPNDownloadMbps, generatedPNUploadMbps):
@@ -344,7 +324,7 @@ def findNodesBranchedOffPtMP(siteList, dataLinks, sites, rootSite, foundAirFiber
'upload': upload,
parent: apID
}
if usePtMPasParent:
if use_ptmp_as_parent():
site['parent'] = apID
print('Site ' + name + ' will use PtMP AP as parent.')
return siteList, nodeOffPtMP
@@ -375,7 +355,7 @@ def buildFullGraph():
# Attempts to build a full network graph, incorporating as much of the UISP
# hierarchy as possible.
from integrationCommon import NetworkGraph, NetworkNode, NodeType
from ispConfig import uispSite, generatedPNUploadMbps, generatedPNDownloadMbps
uispSite = uisp_site()
# Load network sites
print("Loading Data from UISP")
@@ -397,7 +377,7 @@ def buildFullGraph():
siteList = buildSiteList(sites, dataLinks)
rootSite = findInSiteList(siteList, uispSite)
print("Finding PtP Capacities")
foundAirFibersBySite = findAirfibers(devices, generatedPNDownloadMbps, generatedPNUploadMbps)
foundAirFibersBySite = findAirfibers(devices, generated_pn_download_mbps(), generated_pn_upload_mbps())
print('Creating list of route overrides')
routeOverrides = loadRoutingOverrides()
if rootSite is None:
@@ -425,8 +405,8 @@ def buildFullGraph():
id = site['identification']['id']
name = site['identification']['name']
type = site['identification']['type']
download = generatedPNDownloadMbps
upload = generatedPNUploadMbps
download = generated_pn_download_mbps
upload = generated_pn_upload_mbps()
address = ""
customerName = ""
parent = findInSiteListById(siteList, id)['parent']
@@ -469,10 +449,10 @@ def buildFullGraph():
download = int(round(site['qos']['downloadSpeed']/1000000))
upload = int(round(site['qos']['uploadSpeed']/1000000))
if site['identification'] is not None and site['identification']['suspended'] is not None and site['identification']['suspended'] == True:
if uispSuspendedStrategy == "ignore":
if uisp_suspended_strategy() == "ignore":
print("WARNING: Site " + name + " is suspended")
continue
if uispSuspendedStrategy == "slow":
if uisp_suspended_strategy() == "slow":
print("WARNING: Site " + name + " is suspended")
download = 1
upload = 1
@@ -530,13 +510,13 @@ def buildFullGraph():
else:
# Add some defaults in case they want to change them
siteBandwidth[node.displayName] = {
"download": generatedPNDownloadMbps, "upload": generatedPNUploadMbps}
"download": generated_pn_download_mbps(), "upload": generated_pn_upload_mbps()}
net.prepareTree()
print('Plotting network graph')
net.plotNetworkGraph(False)
if net.doesNetworkJsonExist():
if overwriteNetworkJSONalways:
if overwrite_network_json_always():
net.createNetworkJson()
else:
print("network.json already exists and overwriteNetworkJSONalways set to False. Leaving in-place.")
@@ -558,7 +538,7 @@ def buildFullGraph():
def importFromUISP():
startTime = datetime.now()
match uispStrategy:
match uisp_strategy():
case "full": buildFullGraph()
case default: buildFlatGraph()
endTime = datetime.now()

View File

@@ -76,3 +76,4 @@ ipv6_with_mikrotik = false
bandwidth_overhead_factor = 1.0
commit_bandwidth_multiplier = 0.98
exception_cpes = []
use_ptmp_as_parent = false

View File

@@ -15,6 +15,7 @@ pub struct UispIntegration {
pub bandwidth_overhead_factor: f32,
pub commit_bandwidth_multiplier: f32,
pub exception_cpes: Vec<ExceptionCpe>,
pub use_ptmp_as_parent: bool,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
@@ -39,6 +40,7 @@ impl Default for UispIntegration {
bandwidth_overhead_factor: 1.0,
commit_bandwidth_multiplier: 1.0,
exception_cpes: vec![],
use_ptmp_as_parent: false,
}
}
}

View File

@@ -33,6 +33,7 @@ fn liblqos_python(_py: Python, m: &PyModule) -> PyResult<()> {
m.add_wrapped(wrap_pyfunction!(is_libre_already_running))?;
m.add_wrapped(wrap_pyfunction!(create_lock_file))?;
m.add_wrapped(wrap_pyfunction!(free_lock_file))?;
// Unified configuration items
m.add_wrapped(wrap_pyfunction!(check_config))?;
m.add_wrapped(wrap_pyfunction!(sqm))?;
m.add_wrapped(wrap_pyfunction!(upstream_bandwidth_capacity_download_mbps))?;
@@ -56,6 +57,14 @@ fn liblqos_python(_py: Python, m: &PyModule) -> PyResult<()> {
m.add_wrapped(wrap_pyfunction!(bandwidth_overhead_factor))?;
m.add_wrapped(wrap_pyfunction!(committed_bandwidth_multiplier))?;
m.add_wrapped(wrap_pyfunction!(exception_cpes))?;
m.add_wrapped(wrap_pyfunction!(uisp_site))?;
m.add_wrapped(wrap_pyfunction!(uisp_strategy))?;
m.add_wrapped(wrap_pyfunction!(uisp_suspended_strategy))?;
m.add_wrapped(wrap_pyfunction!(airmax_capacity))?;
m.add_wrapped(wrap_pyfunction!(ltu_capacity))?;
m.add_wrapped(wrap_pyfunction!(use_ptmp_as_parent))?;
m.add_wrapped(wrap_pyfunction!(uisp_base_url))?;
m.add_wrapped(wrap_pyfunction!(uisp_auth_token))?;
Ok(())
}
@@ -433,4 +442,52 @@ fn exception_cpes() -> PyResult<Vec<PyExceptionCpe>> {
});
}
Ok(result)
}
#[pyfunction]
fn uisp_site() -> PyResult<String> {
let config = lqos_config::load_config().unwrap();
Ok(config.uisp_integration.site)
}
#[pyfunction]
fn uisp_strategy() -> PyResult<String> {
let config = lqos_config::load_config().unwrap();
Ok(config.uisp_integration.strategy)
}
#[pyfunction]
fn uisp_suspended_strategy() -> PyResult<String> {
let config = lqos_config::load_config().unwrap();
Ok(config.uisp_integration.suspended_strategy)
}
#[pyfunction]
fn airmax_capacity() -> PyResult<f32> {
let config = lqos_config::load_config().unwrap();
Ok(config.uisp_integration.airmax_capacity)
}
#[pyfunction]
fn ltu_capacity() -> PyResult<f32> {
let config = lqos_config::load_config().unwrap();
Ok(config.uisp_integration.ltu_capacity)
}
#[pyfunction]
fn use_ptmp_as_parent() -> PyResult<bool> {
let config = lqos_config::load_config().unwrap();
Ok(config.uisp_integration.use_ptmp_as_parent)
}
#[pyfunction]
fn uisp_base_url() -> PyResult<String> {
let config = lqos_config::load_config().unwrap();
Ok(config.uisp_integration.url)
}
#[pyfunction]
fn uisp_auth_token() -> PyResult<String> {
let config = lqos_config::load_config().unwrap();
Ok(config.uisp_integration.token)
}