forked from poldy79/FfsConfigGenerator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen_config_fastd.py
44 lines (38 loc) · 1.82 KB
/
gen_config_fastd.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
from string import Template
import os
def genFastdConfig(segments,gw,config,instance):
with open("fastd.conf.tpl","r") as fp:
tpl = Template(fp.read())
externalipv4 = None
externalipv6 = None
if "externalipv4" in config["gws"]["%s,%s"%(gw,instance)]:
externalipv4 = config["gws"]["%s,%s"%(gw,instance)]["externalipv4"]
if "externalipv6" in config["gws"]["%s,%s"%(gw,instance)]:
externalipv6 = config["gws"]["%s,%s"%(gw,instance)]["externalipv6"]
if not os.path.exists("etc/fastd"):
os.mkdir("etc/fastd")
for conf in (("vpn",10200,1340,"peers"),("bb",9000,1340,"bb")):
(scope,portBase,mtu,group) = conf
for seg in segments: #alternative MTU
if seg == "00":
if scope=="vpn":
port = portBase-3
else:
continue
else:
port = int(seg)+portBase
if scope=="bb":
auth = Template('include peers from "/etc/fastd/peers-ffs/vpn${seg}/${group}";').substitute(seg=seg,group=group)
else:
auth = Template('on verify "/var/lib/ffs/loadbalancer/fastd-verify.py -k /etc/fastd/peers-ffs/vpn${seg}/peers -g /var/www/html/data/gwstatus.json";').substitute(seg=seg)
bindv4 = ""
if not externalipv4 == None:
bindv4 = "bind 0.0.0.0:%i;"%(port)
bindv6 = ""
if not externalipv6 == None:
bindv6 = "bind [::]:%i;"%(port)
inst = tpl.substitute(seg=seg,bindv4=bindv4,bindv6=bindv6,group=group,scope=scope,mtu=mtu,auth=auth)
if not os.path.exists("etc/fastd/%s%s"%(scope,seg)):
os.mkdir("etc/fastd/%s%s"%(scope,seg))
with open("etc/fastd/%s%s/fastd.conf"%(scope,seg),"w") as fp:
fp.write(inst)