summaryrefslogtreecommitdiff
path: root/src/conf_mode/host_name.py
diff options
context:
space:
mode:
authorJernej Jakob <jernej.jakob@gmail.com>2020-06-11 09:06:02 +0200
committerJernej Jakob <jernej.jakob@gmail.com>2020-06-11 22:10:47 +0200
commit469884f4f4f7977085db54d1ce6ad6842252660e (patch)
treeb563b464f44f96a6c5f1df335ea4bbefbf62e19b /src/conf_mode/host_name.py
parent49eab6aaf392d631e041a99239407f953c2d5e64 (diff)
downloadvyos-1x-469884f4f4f7977085db54d1ce6ad6842252660e.tar.gz
vyos-1x-469884f4f4f7977085db54d1ce6ad6842252660e.zip
host_name: T2486: configure vyos-hostsd
Removes and adds all required settings.
Diffstat (limited to 'src/conf_mode/host_name.py')
-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))