@@ -530,7 +530,7 @@ def confirm_commit(self):
530530 "configure session {} commit" .format (self .config_session ),
531531 "write memory" ,
532532 ]
533- self ._run_commands (commands )
533+ self ._run_commands (commands , encoding = "text" )
534534 self .config_session = None
535535 else :
536536 raise CommitError ("No pending commit-confirm found!" )
@@ -1202,21 +1202,82 @@ 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 [0 ] != "ntp" :
1228+ continue
1229+ if tokens [2 ] == "vrf" :
1230+ details ["network_instance" ] = tokens [3 ]
1231+ server_ip = details ["address" ] = tokens [4 ]
1232+ idx = 5
1233+ else :
1234+ server_ip = details ["address" ] = tokens [2 ]
1235+ idx = 3
1236+ try :
1237+ parsed_address = napalm .base .helpers .ipaddress .ip_address (server_ip )
1238+ family = parsed_address .version
1239+ except ValueError :
1240+ # Assume family of 4, unless local-interface has no IPv4 addresses
1241+ family = 4
1242+ while idx < len (tokens ):
1243+ if tokens [idx ] == "iburst" :
1244+ details ["iburst" ] = True
1245+ idx += 1
1246+
1247+ elif tokens [idx ] == "key" :
1248+ details ["key_id" ] = int (tokens [idx + 1 ])
1249+ idx += 2
1250+
1251+ elif tokens [idx ] == "local-interface" :
1252+ interfaces = self .get_interfaces_ip ()
1253+ intf = tokens [idx + 1 ]
1254+ if family == 6 and interfaces [intf ]["ipv6" ]:
1255+ details ["source_address" ] = list (
1256+ interfaces [intf ]["ipv6" ].keys ()
1257+ )[0 ]
1258+ elif interfaces [intf ]["ipv4" ]:
1259+ details ["source_address" ] = list (
1260+ interfaces [intf ]["ipv4" ].keys ()
1261+ )[0 ]
1262+ elif interfaces [intf ]["ipv6" ]:
1263+ details ["source_address" ] = list (
1264+ interfaces [intf ]["ipv6" ].keys ()
1265+ )[0 ]
1266+ idx += 2
1267+
1268+ elif tokens [idx ] == "version" :
1269+ details ["version" ] = int (tokens [idx + 1 ])
1270+ idx += 2
1271+
1272+ elif tokens [idx ] == "prefer" :
1273+ details ["prefer" ] = True
1274+ idx += 1
1275+ else : # Shouldn't happen
1276+ idx += 1
1277+
1278+ result [server_ip ] = details
1279+
1280+ return result
12201281
12211282 def get_ntp_stats (self ):
12221283 ntp_stats = []
@@ -1687,7 +1748,7 @@ def traceroute(
16871748 commands = []
16881749
16891750 if vrf :
1690- commands .append ("routing-context vrf {vrf}" .format (vrf = vrf ))
1751+ commands .append ("cli vrf {vrf}" .format (vrf = vrf ))
16911752
16921753 if source :
16931754 source_opt = "-s {source}" .format (source = source )
@@ -2193,7 +2254,7 @@ def ping(
21932254 commands = []
21942255
21952256 if vrf :
2196- commands .append ("routing-context vrf {vrf}" .format (vrf = vrf ))
2257+ commands .append ("cli vrf {vrf}" .format (vrf = vrf ))
21972258
21982259 command = "ping {}" .format (destination )
21992260 command += " timeout {}" .format (timeout )
0 commit comments