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
Changes from 4 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
49 changes: 30 additions & 19 deletions show/interfaces/portchannel.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import click

from tabulate import tabulate
from natsort import natsorted
import os
import sys

import click
import utilities_common.cli as clicommon
from natsort import natsorted
from tabulate import tabulate
import utilities_common.multi_asic as multi_asic_util
from utilities_common.constants import PORT_CHANNEL_OBJ

"""
Script to show LAG and LAG member status in a summary view
Expand All @@ -24,7 +28,6 @@

"""


PORT_CHANNEL_APPL_TABLE_PREFIX = "LAG_TABLE:"
PORT_CHANNEL_CFG_TABLE_PREFIX = "PORTCHANNEL|"
PORT_CHANNEL_STATE_TABLE_PREFIX = "LAG_TABLE|"
Expand All @@ -35,21 +38,31 @@
PORT_CHANNEL_MEMBER_STATUS_FIELD = "status"

class Teamshow(object):
def __init__(self, db):
def __init__(self, namespace_option, display_option):
self.teams = []
self.teamsraw = {}
self.summary = {}
self.db = db.db
self.db2 = db
self.err = None
self.db = None
self.multi_asic = multi_asic_util.MultiAsic(display_option, namespace_option)

@multi_asic_util.run_on_multi_asic
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:
lguohan marked this conversation as resolved.
Show resolved Hide resolved
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 Down Expand Up @@ -120,7 +133,7 @@ def get_teamshow_result(self):
pstate = self.db.get_all(self.db.STATE_DB, PORT_CHANNEL_MEMBER_STATE_TABLE_PREFIX+team+'|'+port)
selected = True if pstate['runner.aggregator.selected'] == "true" else False
if clicommon.get_interface_naming_mode() == "alias":
alias = clicommon.InterfaceAliasConverter(self.db2).name_to_alias(port)
alias = clicommon.InterfaceAliasConverter().name_to_alias(port)
info["ports"] += alias + "("
else:
info["ports"] += port + "("
Expand All @@ -142,16 +155,14 @@ def display_summary(self):
output = []
for team_id in natsorted(self.summary):
output.append([team_id, 'PortChannel'+team_id, self.summary[team_id]['protocol'], self.summary[team_id]['ports']])
print(tabulate(output, header))
print tabulate(output, header)
lguohan marked this conversation as resolved.
Show resolved Hide resolved

# 'portchannel' subcommand ("show interfaces portchannel")
@click.command()
@multi_asic_util.multi_asic_click_options
@click.option('--verbose', is_flag=True, help="Enable verbose output")
@clicommon.pass_db
Copy link
Contributor

Choose a reason for hiding this comment

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

why is this removed? this can break the unit test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

With multi asic support, Teamshow will connect to DBs in each namespace or default namespace. No need to pass the db. Unit test will work with the changes done to support multi asic CLIs

def portchannel(db, verbose):
def portchannel(namespace, display, verbose):
"""Show PortChannel information"""
team = Teamshow(db)
team.get_portchannel_names()
team.get_teamdctl()
team.get_teamshow_result()
team.display_summary()
team = Teamshow(namespace, display)
team.get_teams_info()
team.display_summary()