From 6ca1169e5416108ff6275b0b194db438ebac1a52 Mon Sep 17 00:00:00 2001 From: Saikrishna Arcot Date: Tue, 8 Oct 2024 19:06:45 -0700 Subject: [PATCH] Add options to configure new NTP servers 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 --- config/main.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/config/main.py b/config/main.py index bfa6dccadc..b5d7d0a210 100644 --- a/config/main.py +++ b/config/main.py @@ -7055,8 +7055,11 @@ def ntp(ctx): @ntp.command('add') @click.argument('ntp_ip_address', metavar='', 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): @@ -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))