From c94dce7d0c101c6ade7aa435d82927b31d7456b7 Mon Sep 17 00:00:00 2001 From: kannankvs Date: Tue, 10 Sep 2019 00:23:23 +0530 Subject: [PATCH] updated "show ntp" to use cgexec when management vrf is enabled (#627) --- show/main.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/show/main.py b/show/main.py index da4e3ae879..5a4ba17cde 100755 --- a/show/main.py +++ b/show/main.py @@ -1539,11 +1539,28 @@ def bgp(verbose): # @cli.command() +@click.pass_context @click.option('--verbose', is_flag=True, help="Enable verbose output") -def ntp(verbose): +def ntp(ctx, verbose): """Show NTP information""" - cmd = "ntpq -p -n" - run_command(cmd, display_cmd=verbose) + ntpcmd = "ntpq -p -n" + if ctx.invoked_subcommand is None: + cmd = 'sonic-cfggen -d --var-json "MGMT_VRF_CONFIG"' + + p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + res = p.communicate() + if p.returncode == 0 : + p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + mvrf_dict = json.loads(p.stdout.read()) + + # if the mgmtVrfEnabled attribute is configured, check the value + # and print Enabled or Disabled accordingly. + if 'mgmtVrfEnabled' in mvrf_dict['vrf_global']: + if (mvrf_dict['vrf_global']['mgmtVrfEnabled'] == "true"): + #ManagementVRF is enabled. Call ntpq using cgexec + ntpcmd = "cgexec -g l3mdev:mgmt ntpq -p -n" + run_command(ntpcmd, display_cmd=verbose) + #