@@ -1202,21 +1202,78 @@ def get_arp_table(self, vrf=""):
12021202 return arp_table
12031203
12041204 def get_ntp_servers (self ):
1205- commands = [ "show running-config | section ntp" ]
1205+ result = {}
12061206
1207- raw_ntp_config = self ._run_commands (commands , encoding = "text" )[0 ].get (
1208- "output" , ""
1209- )
1207+ commands = ["show running-config | section ntp" ]
12101208
1211- ntp_config = napalm .base .helpers .textfsm_extractor (
1212- self , "ntp_peers" , raw_ntp_config
1209+ raw_ntp_config = (
1210+ self ._run_commands (commands , encoding = "text" )[0 ]
1211+ .get ("output" , "" )
1212+ .splitlines ()
12131213 )
12141214
1215- return {
1216- str (ntp_peer .get ("ntppeer" )): {}
1217- for ntp_peer in ntp_config
1218- if ntp_peer .get ("ntppeer" , "" )
1219- }
1215+ for server in raw_ntp_config :
1216+ details = {
1217+ "port" : 123 ,
1218+ "version" : 4 ,
1219+ "association_type" : "SERVER" ,
1220+ "iburst" : False ,
1221+ "prefer" : False ,
1222+ "network_instance" : "default" ,
1223+ "source_address" : "" ,
1224+ "key_id" : - 1 ,
1225+ }
1226+ tokens = server .split ()
1227+ if tokens [2 ] == "vrf" :
1228+ details ["network_instance" ] = tokens [3 ]
1229+ server_ip = details ["address" ] = tokens [4 ]
1230+ idx = 5
1231+ else :
1232+ server_ip = details ["address" ] = tokens [2 ]
1233+ idx = 3
1234+ try :
1235+ parsed_address = napalm .base .helpers .ipaddress .ip_address (server_ip )
1236+ family = parsed_address .version
1237+ except ValueError :
1238+ # Assume family of 4, unless local-interface has no IPv4 addresses
1239+ family = 4
1240+ while idx < len (tokens ):
1241+ if tokens [idx ] == "iburst" :
1242+ details ["iburst" ] = True
1243+ idx += 1
1244+
1245+ elif tokens [idx ] == "key" :
1246+ details ["key_id" ] = int (tokens [idx + 1 ])
1247+ idx += 2
1248+
1249+ elif tokens [idx ] == "local-interface" :
1250+ interfaces = self .get_interfaces_ip ()
1251+ intf = tokens [idx + 1 ]
1252+ if family == 6 and interfaces [intf ]["ipv6" ]:
1253+ details ["source_address" ] = list (
1254+ interfaces [intf ]["ipv6" ].keys ()
1255+ )[0 ]
1256+ elif interfaces [intf ]["ipv4" ]:
1257+ details ["source_address" ] = list (
1258+ interfaces [intf ]["ipv4" ].keys ()
1259+ )[0 ]
1260+ elif interfaces [intf ]["ipv6" ]:
1261+ details ["source_address" ] = list (
1262+ interfaces [intf ]["ipv6" ].keys ()
1263+ )[0 ]
1264+ idx += 2
1265+
1266+ elif tokens [idx ] == "version" :
1267+ details ["version" ] = int (tokens [idx + 1 ])
1268+ idx += 2
1269+
1270+ elif tokens [idx ] == "prefer" :
1271+ details ["prefer" ] = True
1272+ idx += 1
1273+
1274+ result [server_ip ] = details
1275+
1276+ return result
12201277
12211278 def get_ntp_stats (self ):
12221279 ntp_stats = []
0 commit comments