Skip to content

Commit

Permalink
show interface portchannel support for Multi ASIC
Browse files Browse the repository at this point in the history
Signed-off-by: Arvindsrinivasan Lakshmi Narasimhan <arlakshm@microsoft.com>
  • Loading branch information
arlakshm committed Jul 21, 2020
1 parent 82dfe50 commit e71321f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 15 deletions.
44 changes: 31 additions & 13 deletions scripts/teamshow
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ import subprocess
import sys
from tabulate import tabulate
from natsort import natsorted
from utilities_common.multi_asic import MultiAsic
from utilities_common.multi_asic import run_on_all_asics
from utilities_common.multi_asic import multi_asic_args

from sonic_device_util import get_npu_id_from_name
from utilities_common.multi_asic import multi_asic_args
from utilities_common.multi_asic import PORT_CHANNEL_OBJ

PORT_CHANNEL_APPL_TABLE_PREFIX = "LAG_TABLE:"
PORT_CHANNEL_CFG_TABLE_PREFIX = "PORTCHANNEL|"
Expand All @@ -35,24 +42,31 @@ PORT_CHANNEL_MEMBER_APPL_TABLE_PREFIX = "LAG_MEMBER_TABLE:"
PORT_CHANNEL_MEMBER_STATUS_FIELD = "status"

class Teamshow(object):
def __init__(self):
def __init__(self,display_option, namespace_option):
self.teams = []
self.teamsraw = {}
self.summary = {}
self.err = None
# setup db connection
self.db = swsssdk.SonicV2Connector(host="127.0.0.1")
self.db.connect(self.db.APPL_DB)
self.db.connect(self.db.CONFIG_DB)
self.db = None
self.multi_asic = MultiAsic(display_option, namespace_option)

@run_on_all_asics
def get_teams_info(self):
self.get_portchannel_names()
self.get_teamdctl()
self.get_teamshow_result()

def get_portchannel_names(self):
"""
Get the portchannel names from database.
"""
self.teams = []
team_keys = self.db.keys(self.db.CONFIG_DB, PORT_CHANNEL_CFG_TABLE_PREFIX+"*")
if team_keys is None:
return
self.teams = [key[len(PORT_CHANNEL_CFG_TABLE_PREFIX):] for key in team_keys]
for key in team_keys:
team_name = key[len(PORT_CHANNEL_CFG_TABLE_PREFIX):]
if self.multi_asic.skip_display(PORT_CHANNEL_OBJ, team_name) is True:
continue
self.teams.append(team_name)

def get_portchannel_status(self, port_channel_name):
"""
Expand All @@ -77,7 +91,7 @@ class Teamshow(object):
Command: 'teamdctl <teamdevname> state dump'.
"""
for team in self.teams:
teamdctl_cmd = 'teamdctl ' + team + ' state dump'
teamdctl_cmd = "sudo docker exec -it teamd{} teamdctl {} state dump".format(get_npu_id_from_name(self.multi_asic.current_namespace), team)
p = subprocess.Popen(teamdctl_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
(output, err) = p.communicate()
rc = p.wait()
Expand Down Expand Up @@ -144,11 +158,15 @@ def main():
if os.geteuid() != 0:
exit("This utility must be run as root")

parser = multi_asic_args()
args = parser.parse_args()

display_option = args.display
namespace_option = args.namespace

try:
team = Teamshow()
team.get_portchannel_names()
team.get_teamdctl()
team.get_teamshow_result()
team = Teamshow(display_option, namespace_option)
team.get_teams_info()
team.display_summary()
except Exception as e:
sys.exit(e.message)
Expand Down
10 changes: 8 additions & 2 deletions show/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from swsssdk import ConfigDBConnector
from swsssdk import SonicV2Connector
from portconfig import get_child_ports
from utilities_common.multi_asic import multi_asic_click_options

import mlnx

Expand Down Expand Up @@ -1116,10 +1117,15 @@ def rif(interface, period, verbose):

# 'portchannel' subcommand ("show interfaces portchannel")
@interfaces.command()
@multi_asic_click_options
@click.option('--verbose', is_flag=True, help="Enable verbose output")
def portchannel(verbose):
def portchannel(namespace, display, verbose):
"""Show PortChannel information"""
cmd = "sudo teamshow"

namespace_option = "" if namespace is None else " -n {}".format(namespace)

cmd = "sudo teamshow -d {} {}".format(display, namespace_option)

run_command(cmd, display_cmd=verbose)

#
Expand Down

0 comments on commit e71321f

Please sign in to comment.