summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rwxr-xr-xsrc/conf_mode/host_name.py34
1 files changed, 22 insertions, 12 deletions
diff --git a/src/conf_mode/host_name.py b/src/conf_mode/host_name.py
index 6cefab2fd..0ca7011f4 100755
--- a/src/conf_mode/host_name.py
+++ b/src/conf_mode/host_name.py
@@ -45,6 +45,8 @@ default_config_data = {
'static_host_mapping': {}
}
+hostsd_tag = 'system'
+
def get_config(conf):
hosts = copy.deepcopy(default_config_data)
@@ -118,24 +120,32 @@ def apply(config):
return None
## Send the updated data to vyos-hostsd
+ try:
+ hc = vyos.hostsd_client.Client()
- # vyos-hostsd uses "tags" to identify data sources
- tag = "static"
+ hc.set_host_name(config['hostname'], config['domain_name'])
- try:
- client = vyos.hostsd_client.Client()
+ hc.delete_search_domains([hostsd_tag])
+ if config['domain_search']:
+ hc.add_search_domains({hostsd_tag: config['domain_search']})
+
+ hc.delete_name_servers([hostsd_tag])
+ if config['nameserver']:
+ hc.add_name_servers({hostsd_tag: config['nameserver']})
- # Check if disable-dhcp-nameservers is configured, and if yes - delete DNS servers added by DHCP
- if config['no_dhcp_ns']:
- client.delete_name_servers('dhcp-.+')
+ # add our own tag's (system) nameservers and search to resolv.conf
+ hc.delete_name_server_tags_system(hc.get_name_server_tags_system())
+ hc.add_name_server_tags_system([hostsd_tag])
- client.set_host_name(config['hostname'], config['domain_name'], config['domain_search'])
+ # this will add the dhcp client nameservers to resolv.conf
+ for intf in config['nameservers_dhcp_interfaces']:
+ hc.add_name_server_tags_system([f'dhcp-{intf}', f'dhcpv6-{intf}'])
- client.delete_name_servers(tag)
- client.add_name_servers(tag, config['nameserver'])
+ hc.delete_hosts([hostsd_tag])
+ if config['static_host_mapping']:
+ hc.add_hosts({hostsd_tag: config['static_host_mapping']})
- client.delete_hosts(tag)
- client.add_hosts(tag, config['static_host_mapping'])
+ hc.apply()
except vyos.hostsd_client.VyOSHostsdError as e:
raise ConfigError(str(e))