Skip to content

Commit

Permalink
T6561: Add vrf aware for show ntp
Browse files Browse the repository at this point in the history
  • Loading branch information
sever-sever committed Aug 22, 2024
1 parent 4b9318d commit 5f780eb
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 20 deletions.
8 changes: 4 additions & 4 deletions op-mode-definitions/ntp.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@
<properties>
<help>Show peer status of NTP daemon</help>
</properties>
<command>${vyos_op_scripts_dir}/ntp.py show_sourcestats</command>
<command>sudo ${vyos_op_scripts_dir}/ntp.py show_sourcestats</command>
<children>
<node name="activity">
<properties>
<help>Report the number of servers and peers that are online and offline</help>
</properties>
<command>${vyos_op_scripts_dir}/ntp.py show_activity</command>
<command>sudo ${vyos_op_scripts_dir}/ntp.py show_activity</command>
</node>
<node name="sources">
<properties>
<help>Show information about the current time sources being accessed</help>
</properties>
<command>${vyos_op_scripts_dir}/ntp.py show_sources</command>
<command>sudo ${vyos_op_scripts_dir}/ntp.py show_sources</command>
</node>
<node name="system">
<properties>
<help>Show parameters about the system clock performance</help>
</properties>
<command>${vyos_op_scripts_dir}/ntp.py show_tracking</command>
<command>sudo ${vyos_op_scripts_dir}/ntp.py show_tracking</command>
</node>
</children>
</node>
Expand Down
45 changes: 29 additions & 16 deletions src/op_mode/ntp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 5f780eb

Please sign in to comment.