diff options
author | Christian Poessinger <christian@poessinger.com> | 2020-06-13 23:18:45 +0200 |
---|---|---|
committer | Christian Poessinger <christian@poessinger.com> | 2020-06-13 23:18:45 +0200 |
commit | 5b1f06336b9cc9f27788fbcd426f2fd08431e4f8 (patch) | |
tree | e221674c466505c104284782eb3ed55510c77fe3 /src/conf_mode/ntp.py | |
parent | 84abe1f9d22418d858571992cb4fbe2bb3aa34a3 (diff) | |
download | vyos-1x-5b1f06336b9cc9f27788fbcd426f2fd08431e4f8.tar.gz vyos-1x-5b1f06336b9cc9f27788fbcd426f2fd08431e4f8.zip |
ntp: T2321: add VRF support
Diffstat (limited to 'src/conf_mode/ntp.py')
-rwxr-xr-x | src/conf_mode/ntp.py | 22 |
1 files changed, 20 insertions, 2 deletions
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 |