Add files via upload

This commit is contained in:
rchac
2020-10-02 18:00:37 -06:00
committed by GitHub
parent 45eccad7e1
commit 1e17478e7d
2 changed files with 92 additions and 12 deletions

View File

@@ -26,6 +26,7 @@ import os
import subprocess
import time
from datetime import date
from UCRM_Integration import pullUCRMCustomers, getUCRMCaps
def shell(inputCommand):
if enableActualShellCommands:
@@ -81,27 +82,47 @@ def createTestClientsPool(slash16, quantity):
######################################################## ########################################################
########################################################################################################################################
fqOrCAKE = 'fq_codel' #'fq_codel' or 'cake'
# Cake requires many specific packages and kernel changes.
# For more information visit https://www.bufferbloat.net/projects/codel/wiki/Cake/
# and https://github.com/dtaht/tc-adv
pipeBandwidthCapacityMbps = 500 # How many symmetrical Mbps are available to the edge of this test network
interfaceA = 'eth4' # Interface connected to edge
interfaceB = 'eth5' # Interface connected to core
downSpeedDict = {25:30, 50:55, 100:115}
upSpeedDict = {25:3 , 50:5, 100:15}
enableActualShellCommands = False # Allow execution of these shell commands. Default is False where commands print to console.
runShellCommandsAsSudo = False # Add 'sudo' before execution of any shell commands. Default is False.
fqOrCAKE = 'fq_codel' #'fq_codel' or 'cake'
# Cake requires many specific packages and kernel changes.
# https://www.bufferbloat.net/projects/codel/wiki/Cake/
# https://github.com/dtaht/tc-adv
pipeBandwidthCapacityMbps = 500 # How many symmetrical Mbps are available to the edge of this test network
interfaceA = 'eth4' # Interface connected to edge
interfaceB = 'eth5' # Interface connected to core
downSpeedDict = {25:30, 50:55, 100:115, 200:215, 300:315} # Define Client Plan download speed. 25, 50, 100 etc are plan identifiers.
upSpeedDict = {25:3 , 50:5, 100:15, 200:30, 300:50} # Define Client Plan upload speed
enableActualShellCommands = False # Allow shell commands. Default is False; commands print to console.
runShellCommandsAsSudo = False # Add 'sudo' before execution of any shell commands. Default is False.
importFromUCRM = False # Experimental UCRM integration
#Clients
clientsList = []
#Add arbitrary number of test clients in /16 subnet
clientsList = createTestClientsPool('100.64.X.X', 5)
#Add specific test clients
#clientsList.append((100, '100.65.8.2'))
#clientsList.append((100, '100.65.1.1'))
########################################################################################################################################
#Bring in clients from UCRM if enabled
if importFromUCRM:
tempList = pullUCRMCustomers()
for cust in tempList:
clientID, ipAddr, download, upload = cust
#Use UCRM plan speed values to place into corresponding plan defined here in LibreQoS
if download >= 300:
clientsList.append((300, ipAddr))
elif download >= 200:
clientsList.append((200, ipAddr))
elif download >= 100:
clientsList.append((100, ipAddr))
elif download >= 50:
clientsList.append((50, ipAddr))
elif download >= 25:
clientsList.append((25, ipAddr))
else:
print("Could not match customer ID " + clientID + " with a speed plan. They will be left uncapped.")
#Categorize Clients By IPv4 /16
listOfSlash16SubnetsInvolved = []
clientsListWithSubnet = []

59
UCRM_Integration.py Normal file
View File

@@ -0,0 +1,59 @@
# Copyright (C) 2020 Robert Chacón
# This file is part of LibreQoS.
#
# LibreQoS is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# LibreQoS is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with LibreQoS. If not, see <http://www.gnu.org/licenses/>.
#
# _ _ _ ___ ____
# | | (_) |__ _ __ ___ / _ \ ___/ ___|
# | | | | '_ \| '__/ _ \ | | |/ _ \___ \
# | |___| | |_) | | | __/ |_| | (_) |__) |
# |_____|_|_.__/|_| \___|\__\_\\___/____/
# v.0.3-alpha
#
import requests
#####################################################################
orgUCRMxAuthToken = ''
#####################################################################
def pullUCRMCustomers():
url = 'https://unms.exampleISP.com/crm/api/v1.0/clients?organizationId=1'
headers = {'accept':'application/json', 'x-auth-token': orgUCRMxAuthToken}
r = requests.get(url, headers=headers)
jsonData = r.json()
customerList = []
for customer in jsonData:
try:
if customer['isActive'] == True:
try:
ipAddr = customer['attributes'][0]['value']
idNum = customer['id']
download, upload = getCaps(idNum)
customerList.append((idNum, ipAddr, download, upload))
except:
print("Customer ", street, " did not have IP on UCRM")
except:
print("Failed to load customer #", customer['id'])
return customerList
def getUCRMCaps(idNum):
url = 'https://unms.exampleISP.com/crm/api/v1.0/clients/services?clientId=' + str(idNum)
headers = {'accept':'application/json', 'x-auth-token': ''}
r = requests.get(url, headers=headers)
jsonData = r.json()
for customer in jsonData:
download = customer['downloadSpeed']
upload = customer['uploadSpeed']
downUp = (download, upload)
return downUp