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

CLI optimization #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
18 changes: 11 additions & 7 deletions show/main.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
#! /usr/bin/python -u

import json
import netaddr
#import netaddr
import os
import subprocess
import sys

import click
from natsort import natsorted
import netifaces
from pkg_resources import parse_version
#from pkg_resources import parse_version

import feature
import interfaces
import kube
import mlnx
#import mlnx
import utilities_common.cli as clicommon
import vlan
import system_health

from sonic_py_common import device_info, multi_asic
#from sonic_py_common import device_info, multi_asic
from swsssdk import ConfigDBConnector, SonicV2Connector
from tabulate import tabulate
from utilities_common.db import Db
Expand Down Expand Up @@ -55,7 +55,7 @@ def get_routing_stack():


# Global Routing-Stack variable
routing_stack = get_routing_stack()
routing_stack = "frr"

# Read given JSON file
def readJsonFile(fileName):
Expand Down Expand Up @@ -714,6 +714,7 @@ def get_if_master(iface):
@ip.command()
def interfaces():
"""Show interfaces IPv4 address"""
import netaddr
header = ['Interface', 'Master', 'IPv4 address/mask', 'Admin/Oper', 'BGP Neighbor', 'Neighbor IP']
data = []
bgp_peer = get_bgp_peer()
Expand Down Expand Up @@ -984,6 +985,7 @@ def get_hw_info_dict():
"""
This function is used to get the HW info helper function
"""
from sonic_py_common import device_info, multi_asic
hw_info_dict = {}

version_info = device_info.get_sonic_version_info()
Expand All @@ -999,11 +1001,11 @@ def get_hw_info_dict():
def platform():
"""Show platform-specific hardware info"""
pass

'''

Choose a reason for hiding this comment

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

We cannot comment mellanox commands in community.

version_info = device_info.get_sonic_version_info()
if (version_info and version_info.get('asic_type') == 'mellanox'):
platform.add_command(mlnx.mlnx)

'''
# 'summary' subcommand ("show platform summary")
@platform.command()
@click.option('--json', is_flag=True, help="JSON output")
Expand Down Expand Up @@ -1132,6 +1134,7 @@ def logging(process, lines, follow, verbose):
@cli.command()
@click.option("--verbose", is_flag=True, help="Enable verbose output")
def version(verbose):
from sonic_py_common import device_info
"""Show version information"""
version_info = device_info.get_sonic_version_info()
hw_info_dict = get_hw_info_dict()
Expand Down Expand Up @@ -1381,6 +1384,7 @@ def bgp(verbose):
@click.option('--verbose', is_flag=True, help="Enable verbose output")
def ntp(ctx, verbose):
"""Show NTP information"""
from pkg_resources import parse_version
ntpstat_cmd = "ntpstat"
ntpcmd = "ntpq -p -n"
if is_mgmt_vrf_enabled(ctx) is True:
Expand Down
3 changes: 2 additions & 1 deletion utilities_common/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import click
import json
import netaddr
#import netaddr

from natsort import natsorted

Expand Down Expand Up @@ -195,6 +195,7 @@ def get_interface_naming_mode():

def is_ipaddress(val):
""" Validate if an entry is a valid IP """
import netaddr
if not val:
return False
try:
Expand Down