4
4
from natsort import natsorted
5
5
from tabulate import tabulate
6
6
7
+ from sonic_py_common import multi_asic
7
8
import utilities_common .cli as clicommon
9
+ import utilities_common .multi_asic as multi_asic_util
8
10
import portchannel
9
11
10
- def try_convert_interfacename_from_alias (ctx , db , interfacename ):
12
+ def try_convert_interfacename_from_alias (ctx , interfacename ):
11
13
"""try to convert interface name from alias"""
12
14
13
15
if clicommon .get_interface_naming_mode () == "alias" :
14
16
alias = interfacename
15
- interfacename = clicommon .InterfaceAliasConverter (db ).alias_to_name (alias )
17
+ interfacename = clicommon .InterfaceAliasConverter ().alias_to_name (alias )
16
18
# TODO: ideally alias_to_name should return None when it cannot find
17
19
# the port name for the alias
18
20
if interfacename == alias :
@@ -31,19 +33,19 @@ def interfaces():
31
33
# 'alias' subcommand ("show interfaces alias")
32
34
@interfaces .command ()
33
35
@click .argument ('interfacename' , required = False )
34
- @clicommon . pass_db
35
- def alias (db , interfacename ):
36
+ @multi_asic_util . multi_asic_click_options
37
+ def alias (interfacename , namespace , display ):
36
38
"""Show Interface Name/Alias Mapping"""
37
39
38
40
ctx = click .get_current_context ()
39
41
40
- port_dict = db . cfgdb . get_table ( "PORT" )
42
+ port_dict = multi_asic . get_port_table ( namespace = namespace )
41
43
42
44
header = ['Name' , 'Alias' ]
43
45
body = []
44
46
45
47
if interfacename is not None :
46
- interfacename = try_convert_interfacename_from_alias (ctx , db , interfacename )
48
+ interfacename = try_convert_interfacename_from_alias (ctx , interfacename )
47
49
48
50
# If we're given an interface name, output name and alias for that interface only
49
51
if interfacename in port_dict .keys ():
@@ -56,6 +58,10 @@ def alias(db, interfacename):
56
58
else :
57
59
# Output name and alias for all interfaces
58
60
for port_name in natsorted (port_dict .keys ()):
61
+ if ((display == multi_asic_util .constants .DISPLAY_EXTERNAL ) and
62
+ ('role' in port_dict [port_name ]) and
63
+ (port_dict [port_name ]['role' ] is multi_asic .INTERNAL_PORT )):
64
+ continue
59
65
if 'alias' in port_dict [port_name ]:
60
66
body .append ([port_name , port_dict [port_name ]['alias' ]])
61
67
else :
@@ -65,19 +71,25 @@ def alias(db, interfacename):
65
71
66
72
@interfaces .command ()
67
73
@click .argument ('interfacename' , required = False )
74
+ @multi_asic_util .multi_asic_click_options
68
75
@click .option ('--verbose' , is_flag = True , help = "Enable verbose output" )
69
- @clicommon .pass_db
70
- def description (db , interfacename , verbose ):
76
+ def description (interfacename , namespace , display , verbose ):
71
77
"""Show interface status, protocol and description"""
72
78
73
79
ctx = click .get_current_context ()
74
80
75
- cmd = "intfutil description"
81
+ cmd = "intfutil -c description"
76
82
83
+ #ignore the display option when interface name is passed
77
84
if interfacename is not None :
78
- interfacename = try_convert_interfacename_from_alias (ctx , db , interfacename )
85
+ interfacename = try_convert_interfacename_from_alias (ctx , interfacename )
79
86
80
- cmd += " {}" .format (interfacename )
87
+ cmd += " -i {}" .format (interfacename )
88
+ else :
89
+ cmd += " -d {}" .format (display )
90
+
91
+ if namespace is not None :
92
+ cmd += " -n {}" .format (namespace )
81
93
82
94
clicommon .run_command (cmd , display_cmd = verbose )
83
95
@@ -91,19 +103,24 @@ def naming_mode(verbose):
91
103
92
104
@interfaces .command ()
93
105
@click .argument ('interfacename' , required = False )
106
+ @multi_asic_util .multi_asic_click_options
94
107
@click .option ('--verbose' , is_flag = True , help = "Enable verbose output" )
95
- @clicommon .pass_db
96
- def status (db , interfacename , verbose ):
108
+ def status (interfacename , namespace , display , verbose ):
97
109
"""Show Interface status information"""
98
110
99
111
ctx = click .get_current_context ()
100
112
101
- cmd = "intfutil status"
113
+ cmd = "intfutil -c status"
102
114
103
115
if interfacename is not None :
104
- interfacename = try_convert_interfacename_from_alias (ctx , db , interfacename )
116
+ interfacename = try_convert_interfacename_from_alias (ctx , interfacename )
105
117
106
- cmd += " {}" .format (interfacename )
118
+ cmd += " -i {}" .format (interfacename )
119
+ else :
120
+ cmd += " -d {}" .format (display )
121
+
122
+ if namespace is not None :
123
+ cmd += " -n {}" .format (namespace )
107
124
108
125
clicommon .run_command (cmd , display_cmd = verbose )
109
126
@@ -225,7 +242,7 @@ def expected(db, interfacename):
225
242
for port in natsorted (neighbor_dict .keys ()):
226
243
temp_port = port
227
244
if clicommon .get_interface_naming_mode () == "alias" :
228
- port = clicommon .InterfaceAliasConverter (db ).name_to_alias (port )
245
+ port = clicommon .InterfaceAliasConverter ().name_to_alias (port )
229
246
neighbor_dict [port ] = neighbor_dict .pop (temp_port )
230
247
device2interface_dict [neighbor_dict [port ]['name' ]] = {'localPort' : port , 'neighborPort' : neighbor_dict [port ]['port' ]}
231
248
@@ -268,8 +285,7 @@ def transceiver():
268
285
@click .argument ('interfacename' , required = False )
269
286
@click .option ('-d' , '--dom' , 'dump_dom' , is_flag = True , help = "Also display Digital Optical Monitoring (DOM) data" )
270
287
@click .option ('--verbose' , is_flag = True , help = "Enable verbose output" )
271
- @clicommon .pass_db
272
- def eeprom (db , interfacename , dump_dom , verbose ):
288
+ def eeprom (interfacename , dump_dom , verbose ):
273
289
"""Show interface transceiver EEPROM information"""
274
290
275
291
ctx = click .get_current_context ()
@@ -280,7 +296,7 @@ def eeprom(db, interfacename, dump_dom, verbose):
280
296
cmd += " --dom"
281
297
282
298
if interfacename is not None :
283
- interfacename = try_convert_interfacename_from_alias (ctx , db , interfacename )
299
+ interfacename = try_convert_interfacename_from_alias (ctx , interfacename )
284
300
285
301
cmd += " -p {}" .format (interfacename )
286
302
@@ -289,16 +305,15 @@ def eeprom(db, interfacename, dump_dom, verbose):
289
305
@transceiver .command ()
290
306
@click .argument ('interfacename' , required = False )
291
307
@click .option ('--verbose' , is_flag = True , help = "Enable verbose output" )
292
- @clicommon .pass_db
293
- def lpmode (db , interfacename , verbose ):
308
+ def lpmode (interfacename , verbose ):
294
309
"""Show interface transceiver low-power mode status"""
295
310
296
311
ctx = click .get_current_context ()
297
312
298
313
cmd = "sudo sfputil show lpmode"
299
314
300
315
if interfacename is not None :
301
- interfacename = try_convert_interfacename_from_alias (ctx , db , interfacename )
316
+ interfacename = try_convert_interfacename_from_alias (ctx , interfacename )
302
317
303
318
cmd += " -p {}" .format (interfacename )
304
319
@@ -316,7 +331,7 @@ def presence(db, interfacename, verbose):
316
331
cmd = "sfpshow presence"
317
332
318
333
if interfacename is not None :
319
- interfacename = try_convert_interfacename_from_alias (ctx , db , interfacename )
334
+ interfacename = try_convert_interfacename_from_alias (ctx , interfacename )
320
335
321
336
cmd += " -p {}" .format (interfacename )
322
337
0 commit comments