@@ -321,36 +321,65 @@ def expected(db, interfacename):
321
321
322
322
click .echo (tabulate (body , header ))
323
323
324
- # 'mpls' subcommand ("show interfaces mpls")
325
324
@interfaces .command ()
326
325
@click .argument ('interfacename' , required = False )
326
+ @click .option ('--namespace' , '-n' , 'namespace' , default = None ,
327
+ type = str , show_default = True , help = 'Namespace name or all' ,
328
+ callback = multi_asic_util .multi_asic_namespace_validation_callback )
329
+ @click .option ('--display' , '-d' , 'display' , default = None , show_default = False ,
330
+ type = str , help = 'all|frontend' )
327
331
@click .pass_context
328
- def mpls (ctx , interfacename ):
332
+ def mpls (ctx , interfacename , namespace , display ):
329
333
"""Show Interface MPLS status"""
334
+
335
+ #Edge case: Force show frontend interfaces on single asic
336
+ if not (multi_asic .is_multi_asic ()):
337
+ if (display == 'frontend' or display == 'all' or display is None ):
338
+ display = None
339
+ else :
340
+ print ("Error: Invalid display option command for single asic" )
341
+ return
342
+
343
+ masic = multi_asic_util .MultiAsic (display_option = display , namespace_option = namespace )
344
+ ns_list = masic .get_ns_list_based_on_options ()
345
+ intfs_data = {}
330
346
331
- appl_db = SonicV2Connector ()
332
- appl_db .connect (appl_db .APPL_DB )
347
+ for ns in ns_list :
333
348
334
- if interfacename is not None :
335
- interfacename = try_convert_interfacename_from_alias (ctx , interfacename )
349
+ appl_db = multi_asic .connect_to_all_dbs_for_ns (namespace = ns )
336
350
337
- # Fetching data from appl_db for intfs
338
- keys = appl_db .keys (appl_db .APPL_DB , "INTF_TABLE:*" )
339
- intfs_data = {}
340
- for key in keys if keys else []:
341
- tokens = key .split (":" )
342
- # Skip INTF_TABLE entries with address information
343
- if len (tokens ) != 2 :
344
- continue
345
-
346
- if (interfacename is not None ) and (interfacename != tokens [1 ]):
347
- continue
348
-
349
- mpls = appl_db .get (appl_db .APPL_DB , key , 'mpls' )
350
- if mpls is None or mpls == '' :
351
- intfs_data .update ({tokens [1 ]: 'disable' })
352
- else :
353
- intfs_data .update ({tokens [1 ]: mpls })
351
+ if interfacename is not None :
352
+ interfacename = try_convert_interfacename_from_alias (ctx , interfacename )
353
+
354
+ # Fetching data from appl_db for intfs
355
+ keys = appl_db .keys (appl_db .APPL_DB , "INTF_TABLE:*" )
356
+ for key in keys if keys else []:
357
+ tokens = key .split (":" )
358
+ ifname = tokens [1 ]
359
+ # Skip INTF_TABLE entries with address information
360
+ if len (tokens ) != 2 :
361
+ continue
362
+
363
+ if (interfacename is not None ) and (interfacename != tokens [1 ]):
364
+ continue
365
+
366
+ if (display != "all" ):
367
+ if ("Loopback" in tokens [1 ]):
368
+ continue
369
+
370
+ if ifname .startswith ("Ethernet" ) and multi_asic .is_port_internal (ifname , ns ):
371
+ continue
372
+
373
+ if ifname .startswith ("PortChannel" ) and multi_asic .is_port_channel_internal (ifname , ns ):
374
+ continue
375
+
376
+
377
+ mpls_intf = appl_db .get_all (appl_db .APPL_DB , key )
378
+
379
+ if 'mpls' not in mpls_intf or mpls_intf ['mpls' ] == 'disable' :
380
+ intfs_data .update ({tokens [1 ]: 'disable' })
381
+ else :
382
+ intfs_data .update ({tokens [1 ]: mpls_intf ['mpls' ]})
354
383
355
384
header = ['Interface' , 'MPLS State' ]
356
385
body = []
0 commit comments