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

Make NTP minpoll and maxpoll config together #129

Merged
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
1 change: 1 addition & 0 deletions plugins/module_utils/network/sonic/argspec/ntp/ntp.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def __init__(self, **kwargs):
'minpoll': {'type': 'int'},
'prefer': {'type': 'bool'}
},
'required_together': [['minpoll', 'maxpoll']],
'type': 'list'
},
'source_interfaces': {
Expand Down
37 changes: 37 additions & 0 deletions plugins/module_utils/network/sonic/config/ntp/ntp.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ def _state_merged(self, want, have):

commands = diff
requests = []

self.preprocess_merge_commands(commands, want)
if commands:
requests = self.get_merge_requests(commands, have)

Expand Down Expand Up @@ -252,6 +254,41 @@ def preprocess_want(self, want, state):
if 'prefer' in server and server['prefer'] is None:
server.pop('prefer')

def search_servers(self, svr_address, servers):

found_server = dict()
if servers is not None:
for server in servers:
if server['address'] == svr_address:
found_server = server
return found_server

def preprocess_merge_commands(self, commands, want):

if 'servers' in commands and commands['servers'] is not None:
for server in commands['servers']:
if 'minpoll' in server and 'maxpoll' not in server:
want_server = dict()
if 'servers' in want:
want_server = self.search_servers(server['address'], want['servers'])

if want_server:
server['maxpoll'] = want_server['maxpoll']
else:
err_msg = "Internal error with NTP server maxpoll configuration."
self._module.fail_json(msg=err_msg, code=500)

if 'maxpoll' in server and 'minpoll' not in server:
want_server = dict()
if 'servers' in want:
want_server = self.search_servers(server['address'], want['servers'])

if want_server:
server['minpoll'] = want_server['minpoll']
else:
err_msg = "Internal error with NTP server minpoll configuration."
self._module.fail_json(msg=err_msg, code=500)

def get_merge_requests(self, configs, have):

requests = []
Expand Down
1 change: 1 addition & 0 deletions plugins/modules/sonic_ntp.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
elements: dict
description:
- List of NTP servers.
- minpoll and maxpoll are required to be configured together.
kerry-meyer marked this conversation as resolved.
Show resolved Hide resolved
suboptions:
address:
type: str
Expand Down