-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_dhcpd.py
50 lines (41 loc) · 1.31 KB
/
generate_dhcpd.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
from ditto import readConfig, getFilename
def getBaseConfig(domain, dns):
config = """
# dhcpd.conf
option domain-name "%s";
option domain-name-servers %s;
default-lease-time 3600;
max-lease-time 7200;
set vendor-string = option vendor-class-identifier;
ddns-update-style none;
authoritative;
log-facility local7;
""" % (domain, dns)
return config
def getTftpConfig(tftpServer, fileName):
config = """
next-server %s;
filename "%s";
""" % ( tftpServer, fileName)
return config
def createTableSubnet(name, switch, tftpServer):
config = """
subnet %s netmask %s {
range %s %s;
option routers %s;
next-server %s;
if substring (option vendor-class-identifier, 0, 9) = "docsis1.0" {
filename "cisco/%s";
}
}
""" % (switch["network"], switch["netmask"], switch["to"], switch["from"], switch["gateway"], tftpServer, name)
return config
def main():
fn = getFilename()
conf = readConfig(fn)
output = getBaseConfig(conf["general"]["domain"], conf["general"]["dns-master"])
output += getTftpConfig(conf["general"]["tftp"], conf["general"]["pxefile"])
for switch in conf["switch"]:
output += createTableSubnet(switch, conf["switch"][switch], conf["general"]["tftp"])
print(output)
main()