From 5b1f06336b9cc9f27788fbcd426f2fd08431e4f8 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Sat, 13 Jun 2020 23:18:45 +0200 Subject: ntp: T2321: add VRF support --- src/conf_mode/ntp.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'src/conf_mode') diff --git a/src/conf_mode/ntp.py b/src/conf_mode/ntp.py index 05bc962c2..9180998aa 100755 --- a/src/conf_mode/ntp.py +++ b/src/conf_mode/ntp.py @@ -18,6 +18,7 @@ import os from copy import deepcopy from ipaddress import ip_network +from netifaces import interfaces from sys import exit from vyos.config import Config @@ -29,11 +30,13 @@ from vyos import airbag airbag.enable() config_file = r'/etc/ntp.conf' +systemd_override = r'/etc/systemd/system/ntp.service.d/override.conf' default_config_data = { 'servers': [], 'allowed_networks': [], - 'listen_address': [] + 'listen_address': [], + 'vrf': '' } def get_config(): @@ -80,6 +83,10 @@ def get_config(): server['options'] = options ntp['servers'].append(server) + node = ['vrf'] + if conf.exists(node): + ntp['vrf'] = conf.return_value(node) + return ntp def verify(ntp): @@ -91,6 +98,9 @@ def verify(ntp): if len(ntp['allowed_networks']) and not len(ntp['servers']): raise ConfigError('NTP server not configured') + if ntp['vrf'] and ntp['vrf'] not in interfaces(): + raise ConfigError('VRF "{vrf}" does not exist'.format(**ntp)) + return None def generate(ntp): @@ -99,6 +109,8 @@ def generate(ntp): return None render(config_file, 'ntp/ntp.conf.tmpl', ntp) + render(systemd_override, 'ntp/override.conf.tmpl', ntp, trim_blocks=True) + return None def apply(ntp): @@ -107,7 +119,13 @@ def apply(ntp): call('systemctl stop ntp.service') if os.path.exists(config_file): os.unlink(config_file) - else: + if os.path.isfile(systemd_override): + os.unlink(systemd_override) + + # Reload systemd manager configuration + call('systemctl daemon-reload') + + if ntp: call('systemctl restart ntp.service') return None -- cgit v1.2.3