Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VyOS v1.4+ chronyd conf support #357

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions plugins/module_utils/network/vyos/config/ntp_global/ntp_global.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
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):
"""
Expand Down Expand Up @@ -120,6 +124,17 @@ def generate_commands(self):
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
Expand Down
24 changes: 12 additions & 12 deletions plugins/module_utils/network/vyos/rm_templates/ntp_global.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ def __init__(self, lines=None, module=None):
"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}}"],
},
Expand All @@ -50,11 +50,11 @@ def __init__(self, lines=None, module=None):
"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": {

},
Expand All @@ -66,11 +66,11 @@ def __init__(self, lines=None, module=None):
"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}}"],
},
Expand All @@ -81,11 +81,11 @@ def __init__(self, lines=None, module=None):
"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": {
},
},
Expand All @@ -95,11 +95,11 @@ def __init__(self, lines=None, module=None):
"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}}": {
Expand All @@ -115,13 +115,13 @@ def __init__(self, lines=None, module=None):
"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}}": {
Expand Down