-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhuaweibng.py
57 lines (47 loc) · 2.11 KB
/
huaweibng.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python3
import os
import yaml
import re
from termtools import TerminalTools as TT
class HuaweiConfig(object):
def __init__(self):
self.term = TT()
with open('perfiles.yaml', 'r') as f:
self.config = yaml.safe_load(f)
self.profiles = []
keys = self.config.keys()
self.profile_names = keys
for key in keys:
mydict = self.config[key]
mydict['nombre'] = key
self.profiles.append(mydict)
def GetProfiles(self):
return self.profiles
def HuaweiQoSProfile(self, nombre, download, upload, unidad):
"""
Genera los profiles de QoS en Huawei para aplicar a los clientes
"""
if not re.search('[km]', unidad.lower()):
return None
multiplicador_download = 1.25 * 1000
multiplicador_upload = 1.25 * 1000
multiplicador_pir_download = 1.25
multiplicador_pir_upload = 1.25
if unidad.lower() == 'k':
multiplicador_upload = multiplicador_upload / 1000
multiplicador_download = multiplicador_download / 1000
cir_download = int(download * multiplicador_download)
cir_upload = int(upload * multiplicador_upload)
pir_download = int(cir_download * multiplicador_pir_download)
pir_upload = int(cir_upload * multiplicador_pir_upload)
self.term.Red(f'qos-profile {nombre}')
self.term.Yellow(f' car cir {cir_download} pir {pir_download} green pass yellow pass red discard outbound')
self.term.Yellow(f' car cir {cir_upload} pir {pir_upload} green pass yellow pass red discard inbound')
print()
def GetSQLQoSProfiles(self):
"""
Genera los INSERT SQL para agregar los profiles en la base de RADIUS
"""
for profile in self.profile_names:
self.term.Green(f"INSERT INTO radgroupreply (GroupName, Attribute, Op, Value) VALUES ('{profile}', 'Huawei-Qos-Profile-Name', ':=', '{profile}');")
print(f'\n{len(self.profile_names)} INSERTs generados\n')