@@ -251,6 +251,15 @@ def parse_asic_png(png, asic_name, hostname):
251251 devices [name ] = device_data
252252 return (neighbors , devices , port_speeds )
253253
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+
254263def parse_dpg (dpg , hname ):
255264 aclintfs = None
256265 mgmtintfs = None
@@ -269,7 +278,6 @@ def parse_dpg(dpg, hname):
269278 """
270279 if mgmtintfs is None and child .find (str (QName (ns , "ManagementIPInterfaces" ))) is not None :
271280 mgmtintfs = child .find (str (QName (ns , "ManagementIPInterfaces" )))
272-
273281 hostname = child .find (str (QName (ns , "Hostname" )))
274282 if hostname .text .lower () != hname .lower ():
275283 continue
@@ -290,12 +298,7 @@ def parse_dpg(dpg, hname):
290298 ipprefix = ipintf .find (str (QName (ns , "Prefix" ))).text
291299 intfs [(intfname , ipprefix )] = {}
292300
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 )
299302
300303 mvrfConfigs = child .find (str (QName (ns , "MgmtVrfConfigs" )))
301304 mvrf = {}
@@ -452,6 +455,13 @@ def parse_dpg(dpg, hname):
452455 return intfs , lo_intfs , mvrf , mgmt_intf , vlans , vlan_members , pcs , pc_members , acls , vni
453456 return None , None , None , None , None , None , None , None , None , None
454457
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
455465
456466def parse_cpg (cpg , hname ):
457467 bgp_sessions = {}
@@ -826,6 +836,7 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw
826836 cloudtype = None
827837 hostname = None
828838 linkmetas = {}
839+ host_lo_intfs = None
829840
830841 # hostname is the asic_name, get the asic_id from the asic_name
831842 if asic_name is not None :
@@ -867,6 +878,7 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw
867878 else :
868879 if child .tag == str (QName (ns , "DpgDec" )):
869880 (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 )
870882 elif child .tag == str (QName (ns , "CpgDec" )):
871883 (bgp_sessions , bgp_asn , bgp_peers_with_range , bgp_monitors ) = parse_cpg (child , asic_name )
872884 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
930942 for lo_intf in lo_intfs :
931943 results ['LOOPBACK_INTERFACE' ][lo_intf ] = lo_intfs [lo_intf ]
932944 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+
933951 results ['MGMT_VRF_CONFIG' ] = mvrf
934952
935953 phyport_intfs = {}
0 commit comments