diff options
-rw-r--r-- | data/templates/ntp/override.conf.tmpl | 8 | ||||
-rw-r--r-- | interface-definitions/ntp.xml.in | 1 | ||||
-rwxr-xr-x | src/conf_mode/ntp.py | 22 |
3 files changed, 29 insertions, 2 deletions
diff --git a/data/templates/ntp/override.conf.tmpl b/data/templates/ntp/override.conf.tmpl new file mode 100644 index 000000000..69a73b128 --- /dev/null +++ b/data/templates/ntp/override.conf.tmpl @@ -0,0 +1,8 @@ +[Service] +ExecStart= +{% if vrf %} +ExecStart=/sbin/ip vrf exec {{ vrf }} /usr/lib/ntp/ntp-systemd-wrapper +{% else %} +ExecStart=/usr/lib/ntp/ntp-systemd-wrapper +{% endif %} + diff --git a/interface-definitions/ntp.xml.in b/interface-definitions/ntp.xml.in index 945345898..485487a42 100644 --- a/interface-definitions/ntp.xml.in +++ b/interface-definitions/ntp.xml.in @@ -76,6 +76,7 @@ </constraint> </properties> </leafNode> + #include <include/interface-vrf.xml.i> </children> </node> </children> 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 |