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
5864class CarthageServerRole (ImageRole ):
0 commit comments