From 8bfa3b7956e8e2df34a889372d6c904c46c0bfd6 Mon Sep 17 00:00:00 2001 From: yangshiping <43633727+yangshp1987@users.noreply.github.com> Date: Mon, 11 May 2020 23:51:39 +0800 Subject: [PATCH] [show] Add `ntpstat` output to `show ntp` (#861) Signed-off-by: yangshiping --- doc/Command-Reference.md | 5 +++++ show/main.py | 10 ++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/doc/Command-Reference.md b/doc/Command-Reference.md index cdee6a6d0a29..384c1f357e38 100644 --- a/doc/Command-Reference.md +++ b/doc/Command-Reference.md @@ -3997,12 +3997,17 @@ This command displays a list of NTP peers known to the server as well as a summa - Example: ``` admin@sonic:~$ show ntp + synchronised to NTP server (204.2.134.164) at stratum 3 + time correct to within 326797 ms + polling server every 1024 s + remote refid st t when poll reach delay offset jitter ============================================================================== 23.92.29.245 .XFAC. 16 u - 1024 0 0.000 0.000 0.000 *204.2.134.164 46.233.231.73 2 u 916 1024 377 3.079 0.394 0.128 ``` + ### NTP Config Commands This sub-section of commands is used to add or remove the configured NTP servers. diff --git a/show/main.py b/show/main.py index 5c19ce61676e..363895fce1e7 100755 --- a/show/main.py +++ b/show/main.py @@ -2028,20 +2028,22 @@ def bgp(verbose): @click.option('--verbose', is_flag=True, help="Enable verbose output") def ntp(ctx, verbose): """Show NTP information""" + ntpstat_cmd = "ntpstat" ntpcmd = "ntpq -p -n" if is_mgmt_vrf_enabled(ctx) is True: #ManagementVRF is enabled. Call ntpq using "ip vrf exec" or cgexec based on linux version os_info = os.uname() release = os_info[2].split('-') if parse_version(release[0]) > parse_version("4.9.0"): - ntpcmd = "ip vrf exec mgmt ntpq -p -n" + ntpstat_cmd = "sudo ip vrf exec mgmt ntpstat" + ntpcmd = "sudo ip vrf exec mgmt ntpq -p -n" else: - ntpcmd = "cgexec -g l3mdev:mgmt ntpq -p -n" + ntpstat_cmd = "sudo cgexec -g l3mdev:mgmt ntpstat" + ntpcmd = "sudo cgexec -g l3mdev:mgmt ntpq -p -n" + run_command(ntpstat_cmd, display_cmd=verbose) run_command(ntpcmd, display_cmd=verbose) - - # # 'uptime' command ("show uptime") #