@@ -180,7 +180,6 @@ def parse_png(png, hname, dpg_ecmp_content = None):
180
180
port_speeds = {}
181
181
console_ports = {}
182
182
mux_cable_ports = {}
183
- is_storage_device = False
184
183
port_device_map = {}
185
184
png_ecmp_content = {}
186
185
FG_NHG_MEMBER = {}
@@ -253,10 +252,6 @@ def parse_png(png, hname, dpg_ecmp_content = None):
253
252
device_data ['lo_addr_v6' ] = lo_prefix_v6
254
253
devices [name ] = device_data
255
254
256
- if name == hname :
257
- if cluster and "str" in cluster .lower ():
258
- is_storage_device = True
259
-
260
255
if child .tag == str (QName (ns , "DeviceInterfaceLinks" )):
261
256
for if_link in child .findall (str (QName (ns , 'DeviceLinkBase' ))):
262
257
if str (QName (ns3 , "type" )) in if_link .attrib :
@@ -293,7 +288,7 @@ def parse_png(png, hname, dpg_ecmp_content = None):
293
288
294
289
png_ecmp_content = {"FG_NHG_MEMBER" : FG_NHG_MEMBER , "FG_NHG" : FG_NHG , "NEIGH" : NEIGH }
295
290
296
- return (neighbors , devices , console_dev , console_port , mgmt_dev , mgmt_port , port_speeds , console_ports , mux_cable_ports , is_storage_device , png_ecmp_content )
291
+ return (neighbors , devices , console_dev , console_port , mgmt_dev , mgmt_port , port_speeds , console_ports , mux_cable_ports , png_ecmp_content )
297
292
298
293
299
294
def parse_asic_external_link (link , asic_name , hostname ):
@@ -402,6 +397,7 @@ def parse_loopback_intf(child):
402
397
def parse_dpg (dpg , hname ):
403
398
aclintfs = None
404
399
mgmtintfs = None
400
+ subintfs = None
405
401
tunnelintfs = defaultdict (dict )
406
402
for child in dpg :
407
403
"""
@@ -441,6 +437,16 @@ def parse_dpg(dpg, hname):
441
437
ip_intfs_map [ipprefix ] = intfalias
442
438
lo_intfs = parse_loopback_intf (child )
443
439
440
+ subintfs = child .find (str (QName (ns , "SubInterfaces" )))
441
+ if subintfs is not None :
442
+ for subintf in subintfs .findall (str (QName (ns , "SubInterface" ))):
443
+ intfalias = subintf .find (str (QName (ns , "AttachTo" ))).text
444
+ intfname = port_alias_map .get (intfalias , intfalias )
445
+ ipprefix = subintf .find (str (QName (ns , "Prefix" ))).text
446
+ subintfvlan = subintf .find (str (QName (ns , "Vlan" ))).text
447
+ subintfname = intfname + VLAN_SUB_INTERFACE_SEPARATOR + subintfvlan
448
+ intfs [(subintfname , ipprefix )] = {}
449
+
444
450
mvrfConfigs = child .find (str (QName (ns , "MgmtVrfConfigs" )))
445
451
mvrf = {}
446
452
if mvrfConfigs != None :
@@ -1207,7 +1213,7 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw
1207
1213
elif child .tag == str (QName (ns , "CpgDec" )):
1208
1214
(bgp_sessions , bgp_internal_sessions , bgp_voq_chassis_sessions , bgp_asn , bgp_peers_with_range , bgp_monitors ) = parse_cpg (child , hostname )
1209
1215
elif child .tag == str (QName (ns , "PngDec" )):
1210
- (neighbors , devices , console_dev , console_port , mgmt_dev , mgmt_port , port_speed_png , console_ports , mux_cable_ports , is_storage_device , png_ecmp_content ) = parse_png (child , hostname , dpg_ecmp_content )
1216
+ (neighbors , devices , console_dev , console_port , mgmt_dev , mgmt_port , port_speed_png , console_ports , mux_cable_ports , png_ecmp_content ) = parse_png (child , hostname , dpg_ecmp_content )
1211
1217
elif child .tag == str (QName (ns , "UngDec" )):
1212
1218
(u_neighbors , u_devices , _ , _ , _ , _ , _ , _ ) = parse_png (child , hostname , None )
1213
1219
elif child .tag == str (QName (ns , "MetadataDeclaration" )):
@@ -1273,9 +1279,6 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw
1273
1279
1274
1280
results ['DEVICE_METADATA' ]['localhost' ]['peer_switch' ] = list (results ['PEER_SWITCH' ].keys ())[0 ]
1275
1281
1276
- if is_storage_device :
1277
- results ['DEVICE_METADATA' ]['localhost' ]['storage_device' ] = "true"
1278
-
1279
1282
# for this hostname, if sub_role is defined, add sub_role in
1280
1283
# device_metadata
1281
1284
if sub_role is not None :
@@ -1375,6 +1378,9 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw
1375
1378
elif intf [0 ][0 :11 ] == 'PortChannel' :
1376
1379
pc_intfs [intf ] = {}
1377
1380
pc_intfs [intf [0 ]] = {}
1381
+ elif VLAN_SUB_INTERFACE_SEPARATOR in intf [0 ]:
1382
+ vlan_sub_intfs [intf ] = {}
1383
+ vlan_sub_intfs [intf [0 ]] = {'admin_status' : 'up' }
1378
1384
else :
1379
1385
phyport_intfs [intf ] = {}
1380
1386
phyport_intfs [intf [0 ]] = {}
@@ -1457,6 +1463,13 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw
1457
1463
if port [0 ] in ports :
1458
1464
ports .get (port [0 ])['admin_status' ] = 'up'
1459
1465
1466
+ if len (vlan_sub_intfs ):
1467
+ for subintf in vlan_sub_intfs :
1468
+ if not isinstance (subintf , tuple ):
1469
+ parent_port = subintf .split ("." )[0 ]
1470
+ if parent_port in ports :
1471
+ ports .get (parent_port )['admin_status' ] = 'up'
1472
+
1460
1473
for member in list (pc_members .keys ()) + list (vlan_members .keys ()):
1461
1474
port = ports .get (member [1 ])
1462
1475
if port :
@@ -1497,9 +1510,16 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw
1497
1510
1498
1511
results ['PORTCHANNEL_INTERFACE' ] = pc_intfs
1499
1512
1500
- if current_device ['type' ] in backend_device_types and is_storage_device :
1513
+ # for storage backend subinterface info present in minigraph takes precedence over ResourceType
1514
+ if current_device ['type' ] in backend_device_types and bool (vlan_sub_intfs ):
1501
1515
del results ['INTERFACE' ]
1502
1516
del results ['PORTCHANNEL_INTERFACE' ]
1517
+ is_storage_device = True
1518
+ results ['VLAN_SUB_INTERFACE' ] = vlan_sub_intfs
1519
+ elif current_device ['type' ] in backend_device_types and (resource_type is None or 'Storage' in resource_type ):
1520
+ del results ['INTERFACE' ]
1521
+ del results ['PORTCHANNEL_INTERFACE' ]
1522
+ is_storage_device = True
1503
1523
1504
1524
for intf in phyport_intfs .keys ():
1505
1525
if isinstance (intf , tuple ):
@@ -1520,8 +1540,12 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw
1520
1540
else :
1521
1541
sub_intf = pc_intf + VLAN_SUB_INTERFACE_SEPARATOR + VLAN_SUB_INTERFACE_VLAN_ID
1522
1542
vlan_sub_intfs [sub_intf ] = {"admin_status" : "up" }
1523
-
1524
1543
results ['VLAN_SUB_INTERFACE' ] = vlan_sub_intfs
1544
+ elif resource_type is not None and 'Storage' in resource_type :
1545
+ is_storage_device = True
1546
+
1547
+ if is_storage_device :
1548
+ results ['DEVICE_METADATA' ]['localhost' ]['storage_device' ] = "true"
1525
1549
1526
1550
results ['VLAN' ] = vlans
1527
1551
results ['VLAN_MEMBER' ] = vlan_members
0 commit comments