Mercurial > code > home > repos > infra
comparison dns.py @ 106:5faa7e3aa38f
bang can use dhcp and gets a static addr
author | drewp |
---|---|
date | Tue, 19 Jul 2022 17:39:12 -0700 |
parents | 8b8ef9d8f0fd |
children | 6ec849f1a8c9 |
comparison
equal
deleted
inserted
replaced
105:95fcc05c2747 | 106:5faa7e3aa38f |
---|---|
1 import tempfile | |
1 from pyinfra import host | 2 from pyinfra import host |
2 from pyinfra.operations import apt, files, systemd | 3 from pyinfra.operations import apt, files, systemd |
3 | 4 |
4 | 5 |
5 def dnsmasq_instance(net_name, house_iface, dhcp_range, router): | 6 def dnsmasq_instance(net_name, house_iface, dhcp_range, router, dhcp_hosts_filename='/dev/null'): |
6 files.directory(path=f'/opt/dnsmasq/{net_name}') | 7 files.directory(path=f'/opt/dnsmasq/{net_name}') |
7 files.template(src='templates/dnsmasq/dnsmasq.conf.j2', | 8 files.template(src='templates/dnsmasq/dnsmasq.conf.j2', |
8 dest=f'/opt/dnsmasq/{net_name}/dnsmasq.conf', | 9 dest=f'/opt/dnsmasq/{net_name}/dnsmasq.conf', |
9 net=net_name, | 10 net=net_name, |
10 house_iface=house_iface, | 11 house_iface=house_iface, |
11 dhcp_range=dhcp_range, | 12 dhcp_range=dhcp_range, |
12 router=router, | 13 router=router, |
13 dhcp_enabled=net_name == '10.2' and host.name == 'pipe') | 14 dhcp_enabled=net_name == '10.2' and host.name == 'pipe') |
14 files.template(src='templates/dnsmasq/hosts.j2', dest=f'/opt/dnsmasq/{net_name}/hosts', net=net_name) | 15 files.template(src='templates/dnsmasq/hosts.j2', dest=f'/opt/dnsmasq/{net_name}/hosts', net=net_name) |
15 files.template(src='/dev/null', dest=f'/opt/dnsmasq/{net_name}/dhcp_hosts', net=net_name) | 16 files.template(src=dhcp_hosts_filename, dest=f'/opt/dnsmasq/{net_name}/dhcp_hosts', net=net_name) |
16 | 17 |
17 files.template(src='templates/dnsmasq/dnsmasq.service.j2', | 18 files.template(src='templates/dnsmasq/dnsmasq.service.j2', |
18 dest=f'/etc/systemd/system/dnsmasq_{net_name}.service', | 19 dest=f'/etc/systemd/system/dnsmasq_{net_name}.service', |
19 net=net_name) | 20 net=net_name) |
20 if net_name == '10.2': | 21 if net_name == '10.2': |
35 | 36 |
36 elif host.name == 'pipe': | 37 elif host.name == 'pipe': |
37 apt.packages(packages=['dnsmasq']) | 38 apt.packages(packages=['dnsmasq']) |
38 systemd.service(service='dnsmasq', enabled=False, running=False) | 39 systemd.service(service='dnsmasq', enabled=False, running=False) |
39 files.directory(path='/opt/dnsmasq') | 40 files.directory(path='/opt/dnsmasq') |
40 dnsmasq_instance('10.2', house_iface='eth1', dhcp_range='10.2.0.20,10.2.0.120', router='10.2.0.3') | 41 dh = tempfile.NamedTemporaryFile() |
42 dh.write(b'''\ | |
43 60:e3:27:04:4a:85,bang,10.2.0.1,24h | |
44 ''') | |
45 dh.flush() | |
46 dnsmasq_instance('10.2', house_iface='eth1', dhcp_range='10.2.0.20,10.2.0.120', router='10.2.0.3', dhcp_hosts_filename=dh.name) | |
41 | 47 |
42 else: | 48 else: |
43 pass | 49 pass |