@@ -65,9 +65,14 @@ def parse_png(png, hname):
65
65
startport = link .find (str (QName (ns , "StartPort" ))).text
66
66
67
67
if enddevice == hname :
68
+ if port_alias_map .has_key (endport ):
69
+ endport = port_alias_map [endport ]
68
70
neighbors [endport ] = {'name' : startdevice , 'port' : startport }
69
71
else :
72
+ if port_alias_map .has_key (startport ):
73
+ endport = port_alias_map [startport ]
70
74
neighbors [startport ] = {'name' : enddevice , 'port' : endport }
75
+
71
76
if child .tag == str (QName (ns , "Devices" )):
72
77
for device in child .findall (str (QName (ns , "Device" ))):
73
78
lo_addr = None
@@ -174,7 +179,10 @@ def parse_dpg(dpg, hname):
174
179
pcintfname = pcintf .find (str (QName (ns , "Name" ))).text
175
180
pcintfmbr = pcintf .find (str (QName (ns , "AttachTo" ))).text
176
181
pcmbr_list = pcintfmbr .split (';' , 1 )
177
- pc_intfs [pcintfname ]= pcmbr_list
182
+ for i ,member in enumerate (pcmbr_list ):
183
+ if port_alias_map .has_key (member ):
184
+ pcmbr_list [i ] = port_alias_map [member ]
185
+ pc_intfs [pcintfname ] = pcmbr_list
178
186
179
187
lointfs = child .find (str (QName (ns , "LoopbackIPInterfaces" )))
180
188
lo_intfs = []
@@ -210,10 +218,14 @@ def parse_dpg(dpg, hname):
210
218
vlanid = vintf .find (str (QName (ns , "VlanID" ))).text
211
219
vintfmbr = vintf .find (str (QName (ns , "AttachTo" ))).text
212
220
vmbr_list = vintfmbr .split (';' )
213
- vlan_attributes = {'name' : vintfname , 'members' : vmbr_list , 'vlanid' : vlanid }
221
+ for i ,member in enumerate (vmbr_list ):
222
+ if port_alias_map .has_key (member ):
223
+ vmbr_list [i ] = port_alias_map [member ]
224
+ vlan_attributes = {'name' : vintfname , 'members' : " " .join (vmbr_list ), 'vlanid' : vlanid }
214
225
for addrtuple in vlan_map .get (vintfname , []):
215
226
vlan_attributes .update (addrtuple )
216
227
vlan_intfs .append (copy .deepcopy (vlan_attributes ))
228
+
217
229
218
230
return intfs , lo_intfs , mgmt_intf , vlan_intfs , pc_intfs
219
231
return None , None , None , None , None
@@ -352,19 +364,6 @@ def parse_xml(filename, platform=None):
352
364
elif child .tag == str (QName (ns , "UngDec" )):
353
365
(u_neighbors , u_devices , _ , _ , _ , _ ) = parse_png (child , hostname )
354
366
355
- # Replace port with alias in Vlan interfaces members
356
- for vlan in vlan_intfs :
357
- for i ,member in enumerate (vlan ['members' ]):
358
- vlan ['members' ][i ] = port_alias_map [member ]
359
-
360
- # Convert vlan members into a space-delimited string
361
- vlan ['members' ] = " " .join (vlan ['members' ])
362
-
363
- # Replace port with alias in port channel interfaces members
364
- for pc in pc_intfs .keys ():
365
- for i ,member in enumerate (pc_intfs [pc ]):
366
- pc_intfs [pc ][i ] = port_alias_map [member ]
367
-
368
367
Tree = lambda : defaultdict (Tree )
369
368
370
369
results = Tree ()
@@ -385,15 +384,15 @@ def parse_xml(filename, platform=None):
385
384
results ['minigraph_underlay_neighbors' ] = u_neighbors
386
385
results ['minigraph_underlay_devices' ] = u_devices
387
386
results ['minigraph_as_xml' ] = mini_graph_path
388
- results ['minigraph_console' ] = get_console_info (devices , console_dev , console_port )
389
- results ['minigraph_mgmt' ] = get_mgmt_info (devices , mgmt_dev , mgmt_port )
387
+ if devices != None :
388
+ results ['minigraph_console' ] = get_console_info (devices , console_dev , console_port )
389
+ results ['minigraph_mgmt' ] = get_mgmt_info (devices , mgmt_dev , mgmt_port )
390
390
results ['minigraph_hostname' ] = hostname
391
391
results ['inventory_hostname' ] = hostname
392
392
results ['alias_map' ] = alias_map_list
393
393
394
394
return results
395
395
396
-
397
396
port_alias_map = {}
398
397
399
398
0 commit comments