Skip to content

Commit 0873422

Browse files
authored
[cfggen] Allow sku with no alias mapping and minigraph with no png (#335)
* [cfggen] Allow sku with no alias mapping and minigraph with no png * Add alias mapping for minigraph_neighbor keys
1 parent 1b240e8 commit 0873422

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

src/sonic-config-engine/minigraph.py

+17-18
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,14 @@ def parse_png(png, hname):
6565
startport = link.find(str(QName(ns, "StartPort"))).text
6666

6767
if enddevice == hname:
68+
if port_alias_map.has_key(endport):
69+
endport = port_alias_map[endport]
6870
neighbors[endport] = {'name': startdevice, 'port': startport}
6971
else:
72+
if port_alias_map.has_key(startport):
73+
endport = port_alias_map[startport]
7074
neighbors[startport] = {'name': enddevice, 'port': endport}
75+
7176
if child.tag == str(QName(ns, "Devices")):
7277
for device in child.findall(str(QName(ns, "Device"))):
7378
lo_addr = None
@@ -174,7 +179,10 @@ def parse_dpg(dpg, hname):
174179
pcintfname = pcintf.find(str(QName(ns, "Name"))).text
175180
pcintfmbr = pcintf.find(str(QName(ns, "AttachTo"))).text
176181
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
178186

179187
lointfs = child.find(str(QName(ns, "LoopbackIPInterfaces")))
180188
lo_intfs = []
@@ -210,10 +218,14 @@ def parse_dpg(dpg, hname):
210218
vlanid = vintf.find(str(QName(ns, "VlanID"))).text
211219
vintfmbr = vintf.find(str(QName(ns, "AttachTo"))).text
212220
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}
214225
for addrtuple in vlan_map.get(vintfname, []):
215226
vlan_attributes.update(addrtuple)
216227
vlan_intfs.append(copy.deepcopy(vlan_attributes))
228+
217229

218230
return intfs, lo_intfs, mgmt_intf, vlan_intfs, pc_intfs
219231
return None, None, None, None, None
@@ -352,19 +364,6 @@ def parse_xml(filename, platform=None):
352364
elif child.tag == str(QName(ns, "UngDec")):
353365
(u_neighbors, u_devices, _, _, _, _) = parse_png(child, hostname)
354366

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-
368367
Tree = lambda: defaultdict(Tree)
369368

370369
results = Tree()
@@ -385,15 +384,15 @@ def parse_xml(filename, platform=None):
385384
results['minigraph_underlay_neighbors'] = u_neighbors
386385
results['minigraph_underlay_devices'] = u_devices
387386
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)
390390
results['minigraph_hostname'] = hostname
391391
results['inventory_hostname'] = hostname
392392
results['alias_map'] = alias_map_list
393393

394394
return results
395395

396-
397396
port_alias_map = {}
398397

399398

0 commit comments

Comments
 (0)