Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

show interface portchannel support for Multi ASIC #1005

Merged
merged 6 commits into from
Aug 24, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 31 additions & 14 deletions scripts/teamshow
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,18 @@

import json
import os
import swsssdk
import subprocess
import sys

from tabulate import tabulate
from natsort import natsorted

from sonic_py_common.multi_asic_device_info import get_asic_id_from_name
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 utilities_common.multi_asic import PORT_CHANNEL_OBJ

PORT_CHANNEL_APPL_TABLE_PREFIX = "LAG_TABLE:"
PORT_CHANNEL_CFG_TABLE_PREFIX = "PORTCHANNEL|"
PORT_CHANNEL_STATUS_FIELD = "oper_status"
Expand All @@ -35,24 +41,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 +90,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_asic_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 +157,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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the config commands I add the namespace option at the command group level ( i.e if you take this example ..it will be like show interfaces -n asic0 portchannel/counters ) instead of specifying the options after the subcommand keyword viz portchannel, counters etc ..

I was looking to see if both the show and config commands follow similar approach .. @arlakshm @jleveque your thoughts ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@judyjoseph. IMO the CLI syntax is cleaner if we have the keywords first then followed by options/arguments.

@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