Compare commits
No commits in common. "d72ff013721d7f653bbf3f2f5ff3dbc05fd3ed4a" and "035576dff0f980e59e2b810d1dad6d2245fb8bdb" have entirely different histories.
d72ff01372
...
035576dff0
@ -40,3 +40,22 @@ class Config:
|
|||||||
|
|
||||||
def check(self):
|
def check(self):
|
||||||
return self.dect.check()
|
return self.dect.check()
|
||||||
|
|
||||||
|
|
||||||
|
class ExtensionConfig(ConfigBase):
|
||||||
|
def __init__(self, c):
|
||||||
|
self.num = c[0]
|
||||||
|
self._c = c[1]
|
||||||
|
|
||||||
|
|
||||||
|
class Extensions:
|
||||||
|
def __init__(self, c):
|
||||||
|
self._c = c
|
||||||
|
self.extensions = []
|
||||||
|
for e in self._c.get("extensions", {}).items():
|
||||||
|
self.extensions.append(ExtensionConfig(e))
|
||||||
|
|
||||||
|
def extensions_by_type(self, t):
|
||||||
|
for e in self.extensions:
|
||||||
|
if e.type == t:
|
||||||
|
yield e
|
||||||
|
@ -1,67 +0,0 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
|
|
||||||
class ExtensionConfig:
|
|
||||||
num = None
|
|
||||||
|
|
||||||
callgroup_members = []
|
|
||||||
dect_claim_token = None
|
|
||||||
dect_ipei = None
|
|
||||||
dialout_allowed = False
|
|
||||||
name = None
|
|
||||||
outgoing_extension = None
|
|
||||||
sip_password = None
|
|
||||||
static_target = None
|
|
||||||
trunk = False
|
|
||||||
type = None
|
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
|
||||||
for name, value in kwargs.items():
|
|
||||||
if hasattr(type(self), name):
|
|
||||||
self.__setattr__(name, value)
|
|
||||||
else:
|
|
||||||
raise Exception("Invalid config option {}".format(name))
|
|
||||||
|
|
||||||
if self.type is None:
|
|
||||||
raise Exception("Type field for extension {} is required".format(self.num))
|
|
||||||
elif self.type == "dect":
|
|
||||||
if self.dect_ipei is None and self.dect_claim_token is None:
|
|
||||||
raise Exception("dect_ipei can't be used together with dect_claim_token in extension {}".format(self.num))
|
|
||||||
elif self.type == "sip":
|
|
||||||
if self.sip_password is None:
|
|
||||||
raise Exception("sip_password is required for sip extension {}".format(self.num))
|
|
||||||
elif self.type == "static":
|
|
||||||
if self.static_target is None:
|
|
||||||
raise Exception("static_target is required for static extension {}".format(self.num))
|
|
||||||
|
|
||||||
def check_global(self, extensions):
|
|
||||||
if self.type == "callgroup":
|
|
||||||
for member in self.callgroup_members:
|
|
||||||
if member not in extensions.extensions_by_num.keys():
|
|
||||||
raise Exception("Callgroup member {} of callgroup {} does not exist as extension".format(member, self.num))
|
|
||||||
|
|
||||||
|
|
||||||
class Extensions:
|
|
||||||
extensions = []
|
|
||||||
extensions_by_num = {}
|
|
||||||
|
|
||||||
def __init__(self, c):
|
|
||||||
for num, e in c.get("extensions", {}).items():
|
|
||||||
extension_config = ExtensionConfig(**{
|
|
||||||
"num": num,
|
|
||||||
} | e)
|
|
||||||
|
|
||||||
self.extensions.append(extension_config)
|
|
||||||
|
|
||||||
if extension_config.num in self.extensions_by_num.keys():
|
|
||||||
raise Exception("Extension num already used {}".format(num))
|
|
||||||
|
|
||||||
self.extensions_by_num[num] = extension_config
|
|
||||||
|
|
||||||
for e in self.extensions:
|
|
||||||
e.check_global(self)
|
|
||||||
|
|
||||||
|
|
||||||
def extensions_by_type(self, t):
|
|
||||||
for e in self.extensions:
|
|
||||||
if e.type == t:
|
|
||||||
yield e
|
|
@ -8,7 +8,6 @@ import threading
|
|||||||
|
|
||||||
from . import config
|
from . import config
|
||||||
from . import controller
|
from . import controller
|
||||||
from . import extensions
|
|
||||||
from . import dect
|
from . import dect
|
||||||
from . import routing
|
from . import routing
|
||||||
from . import ywsd
|
from . import ywsd
|
||||||
@ -40,18 +39,6 @@ class FieldPOC:
|
|||||||
self._routing = routing.Routing(self)
|
self._routing = routing.Routing(self)
|
||||||
self._ywsd = ywsd.Ywsd(self)
|
self._ywsd = ywsd.Ywsd(self)
|
||||||
|
|
||||||
logger.info("initialising threads")
|
|
||||||
self.threads = {
|
|
||||||
"controller": threading.Thread(target=self._controller.run),
|
|
||||||
"dect": threading.Thread(target=self._dect.run),
|
|
||||||
"routing": threading.Thread(target=self._routing.run),
|
|
||||||
"ywsd": threading.Thread(target=self._ywsd.run, daemon=True),
|
|
||||||
}
|
|
||||||
|
|
||||||
# Set thread names
|
|
||||||
for name, thread in self.threads.items():
|
|
||||||
thread.name = name
|
|
||||||
|
|
||||||
def queue_all(self, msg):
|
def queue_all(self, msg):
|
||||||
"""
|
"""
|
||||||
Send message to every queue
|
Send message to every queue
|
||||||
@ -73,16 +60,21 @@ class FieldPOC:
|
|||||||
logger.info("initialization complete")
|
logger.info("initialization complete")
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
"""
|
logger.info("starting components")
|
||||||
Start FieldPOC
|
|
||||||
"""
|
|
||||||
|
|
||||||
logger.info("starting threads")
|
self._controller_thread = threading.Thread(target=self._controller.run)
|
||||||
|
self._controller_thread.start()
|
||||||
|
|
||||||
for name, thread in self.threads.items():
|
self._dect_thread = threading.Thread(target=self._dect.run)
|
||||||
thread.start()
|
self._dect_thread.start()
|
||||||
|
|
||||||
logger.info("started threads")
|
self._routing_thread = threading.Thread(target=self._routing.run)
|
||||||
|
self._routing_thread.start()
|
||||||
|
|
||||||
|
self._ywsd_thread = threading.Thread(target=self._ywsd.run, daemon=True)
|
||||||
|
self._ywsd_thread.start()
|
||||||
|
|
||||||
|
logger.info("started components")
|
||||||
|
|
||||||
def reload_extensions(self):
|
def reload_extensions(self):
|
||||||
self._load_extensions()
|
self._load_extensions()
|
||||||
@ -92,4 +84,4 @@ class FieldPOC:
|
|||||||
self.config = config.Config(json.loads(self.config_file_path.read_text()))
|
self.config = config.Config(json.loads(self.config_file_path.read_text()))
|
||||||
|
|
||||||
def _load_extensions(self):
|
def _load_extensions(self):
|
||||||
self.extensions = extensions.Extensions(json.loads(self.extensions_file_path.read_text()))
|
self.extensions = config.Extensions(json.loads(self.extensions_file_path.read_text()))
|
||||||
|
Loading…
Reference in New Issue
Block a user