Skip to content

Commit 78beb02

Browse files
committed
Rename Dnsmasqrole and add ability to override resolv.conf changes
1 parent b1b09a3 commit 78beb02

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

carthage_base/roles.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@
2424

2525
__all__ = []
2626

27-
class DhcpRole(MachineModel, template = True):
27+
class DnsmasqRole(MachineModel, template = True):
2828

2929
override_dependencies = True
30+
dnsmasq_replace_resolv_conf = True
3031

3132
dnsmasq_conf = mako_task("dhcp-dnsmasq.conf",
3233
output = "etc/dnsmasq.d/dhcp.conf",
@@ -38,21 +39,26 @@ class dhcp_customization(MachineCustomization):
3839
async def install_software(self):
3940
await self.run_command('apt', 'update')
4041
await self.run_command("apt", "-y", "install", "dnsmasq")
41-
await self.run_command('apt', '-y', 'remove', 'systemd-resolved')
42-
async with self.filesystem_access() as path:
43-
try:
44-
Path(path).joinpath("etc/resolv.conf").unlink()
45-
except FileNotFoundError:
46-
pass
47-
with Path(path).joinpath("etc/resolv.conf").open("wt") as f:
48-
f.write("nameserver 127.0.0.1\n")
42+
if self.model.dnsmasq_replace_resolv_conf:
43+
await self.run_command('apt', '-y', 'remove', 'systemd-resolved')
44+
async with self.filesystem_access() as path:
45+
try:
46+
Path(path).joinpath("etc/resolv.conf").unlink()
47+
except FileNotFoundError:
48+
pass
49+
with Path(path).joinpath("etc/resolv.conf").open("wt") as f:
50+
f.write("nameserver 127.0.0.1\n")
4951

5052
install_mako = install_mako_task('model')
5153

5254
@setup_task("restart dnsmasq")
5355
async def restart_dnsmasq(self):
5456
if not self.running: return
5557
await self.run_command('systemctl', 'restart', 'dnsmasq')
58+
__all__ += ['DnsmasqRole']
59+
60+
# temporary backward compatibility
61+
DhcpRole = DnsmasqRole
5662
__all__ += ['DhcpRole']
5763

5864
class CarthageServerRole(ImageRole):

0 commit comments

Comments
 (0)