diff options
author | omnom62 <75066712+omnom62@users.noreply.github.com> | 2024-11-19 20:35:31 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-19 10:35:31 +0000 |
commit | 04c837af1cf89ff42adc42062df48a0dd209a0e1 (patch) | |
tree | a67c6f3dd2e07ec5bd742b294b1ed423171f9655 /plugins | |
parent | 67cda0147ab54136ef0604427c5a01a7f4b21986 (diff) | |
download | vyos.vyos-04c837af1cf89ff42adc42062df48a0dd209a0e1.tar.gz vyos.vyos-04c837af1cf89ff42adc42062df48a0dd209a0e1.zip |
T6832: VyOS v1.4+ chronyd conf support (#357)
* VyOS v1.4+ chronyd conf support
* template typo fix
* Making replace tool more robust by distinctive placeholder
* allow-clients workaround
* test for ntp_global and v1.4
* sanity and change log
* sanity fix
* updates to tests (dynamic >.pool) and docs
* doc update 'system' > 'service'
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/module_utils/network/vyos/config/ntp_global/ntp_global.py | 15 | ||||
-rw-r--r-- | plugins/module_utils/network/vyos/rm_templates/ntp_global.py | 24 |
2 files changed, 27 insertions, 12 deletions
diff --git a/plugins/module_utils/network/vyos/config/ntp_global/ntp_global.py b/plugins/module_utils/network/vyos/config/ntp_global/ntp_global.py index 106faac..0af1af5 100644 --- a/plugins/module_utils/network/vyos/config/ntp_global/ntp_global.py +++ b/plugins/module_utils/network/vyos/config/ntp_global/ntp_global.py @@ -31,6 +31,10 @@ from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.rm_template NtpTemplate, ) +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import get_os_version + +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.utils.version import LooseVersion + class Ntp_global(ResourceModule): """ @@ -120,6 +124,17 @@ class Ntp_global(ResourceModule): for k, want in iteritems(wantd): self._compare(want=want, have=haved.pop(k, {})) + if LooseVersion(get_os_version(self._module)) >= LooseVersion("1.4"): + path = "service" + ac = "allow-client" + else: + path = "system" + ac = "allow-clients" + + if self.commands: + self.commands = [cl.replace('%%path%%', path) for cl in self.commands] + self.commands = [nc.replace('%%ac%%', ac) for nc in self.commands] + def _compare(self, want, have): """Leverages the base class `compare()` method and populates the list of commands to be run by comparing diff --git a/plugins/module_utils/network/vyos/rm_templates/ntp_global.py b/plugins/module_utils/network/vyos/rm_templates/ntp_global.py index 33d173e..1e011dd 100644 --- a/plugins/module_utils/network/vyos/rm_templates/ntp_global.py +++ b/plugins/module_utils/network/vyos/rm_templates/ntp_global.py @@ -35,11 +35,11 @@ class NtpTemplate(NetworkTemplate): "name": "allow_clients", "getval": re.compile( r""" - ^set\ssystem\sntp\sallow-clients\saddress (\s(?P<ipaddress>\S+))? + ^set\s(?P<path>system|service)?\sntp\s(?P<ac>allow-clients|allow-client)?\saddress (\s(?P<ipaddress>\S+))? $""", re.VERBOSE, ), - "setval": "system ntp allow-clients address {{allow_clients}}", + "setval": "%%path%% ntp %%ac%% address {{allow_clients}}", "result": { "allow_clients": ["{{ipaddress}}"], }, @@ -50,11 +50,11 @@ class NtpTemplate(NetworkTemplate): "name": "allow_clients_delete", "getval": re.compile( r""" - ^set\ssystem\sntp\sallow-clients + ^set\s(?P<path>system|service)?\sntp\s(?P<ac>allow-clients|allow-client)? $""", re.VERBOSE, ), - "setval": "system ntp allow-clients", + "setval": "%%path%% ntp %%ac%%", "result": { }, @@ -66,11 +66,11 @@ class NtpTemplate(NetworkTemplate): "name": "listen_addresses", "getval": re.compile( r""" - ^set\ssystem\sntp\slisten-address (\s(?P<ip_address>\S+))? + ^set\s(?P<path>system|service)?\sntp\slisten-address (\s(?P<ip_address>\S+))? $""", re.VERBOSE, ), - "setval": "system ntp listen-address {{listen_addresses}}", + "setval": "%%path%% ntp listen-address {{listen_addresses}}", "result": { "listen_addresses": ["{{ip_address}}"], }, @@ -81,11 +81,11 @@ class NtpTemplate(NetworkTemplate): "name": "listen_addresses_delete", "getval": re.compile( r""" - ^set\ssystem\sntp\slisten-address + ^set\s(?P<path>system|service)?\sntp\slisten-address $""", re.VERBOSE, ), - "setval": "system ntp listen-address", + "setval": "%%path%% ntp listen-address", "result": { }, }, @@ -95,11 +95,11 @@ class NtpTemplate(NetworkTemplate): "name": "server", "getval": re.compile( r""" - ^set\ssystem\sntp\sserver (\s(?P<name>\S+))? + ^set\s(?P<path>system|service)?\sntp\sserver (\s(?P<name>\S+))? $""", re.VERBOSE, ), - "setval": "system ntp server {{server}}", + "setval": "%%path%% ntp server {{server}}", "result": { "servers": { "{{name}}": { @@ -115,13 +115,13 @@ class NtpTemplate(NetworkTemplate): "name": "options", "getval": re.compile( r""" - ^set\ssystem\sntp\sserver + ^set\s(?P<path>system|service)?\sntp\sserver \s(?P<name>\S+) \s(?P<options>noselect|dynamic|pool|preempt|prefer)? $""", re.VERBOSE, ), - "setval": "system ntp server {{server}} {{options}}", + "setval": "%%path%% ntp server {{server}} {{options}}", "result": { "servers": { "{{name}}": { |