Skip to content

Commit

Permalink
Add options to configure new NTP servers
Browse files Browse the repository at this point in the history
When adding new NTP servers via the CLI, allow options such as iburst,
version, and the association type to be specified.

Signed-off-by: Saikrishna Arcot <sarcot@microsoft.com>
  • Loading branch information
saiarcot895 committed Oct 9, 2024
1 parent 66b41e5 commit 6ca1169
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7055,8 +7055,11 @@ def ntp(ctx):

@ntp.command('add')
@click.argument('ntp_ip_address', metavar='<ntp_ip_address>', required=True)
@click.option('--association-type', type=click.Choice(["server", "pool"], case_sensitive=False), default="server", help="Define the association type for this NTP server")
@click.option('--iburst', is_flag=True, help="Enable iburst for this NTP server")
@click.option('--version', type=int, help="Specify the version for this NTP server")
@click.pass_context
def add_ntp_server(ctx, ntp_ip_address):
def add_ntp_server(ctx, ntp_ip_address, association_type, iburst, version):
""" Add NTP server IP """
if ADHOC_VALIDATION:
if not clicommon.is_ipaddress(ntp_ip_address):
Expand All @@ -7067,10 +7070,15 @@ def add_ntp_server(ctx, ntp_ip_address):
click.echo("NTP server {} is already configured".format(ntp_ip_address))
return
else:
ntp_server_options = {}
if version:
ntp_server_options['version'] = version
if association_type != "server":
ntp_server_options['association_type'] = association_type
if iburst:
ntp_server_options['iburst'] = "on"
try:
db.set_entry('NTP_SERVER', ntp_ip_address,
{'resolve_as': ntp_ip_address,
'association_type': 'server'})
db.set_entry('NTP_SERVER', ntp_ip_address, ntp_server_options)
except ValueError as e:
ctx.fail("Invalid ConfigDB. Error: {}".format(e))
click.echo("NTP server {} added to configuration".format(ntp_ip_address))
Expand Down

0 comments on commit 6ca1169

Please sign in to comment.