Skip to content

Commit c94dce7

Browse files
kannankvsjleveque
authored andcommitted
updated "show ntp" to use cgexec when management vrf is enabled (sonic-net#627)
1 parent 0b11b24 commit c94dce7

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

show/main.py

+20-3
Original file line numberDiff line numberDiff line change
@@ -1539,11 +1539,28 @@ def bgp(verbose):
15391539
#
15401540

15411541
@cli.command()
1542+
@click.pass_context
15421543
@click.option('--verbose', is_flag=True, help="Enable verbose output")
1543-
def ntp(verbose):
1544+
def ntp(ctx, verbose):
15441545
"""Show NTP information"""
1545-
cmd = "ntpq -p -n"
1546-
run_command(cmd, display_cmd=verbose)
1546+
ntpcmd = "ntpq -p -n"
1547+
if ctx.invoked_subcommand is None:
1548+
cmd = 'sonic-cfggen -d --var-json "MGMT_VRF_CONFIG"'
1549+
1550+
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
1551+
res = p.communicate()
1552+
if p.returncode == 0 :
1553+
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
1554+
mvrf_dict = json.loads(p.stdout.read())
1555+
1556+
# if the mgmtVrfEnabled attribute is configured, check the value
1557+
# and print Enabled or Disabled accordingly.
1558+
if 'mgmtVrfEnabled' in mvrf_dict['vrf_global']:
1559+
if (mvrf_dict['vrf_global']['mgmtVrfEnabled'] == "true"):
1560+
#ManagementVRF is enabled. Call ntpq using cgexec
1561+
ntpcmd = "cgexec -g l3mdev:mgmt ntpq -p -n"
1562+
run_command(ntpcmd, display_cmd=verbose)
1563+
15471564

15481565

15491566
#

0 commit comments

Comments
 (0)