@@ -251,6 +251,15 @@ def parse_asic_png(png, asic_name, hostname):
251
251
devices [name ] = device_data
252
252
return (neighbors , devices , port_speeds )
253
253
254
+ def parse_loopback_intf (child ):
255
+ lointfs = child .find (str (QName (ns , "LoopbackIPInterfaces" )))
256
+ lo_intfs = {}
257
+ for lointf in lointfs .findall (str (QName (ns1 , "LoopbackIPInterface" ))):
258
+ intfname = lointf .find (str (QName (ns , "AttachTo" ))).text
259
+ ipprefix = lointf .find (str (QName (ns1 , "PrefixStr" ))).text
260
+ lo_intfs [(intfname , ipprefix )] = {}
261
+ return lo_intfs
262
+
254
263
def parse_dpg (dpg , hname ):
255
264
aclintfs = None
256
265
mgmtintfs = None
@@ -269,7 +278,6 @@ def parse_dpg(dpg, hname):
269
278
"""
270
279
if mgmtintfs is None and child .find (str (QName (ns , "ManagementIPInterfaces" ))) is not None :
271
280
mgmtintfs = child .find (str (QName (ns , "ManagementIPInterfaces" )))
272
-
273
281
hostname = child .find (str (QName (ns , "Hostname" )))
274
282
if hostname .text .lower () != hname .lower ():
275
283
continue
@@ -290,12 +298,7 @@ def parse_dpg(dpg, hname):
290
298
ipprefix = ipintf .find (str (QName (ns , "Prefix" ))).text
291
299
intfs [(intfname , ipprefix )] = {}
292
300
293
- lointfs = child .find (str (QName (ns , "LoopbackIPInterfaces" )))
294
- lo_intfs = {}
295
- for lointf in lointfs .findall (str (QName (ns1 , "LoopbackIPInterface" ))):
296
- intfname = lointf .find (str (QName (ns , "AttachTo" ))).text
297
- ipprefix = lointf .find (str (QName (ns1 , "PrefixStr" ))).text
298
- lo_intfs [(intfname , ipprefix )] = {}
301
+ lo_intfs = parse_loopback_intf (child )
299
302
300
303
mvrfConfigs = child .find (str (QName (ns , "MgmtVrfConfigs" )))
301
304
mvrf = {}
@@ -452,6 +455,13 @@ def parse_dpg(dpg, hname):
452
455
return intfs , lo_intfs , mvrf , mgmt_intf , vlans , vlan_members , pcs , pc_members , acls , vni
453
456
return None , None , None , None , None , None , None , None , None , None
454
457
458
+ def parse_host_loopback (dpg , hname ):
459
+ for child in dpg :
460
+ hostname = child .find (str (QName (ns , "Hostname" )))
461
+ if hostname .text .lower () != hname .lower ():
462
+ continue
463
+ lo_intfs = parse_loopback_intf (child )
464
+ return lo_intfs
455
465
456
466
def parse_cpg (cpg , hname ):
457
467
bgp_sessions = {}
@@ -826,6 +836,7 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw
826
836
cloudtype = None
827
837
hostname = None
828
838
linkmetas = {}
839
+ host_lo_intfs = None
829
840
830
841
# hostname is the asic_name, get the asic_id from the asic_name
831
842
if asic_name is not None :
@@ -867,6 +878,7 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw
867
878
else :
868
879
if child .tag == str (QName (ns , "DpgDec" )):
869
880
(intfs , lo_intfs , mvrf , mgmt_intf , vlans , vlan_members , pcs , pc_members , acls , vni ) = parse_dpg (child , asic_name )
881
+ host_lo_intfs = parse_host_loopback (child , hostname )
870
882
elif child .tag == str (QName (ns , "CpgDec" )):
871
883
(bgp_sessions , bgp_asn , bgp_peers_with_range , bgp_monitors ) = parse_cpg (child , asic_name )
872
884
enable_internal_bgp_session (bgp_sessions , filename , asic_name )
@@ -930,6 +942,12 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw
930
942
for lo_intf in lo_intfs :
931
943
results ['LOOPBACK_INTERFACE' ][lo_intf ] = lo_intfs [lo_intf ]
932
944
results ['LOOPBACK_INTERFACE' ][lo_intf [0 ]] = {}
945
+
946
+ if host_lo_intfs is not None :
947
+ for host_lo_intf in host_lo_intfs :
948
+ results ['LOOPBACK_INTERFACE' ][host_lo_intf ] = host_lo_intfs [host_lo_intf ]
949
+ results ['LOOPBACK_INTERFACE' ][host_lo_intf [0 ]] = {}
950
+
933
951
results ['MGMT_VRF_CONFIG' ] = mvrf
934
952
935
953
phyport_intfs = {}
0 commit comments