diff options
author | Christian Poessinger <christian@poessinger.com> | 2019-02-20 22:56:35 +0100 |
---|---|---|
committer | Christian Poessinger <christian@poessinger.com> | 2019-02-20 22:56:38 +0100 |
commit | c815cfe3e075d9ff118813e67ad36dded31213af (patch) | |
tree | cf98ab66e0915f5f6c38c581dd182da73d87f6b4 /src/conf_mode/host_name.py | |
parent | 652fe81ad82ad962ab163bc95ecbeeab0f3d391d (diff) | |
download | vyos-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/conf_mode/host_name.py')
-rwxr-xr-x | src/conf_mode/host_name.py | 21 |
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) |