summaryrefslogtreecommitdiff
path: root/src/conf_mode/host_name.py
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@baturin.org>2018-05-17 06:50:40 +0200
committerDaniil Baturin <daniil@baturin.org>2018-05-17 06:50:40 +0200
commitaf97e7d09644cd14b7cd0c2aab42d329dcbd9ae1 (patch)
treedb6c42eb7a999c58c6bc0dc2dfaa923aa3499faf /src/conf_mode/host_name.py
parentcf596d3368a665d59ec60fe0da8ab0c3c0c97c97 (diff)
downloadvyos-1x-af97e7d09644cd14b7cd0c2aab42d329dcbd9ae1.tar.gz
vyos-1x-af97e7d09644cd14b7cd0c2aab42d329dcbd9ae1.zip
T574: fix setting the hostname on boot.
Diffstat (limited to 'src/conf_mode/host_name.py')
-rwxr-xr-xsrc/conf_mode/host_name.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/conf_mode/host_name.py b/src/conf_mode/host_name.py
index f6d091ac2..11612637c 100755
--- a/src/conf_mode/host_name.py
+++ b/src/conf_mode/host_name.py
@@ -81,8 +81,14 @@ def generate(config):
old_hostname = subprocess.check_output(['hostname']).decode().strip()
# replace the local host line
- hosts = re.sub(r"({}\s+{}.*)".format(local_addr, old_hostname),
- r"{}\t{} # VyOS entry\n".format(local_addr, config["fqdn"]), hosts)
+ vyos_host_line_re = re.compile(r"({}\s+{}.*)".format(local_addr, old_hostname))
+ vyos_host_line = "{}\t{} # VyOS entry\n".format(local_addr, config["fqdn"])
+ if re.search(vyos_host_line_re, hosts):
+ hosts = re.sub(vyos_host_line_re, vyos_host_line, hosts)
+ else:
+ # On boot (or after errors), the /etc/hosts file has no line for vyos hostname,
+ # so we have to add it
+ hosts = "{0}\n{1}".format(hosts, vyos_host_line)
with open(hosts_file, 'w') as f:
f.write(hosts)