From 51d26ceb3a2b606c7c1123ee3141dfac77eede38 Mon Sep 17 00:00:00 2001 From: bsun-sudo <56011247+bsun-sudo@users.noreply.github.com> Date: Wed, 25 Mar 2020 10:51:47 -0700 Subject: [PATCH] [ntp]: support "show ntp" with mgmt vrf based on linux os version (#858) Co-authored-by: Bing Sun --- show/main.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/show/main.py b/show/main.py index c5add8729e3b..f1c2b77f07ea 100755 --- a/show/main.py +++ b/show/main.py @@ -9,6 +9,7 @@ import subprocess import sys import ipaddress +from pkg_resources import parse_version import click from click_default_group import DefaultGroup @@ -2002,8 +2003,14 @@ def ntp(ctx, verbose): """Show NTP information""" ntpcmd = "ntpq -p -n" if is_mgmt_vrf_enabled(ctx) is True: - #ManagementVRF is enabled. Call ntpq using cgexec - ntpcmd = "cgexec -g l3mdev:mgmt ntpq -p -n" + #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" + else: + ntpcmd = "cgexec -g l3mdev:mgmt ntpq -p -n" + run_command(ntpcmd, display_cmd=verbose)