summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorChristian Breunig <christian@breunig.cc>2024-05-30 13:41:44 +0200
committerGitHub <noreply@github.com>2024-05-30 13:41:44 +0200
commit1d49c9a1e1b89aa921b1ea79e43fe06ae3dfe6a0 (patch)
tree586aa7c714230d08dca34af9831b827c64167658 /python
parenta2407a3ff8ce9a7cdcc9bda8da590899b2dcd55a (diff)
parentcf07a55d183be1f4d28b8b50a0784513d91d6fe2 (diff)
downloadvyos-1x-1d49c9a1e1b89aa921b1ea79e43fe06ae3dfe6a0.tar.gz
vyos-1x-1d49c9a1e1b89aa921b1ea79e43fe06ae3dfe6a0.zip
Merge pull request #3551 from c-po/hostname-priority
hostname: T6421: enforce explicit CLI priority for host-name and domain-name
Diffstat (limited to 'python')
-rw-r--r--python/vyos/ifconfig/interface.py12
1 files changed, 7 insertions, 5 deletions
diff --git a/python/vyos/ifconfig/interface.py b/python/vyos/ifconfig/interface.py
index f0897bc21..117479ade 100644
--- a/python/vyos/ifconfig/interface.py
+++ b/python/vyos/ifconfig/interface.py
@@ -42,6 +42,7 @@ from vyos.utils.process import is_systemd_service_active
from vyos.utils.process import run
from vyos.template import is_ipv4
from vyos.template import is_ipv6
+from vyos.utils.file import read_file
from vyos.utils.network import is_intf_addr_assigned
from vyos.utils.network import is_ipv6_link_local
from vyos.utils.assertion import assert_boolean
@@ -1356,12 +1357,13 @@ class Interface(Control):
if enable and 'disable' not in self.config:
if dict_search('dhcp_options.host_name', self.config) == None:
# read configured system hostname.
- # maybe change to vyos hostd client ???
+ # maybe change to vyos-hostsd client ???
hostname = 'vyos'
- with open('/etc/hostname', 'r') as f:
- hostname = f.read().rstrip('\n')
- tmp = {'dhcp_options' : { 'host_name' : hostname}}
- self.config = dict_merge(tmp, self.config)
+ hostname_file = '/etc/hostname'
+ if os.path.isfile(hostname_file):
+ hostname = read_file(hostname_file)
+ tmp = {'dhcp_options' : { 'host_name' : hostname}}
+ self.config = dict_merge(tmp, self.config)
render(systemd_override_file, 'dhcp-client/override.conf.j2', self.config)
render(dhclient_config_file, 'dhcp-client/ipv4.j2', self.config)