68 lines
2.2 KiB
Python
68 lines
2.2 KiB
Python
#!/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
|