Skip to content

Commit 92c261e

Browse files
T6561: Add vrf aware for show ntp (#4009)
(cherry picked from commit 5f780eb) Co-authored-by: Viacheslav Hletenko <v.gletenko@vyos.io>
1 parent de2bdd1 commit 92c261e

File tree

2 files changed

+33
-20
lines changed

2 files changed

+33
-20
lines changed

op-mode-definitions/ntp.xml.in

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,25 @@
66
<properties>
77
<help>Show peer status of NTP daemon</help>
88
</properties>
9-
<command>${vyos_op_scripts_dir}/ntp.py show_sourcestats</command>
9+
<command>sudo ${vyos_op_scripts_dir}/ntp.py show_sourcestats</command>
1010
<children>
1111
<node name="activity">
1212
<properties>
1313
<help>Report the number of servers and peers that are online and offline</help>
1414
</properties>
15-
<command>${vyos_op_scripts_dir}/ntp.py show_activity</command>
15+
<command>sudo ${vyos_op_scripts_dir}/ntp.py show_activity</command>
1616
</node>
1717
<node name="sources">
1818
<properties>
1919
<help>Show information about the current time sources being accessed</help>
2020
</properties>
21-
<command>${vyos_op_scripts_dir}/ntp.py show_sources</command>
21+
<command>sudo ${vyos_op_scripts_dir}/ntp.py show_sources</command>
2222
</node>
2323
<node name="system">
2424
<properties>
2525
<help>Show parameters about the system clock performance</help>
2626
</properties>
27-
<command>${vyos_op_scripts_dir}/ntp.py show_tracking</command>
27+
<command>sudo ${vyos_op_scripts_dir}/ntp.py show_tracking</command>
2828
</node>
2929
</children>
3030
</node>

src/op_mode/ntp.py

+29-16
Original file line numberDiff line numberDiff line change
@@ -110,49 +110,62 @@ def _is_configured():
110110
if not config.exists("service ntp"):
111111
raise vyos.opmode.UnconfiguredSubsystem("NTP service is not enabled.")
112112

113+
def _extend_command_vrf():
114+
config = ConfigTreeQuery()
115+
if config.exists('service ntp vrf'):
116+
vrf = config.value('service ntp vrf')
117+
return f'ip vrf exec {vrf} '
118+
return ''
119+
120+
113121
def show_activity(raw: bool):
114122
_is_configured()
115123
command = f'chronyc'
116124

117125
if raw:
118-
command += f" -c activity"
119-
return _get_raw_data(command)
126+
command += f" -c activity"
127+
return _get_raw_data(command)
120128
else:
121-
command += f" activity"
122-
return cmd(command)
129+
command = _extend_command_vrf() + command
130+
command += f" activity"
131+
return cmd(command)
123132

124133
def show_sources(raw: bool):
125134
_is_configured()
126135
command = f'chronyc'
127136

128137
if raw:
129-
command += f" -c sources"
130-
return _get_raw_data(command)
138+
command += f" -c sources"
139+
return _get_raw_data(command)
131140
else:
132-
command += f" sources -v"
133-
return cmd(command)
141+
command = _extend_command_vrf() + command
142+
command += f" sources -v"
143+
return cmd(command)
134144

135145
def show_tracking(raw: bool):
136146
_is_configured()
137147
command = f'chronyc'
138148

139149
if raw:
140-
command += f" -c tracking"
141-
return _get_raw_data(command)
150+
command += f" -c tracking"
151+
return _get_raw_data(command)
142152
else:
143-
command += f" tracking"
144-
return cmd(command)
153+
command = _extend_command_vrf() + command
154+
command += f" tracking"
155+
return cmd(command)
145156

146157
def show_sourcestats(raw: bool):
147158
_is_configured()
148159
command = f'chronyc'
149160

150161
if raw:
151-
command += f" -c sourcestats"
152-
return _get_raw_data(command)
162+
command += f" -c sourcestats"
163+
return _get_raw_data(command)
153164
else:
154-
command += f" sourcestats -v"
155-
return cmd(command)
165+
command = _extend_command_vrf() + command
166+
command += f" sourcestats -v"
167+
return cmd(command)
168+
156169

157170
if __name__ == '__main__':
158171
try:

0 commit comments

Comments
 (0)