1
- import click
2
1
3
- from tabulate import tabulate
4
- from natsort import natsorted
2
+ import os
3
+ import sys
5
4
5
+ import click
6
6
import utilities_common .cli as clicommon
7
+ from natsort import natsorted
8
+ from tabulate import tabulate
9
+ import utilities_common .multi_asic as multi_asic_util
10
+ from utilities_common .constants import PORT_CHANNEL_OBJ
7
11
8
12
"""
9
13
Script to show LAG and LAG member status in a summary view
24
28
25
29
"""
26
30
27
- import json
28
- import os
29
- import subprocess
30
- import sys
31
-
32
- from tabulate import tabulate
33
- from natsort import natsorted
34
-
35
- from sonic_py_common .multi_asic_device_info import get_asic_id_from_name
36
- from utilities_common .multi_asic import MultiAsic
37
- from utilities_common .multi_asic import run_on_all_asics
38
- from utilities_common .multi_asic import multi_asic_args
39
- from utilities_common .multi_asic import PORT_CHANNEL_OBJ
40
-
41
31
PORT_CHANNEL_APPL_TABLE_PREFIX = "LAG_TABLE:"
42
32
PORT_CHANNEL_CFG_TABLE_PREFIX = "PORTCHANNEL|"
43
33
PORT_CHANNEL_STATE_TABLE_PREFIX = "LAG_TABLE|"
48
38
PORT_CHANNEL_MEMBER_STATUS_FIELD = "status"
49
39
50
40
class Teamshow (object ):
51
- def __init__ (self ,display_option , namespace_option ):
41
+ def __init__ (self , namespace_option , display_option ):
52
42
self .teams = []
53
43
self .teamsraw = {}
54
44
self .summary = {}
55
45
self .err = None
56
46
self .db = None
57
- self .multi_asic = MultiAsic (display_option , namespace_option )
47
+ self .multi_asic = multi_asic_util . MultiAsic (display_option , namespace_option )
58
48
59
- @run_on_all_asics
49
+ @multi_asic_util . run_on_multi_asic
60
50
def get_teams_info (self ):
61
51
self .get_portchannel_names ()
62
52
self .get_teamdctl ()
@@ -143,7 +133,7 @@ def get_teamshow_result(self):
143
133
pstate = self .db .get_all (self .db .STATE_DB , PORT_CHANNEL_MEMBER_STATE_TABLE_PREFIX + team + '|' + port )
144
134
selected = True if pstate ['runner.aggregator.selected' ] == "true" else False
145
135
if clicommon .get_interface_naming_mode () == "alias" :
146
- alias = clicommon .InterfaceAliasConverter (self . db2 ).name_to_alias (port )
136
+ alias = clicommon .InterfaceAliasConverter ().name_to_alias (port )
147
137
info ["ports" ] += alias + "("
148
138
else :
149
139
info ["ports" ] += port + "("
@@ -167,22 +157,12 @@ def display_summary(self):
167
157
output .append ([team_id , 'PortChannel' + team_id , self .summary [team_id ]['protocol' ], self .summary [team_id ]['ports' ]])
168
158
print tabulate (output , header )
169
159
170
- def main ():
171
- if os .geteuid () != 0 :
172
- exit ("This utility must be run as root" )
173
-
174
- parser = multi_asic_args ()
175
- args = parser .parse_args ()
176
-
177
- display_option = args .display
178
- namespace_option = args .namespace
179
-
180
- try :
181
- team = Teamshow (display_option , namespace_option )
182
- team .get_teams_info ()
183
- team .display_summary ()
184
- except Exception as e :
185
- sys .exit (e .message )
186
-
187
- if __name__ == "__main__" :
188
- main ()
160
+ # 'portchannel' subcommand ("show interfaces portchannel")
161
+ @click .command ()
162
+ @multi_asic_util .multi_asic_click_options
163
+ @click .option ('--verbose' , is_flag = True , help = "Enable verbose output" )
164
+ def portchannel (namespace , display , verbose ):
165
+ """Show PortChannel information"""
166
+ team = Teamshow (namespace , display )
167
+ team .get_teams_info ()
168
+ team .display_summary ()
0 commit comments