@@ -200,6 +200,26 @@ def augment_routes(d, attribs): # augment routes with attributes
200
200
)
201
201
if d .get ("vni" , 0 ) == 0 :
202
202
d ["vni" ] = "-"
203
+ d ["_rt" ] = "," .join (
204
+ [
205
+ x_comm .split ("target:" )[1 ]
206
+ for x_comm in d .get ("communities" , {}).get (
207
+ "ext-community" , []
208
+ )
209
+ if "target:" in x_comm
210
+ ]
211
+ )
212
+ d ["_esi_lbl" ] = "," .join (
213
+ [
214
+ str (x_comm .split ("esi-label:" )[1 ])
215
+ .replace ("Single-Active" , "S-A" )
216
+ .replace ("All-Active" , "A-A" )
217
+ for x_comm in d .get ("communities" , {}).get (
218
+ "ext-community" , []
219
+ )
220
+ if "esi-label:" in x_comm
221
+ ]
222
+ )
203
223
return d
204
224
else :
205
225
return {k : augment_routes (v , attribs ) for k , v in d .items ()}
@@ -240,11 +260,11 @@ def augment_routes(d, attribs): # augment routes with attributes
240
260
+ ROUTE_TYPE [route_type ] # type: ignore
241
261
+ '"[]' ,
242
262
"RIB_EVPN_JMESPATH_ATTRS" : {
243
- "1" : '.{RD:"route-distinguisher", peer:neighbor, ESI:esi, Tag:"ethernet-tag-id",vni:vni, "next-hop ":"next-hop", origin:origin , "0_st":"_r_state"}}' ,
244
- "2" : '.{RD:"route-distinguisher", peer:neighbor, ESI:esi, "MAC":"mac-address", "IP":"ip-address",vni:vni,"next-hop":"next-hop", origin:origin , "0_st":"_r_state"}}' ,
245
- "3" : '.{RD:"route-distinguisher", peer:neighbor, Tag:"ethernet-tag-id", "next-hop":"next-hop", origin:origin, "0_st":"_r_state"}}' ,
246
- "4" : '.{RD:"route-distinguisher", peer:neighbor, ESI:esi, "next-hop":"next-hop", origin:origin, "0_st":"_r_state"}}' ,
247
- "5" : '.{RD:"route-distinguisher", peer:neighbor, lpref:"local-pref", "IP-Pfx":"ip-prefix",vni:vni, med:med, "next-hop":"next-hop", GW:"gateway-ip",origin:origin, "0_st":"_r_state"}}' ,
263
+ "1" : '.{RD:"route-distinguisher", peer:neighbor, ESI:esi, Tag:"ethernet-tag-id",vni:vni, "NextHop ":"next-hop", RT:"_rt", "esi-lbl":"_esi_lbl" , "0_st":"_r_state"}}' ,
264
+ "2" : '.{RD:"route-distinguisher", RT:"_rt", peer:neighbor, ESI:esi, "MAC":"mac-address", "IP":"ip-address",vni:vni,"next-hop":"next-hop", "0_st":"_r_state"}}' ,
265
+ "3" : '.{RD:"route-distinguisher", RT:"_rt", peer:neighbor, Tag:"ethernet-tag-id", "next-hop":"next-hop", origin:origin, "0_st":"_r_state"}}' ,
266
+ "4" : '.{RD:"route-distinguisher", RT:"_rt", peer:neighbor, ESI:esi, "next-hop":"next-hop", origin:origin, "0_st":"_r_state"}}' ,
267
+ "5" : '.{RD:"route-distinguisher", RT:"_rt", peer:neighbor, lpref:"local-pref", "IP-Pfx":"ip-prefix",vni:vni, med:med, "next-hop":"next-hop", GW:"gateway-ip",origin:origin, "0_st":"_r_state"}}' ,
248
268
},
249
269
},
250
270
}
@@ -268,7 +288,7 @@ def augment_routes(d, attribs): # augment routes with attributes
268
288
+ ROUTE_FAMILY [route_fam ]
269
289
+ '"."local-rib"."routes"[]'
270
290
+ '.{neighbor:neighbor, "0_st":"_r_state", "Pfx":prefix, "lpref":"local-pref", med:med, "next-hop":"next-hop","as-path":"as-path".segment[0].member,\
271
- "communities":[communities.community, communities."large-community"][]|join(\' ,\' ,@)}}' ,
291
+ "communities":[communities.community, communities."large-community"][]|join(\' , \' ,@)}}' ,
272
292
},
273
293
3 : {
274
294
"RIB_IP_PATH" : (
@@ -538,9 +558,9 @@ def get_rib_ipv4(
538
558
continue
539
559
for route in ni ["route-table" ]["ipv4-unicast" ]["route" ]:
540
560
if route ["active" ]:
541
- route ["active" ] = "Yes "
561
+ route ["active" ] = "yes "
542
562
else :
543
- route ["active" ] = "No "
563
+ route ["active" ] = "no "
544
564
if "next-hop-group" in route :
545
565
leaked = False
546
566
if "origin-network-instance" in route :
@@ -552,30 +572,34 @@ def get_rib_ipv4(
552
572
nh_ni = ni ["name" ]
553
573
route ["_next-hop" ] = [
554
574
nh .get ("ip-address" )
555
- for nh in nhgroup_mapping [nh_ni ][route ["next-hop-group" ]]
575
+ for nh in nhgroup_mapping [nh_ni ].get (
576
+ route ["next-hop-group" ], {}
577
+ )
556
578
]
557
579
558
580
route ["_nh_itf" ] = [
559
581
nh .get ("subinterface" ) + f"@vrf:{ nh_ni } "
560
582
if leaked
561
583
else nh .get ("subinterface" )
562
- for nh in nhgroup_mapping [nh_ni ][route ["next-hop-group" ]]
584
+ for nh in nhgroup_mapping [nh_ni ].get (
585
+ route ["next-hop-group" ], {}
586
+ )
563
587
if nh .get ("subinterface" )
564
588
]
565
589
if len (route ["_nh_itf" ]) == 0 :
566
590
route ["_nh_itf" ] = [
567
591
nh .get ("tunnel" )
568
- for nh in nhgroup_mapping [nh_ni ][
569
- route ["next-hop-group" ]
570
- ]
592
+ for nh in nhgroup_mapping [nh_ni ]. get (
593
+ route ["next-hop-group" ], {}
594
+ )
571
595
if nh .get ("tunnel" )
572
596
]
573
597
if len (route ["_nh_itf" ]) == 0 :
574
598
resolving_routes = [
575
599
nh .get ("resolving-route" , {})
576
- for nh in nhgroup_mapping [nh_ni ][
577
- route ["next-hop-group" ]
578
- ]
600
+ for nh in nhgroup_mapping [nh_ni ]. get (
601
+ route ["next-hop-group" ], {}
602
+ )
579
603
if nh .get ("resolving-route" )
580
604
]
581
605
# if len(resolving_routes) > 0:
@@ -589,7 +613,7 @@ def get_nwi_itf(self, nw_instance: str = "*") -> Dict[str, Any]:
589
613
path_spec = {
590
614
"path" : f"/network-instance[name={ nw_instance } ]" ,
591
615
"jmespath" : '"network-instance"[].{NI:name,oper:"oper-state",type:type,"router-id":protocols.bgp."router-id",\
592
- itfs: interface[].{Subitf:name,"if-oper":"oper-state", ipv4:ipv4.address[]."ip-prefix",\
616
+ itfs: interface[].{Subitf:name,"assoc-ni":"_other_ni"," if-oper":"oper-state", ipv4:ipv4.address[]."ip-prefix",\
593
617
vlan:vlan.encap."single-tagged"."vlan-id", "mtu":"_mtu"}}' ,
594
618
"datatype" : "state" ,
595
619
}
@@ -609,21 +633,31 @@ def get_nwi_itf(self, nw_instance: str = "*") -> Dict[str, Any]:
609
633
for ni in resp [0 ].get ("network-instance" , {}):
610
634
for ni_itf in ni .get ("interface" , []):
611
635
ni_itf .update (subitf .get (ni_itf ["name" ], {}))
636
+ if ni_itf ["name" ].startswith ("irb" ):
637
+ ni_itf ["_other_ni" ] = " " .join (
638
+ f"{ vrf ['name' ]} "
639
+ for vrf in resp [0 ].get ("network-instance" , {})
640
+ if ni_itf ["name" ] in [i ["name" ] for i in vrf ["interface" ]]
641
+ and vrf ["name" ] != ni ["name" ]
642
+ )
612
643
613
644
res = jmespath .search (path_spec ["jmespath" ], resp [0 ])
614
645
return {"nwi_itfs" : res }
615
646
616
647
def get_lag (self , lag_id : str = "*" ) -> Dict [str , Any ]:
617
648
path_spec = {
618
649
"path" : f"/interface[name=lag{ lag_id } ]" ,
619
- "jmespath" : '"interface"[].{lag:name, oper:"oper-state",mtu:mtu,num:lag.member|length(@), "min":lag."min-links",desc:description, type:lag."lag-type", speed:lag."lag-speed","stby-sig":ethernet."standby-signaling",\
650
+ "jmespath" : '"interface"[].{lag:name, oper:"oper-state",mtu:mtu,"min":lag."min-links",desc:description, type:lag."lag-type", speed:lag."lag-speed","stby-sig":ethernet."standby-signaling",\
620
651
"lacp-key":lag.lacp."admin-key","lacp-itvl":lag.lacp.interval,"lacp-mode":lag.lacp."lacp-mode","lacp-sysid":lag.lacp."system-id-mac","lacp-prio":lag.lacp."system-priority",\
621
652
members:lag.member[].{"member-itf":name, "member-oper":"oper-state","act":lacp."activity"}}' ,
622
653
"datatype" : "state" ,
623
654
}
624
655
resp = self .get (
625
656
paths = [path_spec .get ("path" , "" )], datatype = path_spec ["datatype" ]
626
657
)
658
+ for itf in resp [0 ].get ("interface" , []):
659
+ for member in itf .get ("lag" , {}).get ("member" , []):
660
+ member ["name" ] = str (member .get ("name" , "" )).replace ("ethernet" , "et" )
627
661
res = jmespath .search (path_spec ["jmespath" ], resp [0 ])
628
662
return {"lag" : res }
629
663
0 commit comments