From fd57f3e373133fe3500b9189b48173269bb488f7 Mon Sep 17 00:00:00 2001 From: Viacheslav Hletenko Date: Thu, 22 Aug 2024 13:12:29 +0000 Subject: T6561: Add vrf aware for show ntp (cherry picked from commit 5f780ebb7f1799eb9a93218bb83561db509c7e56) --- op-mode-definitions/ntp.xml.in | 8 ++++---- src/op_mode/ntp.py | 45 +++++++++++++++++++++++++++--------------- 2 files changed, 33 insertions(+), 20 deletions(-) diff --git a/op-mode-definitions/ntp.xml.in b/op-mode-definitions/ntp.xml.in index 17250a45e..565a5edb5 100644 --- a/op-mode-definitions/ntp.xml.in +++ b/op-mode-definitions/ntp.xml.in @@ -6,25 +6,25 @@ Show peer status of NTP daemon - ${vyos_op_scripts_dir}/ntp.py show_sourcestats + sudo ${vyos_op_scripts_dir}/ntp.py show_sourcestats Report the number of servers and peers that are online and offline - ${vyos_op_scripts_dir}/ntp.py show_activity + sudo ${vyos_op_scripts_dir}/ntp.py show_activity Show information about the current time sources being accessed - ${vyos_op_scripts_dir}/ntp.py show_sources + sudo ${vyos_op_scripts_dir}/ntp.py show_sources Show parameters about the system clock performance - ${vyos_op_scripts_dir}/ntp.py show_tracking + sudo ${vyos_op_scripts_dir}/ntp.py show_tracking diff --git a/src/op_mode/ntp.py b/src/op_mode/ntp.py index e14cc46d0..6ec0fedcb 100644 --- a/src/op_mode/ntp.py +++ b/src/op_mode/ntp.py @@ -110,49 +110,62 @@ def _is_configured(): if not config.exists("service ntp"): raise vyos.opmode.UnconfiguredSubsystem("NTP service is not enabled.") +def _extend_command_vrf(): + config = ConfigTreeQuery() + if config.exists('service ntp vrf'): + vrf = config.value('service ntp vrf') + return f'ip vrf exec {vrf} ' + return '' + + def show_activity(raw: bool): _is_configured() command = f'chronyc' if raw: - command += f" -c activity" - return _get_raw_data(command) + command += f" -c activity" + return _get_raw_data(command) else: - command += f" activity" - return cmd(command) + command = _extend_command_vrf() + command + command += f" activity" + return cmd(command) def show_sources(raw: bool): _is_configured() command = f'chronyc' if raw: - command += f" -c sources" - return _get_raw_data(command) + command += f" -c sources" + return _get_raw_data(command) else: - command += f" sources -v" - return cmd(command) + command = _extend_command_vrf() + command + command += f" sources -v" + return cmd(command) def show_tracking(raw: bool): _is_configured() command = f'chronyc' if raw: - command += f" -c tracking" - return _get_raw_data(command) + command += f" -c tracking" + return _get_raw_data(command) else: - command += f" tracking" - return cmd(command) + command = _extend_command_vrf() + command + command += f" tracking" + return cmd(command) def show_sourcestats(raw: bool): _is_configured() command = f'chronyc' if raw: - command += f" -c sourcestats" - return _get_raw_data(command) + command += f" -c sourcestats" + return _get_raw_data(command) else: - command += f" sourcestats -v" - return cmd(command) + command = _extend_command_vrf() + command + command += f" sourcestats -v" + return cmd(command) + if __name__ == '__main__': try: -- cgit v1.2.3