-
Notifications
You must be signed in to change notification settings - Fork 0
/
genconf.py
40 lines (30 loc) · 1.03 KB
/
genconf.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
with open('dhcpd.conf') as f:
lines = f.readlines()
hostname=''
mac=''
mac_host = {'d0-67-e5-e8-d4-85':'elcapitan3a'}
host_mac = {v:k for k,v in mac_host.items()}
for line in lines:
if 'host ' in line:
hostname = line.split(' ')[-2]
if "hardware" in line:
mac = line.split(' ')[-1][:-2].replace(':', '-')
mac_host[mac] = hostname
host_mac[hostname] = mac
host_mac
import jinja2
e = jinja2.Environment()
tpl7 = e.from_string(open('centos7.tpl').read())
tpl8 = e.from_string(open('centos8.tpl').read())
for i in range(1,62):
hostname = f'c{i}'
mac = host_mac[hostname]
with open(f'centos7/{hostname}-{mac}.cfg', 'w') as f:
f.write(tpl7.render(hostname=hostname))
with open(f'centos8/{hostname}-{mac}.cfg', 'w') as f:
f.write(tpl8.render(hostname=hostname))
tpl = e.from_string(open('pxemenu.tpl').read())
for mac in mac_host.keys():
hostname = mac_host[mac]
with open(f'pxelinux.cfg/01-{mac}', 'w') as f:
f.write(tpl.render(mac=mac, hostname=hostname))