diff options
author | Christian Breunig <christian@breunig.cc> | 2024-05-30 14:16:09 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-30 14:16:09 +0200 |
commit | 8d501631109534b541e20db8ef51a8a3cbd691d4 (patch) | |
tree | d052eed3904e1194dc233eee961e5055aa923ba1 /python/vyos/ifconfig | |
parent | c5fb6aecdc1fc3ca492b1641404ede1eba7a5e74 (diff) | |
parent | 013ed1d6ff6360db771cb992d8331a5dceada154 (diff) | |
download | vyos-1x-8d501631109534b541e20db8ef51a8a3cbd691d4.tar.gz vyos-1x-8d501631109534b541e20db8ef51a8a3cbd691d4.zip |
Merge pull request #3553 from vyos/mergify/bp/sagitta/pr-3551
hostname: T6421: enforce explicit CLI priority for host-name and domain-name (backport #3551)
Diffstat (limited to 'python/vyos/ifconfig')
-rw-r--r-- | python/vyos/ifconfig/interface.py | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/python/vyos/ifconfig/interface.py b/python/vyos/ifconfig/interface.py index fbbc04532..fa79395ff 100644 --- a/python/vyos/ifconfig/interface.py +++ b/python/vyos/ifconfig/interface.py @@ -39,6 +39,7 @@ from vyos.utils.network import get_interface_config from vyos.utils.process import is_systemd_service_active 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 @@ -1286,12 +1287,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) |