summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2019-02-20 22:56:35 +0100
committerChristian Poessinger <christian@poessinger.com>2019-02-20 22:56:38 +0100
commitc815cfe3e075d9ff118813e67ad36dded31213af (patch)
treecf98ab66e0915f5f6c38c581dd182da73d87f6b4 /src
parent652fe81ad82ad962ab163bc95ecbeeab0f3d391d (diff)
downloadvyos-1x-c815cfe3e075d9ff118813e67ad36dded31213af.tar.gz
vyos-1x-c815cfe3e075d9ff118813e67ad36dded31213af.zip
T1255: read in modifications from third party scripts before altering /etc/hosts
E.g. DHCP server can update /etc/hosts with somw mappings - those mappings were lost on any subsequent invocation of host_name.py
Diffstat (limited to 'src')
-rwxr-xr-xsrc/conf_mode/host_name.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/conf_mode/host_name.py b/src/conf_mode/host_name.py
index 4eedac408..3ffc7829f 100755
--- a/src/conf_mode/host_name.py
+++ b/src/conf_mode/host_name.py
@@ -149,10 +149,31 @@ def generate(config):
if not config['no_dhcp_ns']:
config['nameserver'] += dhcp_ns
+ # We have third party scripts altering /etc/hosts, too.
+ # One example are the DHCP hostname update scripts thus we need to cache in
+ # every modification first - so changing domain-name, domain-search or hostname
+ # during runtime works
+ old_hosts = ""
+ with open(config_file_hosts, 'r') as f:
+ # Skips text before the beginning of our marker.
+ # NOTE: Marker __MUST__ match the one specified in config_tmpl_hosts
+ for line in f:
+ if line.strip() == '### modifications from other scripts should be added below':
+ break
+
+ for line in f:
+ # This additional line.strip() filters empty lines
+ if line.strip():
+ old_hosts += line
+
+ # Add an additional newline
+ old_hosts += '\n'
+
tmpl = jinja2.Template(config_tmpl_hosts)
config_text = tmpl.render(config)
with open(config_file_hosts, 'w') as f:
f.write(config_text)
+ f.write(old_hosts)
tmpl = jinja2.Template(config_tmpl_resolv)
config_text = tmpl.render(config)