From 3a169c7e3bb1dc71b4984e0568251bf0c6e3b70b Mon Sep 17 00:00:00 2001 From: Brandon Zhi Date: Wed, 29 May 2024 05:55:11 -0700 Subject: [PATCH] Fix the issue caused by the non-existence of the hostname file --- python/vyos/ifconfig/interface.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/python/vyos/ifconfig/interface.py b/python/vyos/ifconfig/interface.py index f0897bc216..6a84a600d3 100644 --- a/python/vyos/ifconfig/interface.py +++ b/python/vyos/ifconfig/interface.py @@ -1358,10 +1358,11 @@ def set_dhcp(self, enable): # read configured system hostname. # maybe change to vyos hostd 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) + if os.path.isfile('/etc/hostname'): + 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) render(systemd_override_file, 'dhcp-client/override.conf.j2', self.config) render(dhclient_config_file, 'dhcp-client/ipv4.j2', self.config)