Skip to content

Commit d4eb2d9

Browse files
[show] Moving some py imports inside specific cmds (sonic-net#1202)
- Some py imports in show/main.py script are taking more time on arm cpu. - modules - pkg_resources, netaddr are taking around 500ms causing delay for all show cmds. - These modules are used by only specific cmds. So, I have included these imports only for the commands that are using them. Signed-off-by: Sabareesh Kumar Anandan <[email protected]>
1 parent fab84fb commit d4eb2d9

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

show/main.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import json
2-
import netaddr
32
import os
43
import subprocess
54
import sys
@@ -9,7 +8,6 @@
98
import utilities_common.cli as clicommon
109
import utilities_common.multi_asic as multi_asic_util
1110
from natsort import natsorted
12-
from pkg_resources import parse_version
1311
from sonic_py_common import device_info, multi_asic
1412
from swsssdk import ConfigDBConnector
1513
from swsscommon.swsscommon import SonicV2Connector
@@ -751,6 +749,7 @@ def get_if_master(iface):
751749
@ip.command()
752750
def interfaces():
753751
"""Show interfaces IPv4 address"""
752+
import netaddr
754753
header = ['Interface', 'Master', 'IPv4 address/mask', 'Admin/Oper', 'BGP Neighbor', 'Neighbor IP']
755754
data = []
756755
bgp_peer = get_bgp_peer()
@@ -1266,6 +1265,7 @@ def bgp(verbose):
12661265
@click.option('--verbose', is_flag=True, help="Enable verbose output")
12671266
def ntp(ctx, verbose):
12681267
"""Show NTP information"""
1268+
from pkg_resources import parse_version
12691269
ntpstat_cmd = "ntpstat"
12701270
ntpcmd = "ntpq -p -n"
12711271
if is_mgmt_vrf_enabled(ctx) is True:

utilities_common/cli.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import click
88
import json
9-
import netaddr
109

1110
from natsort import natsorted
1211
from sonic_py_common import multi_asic
@@ -191,6 +190,7 @@ def get_interface_naming_mode():
191190

192191
def is_ipaddress(val):
193192
""" Validate if an entry is a valid IP """
193+
import netaddr
194194
if not val:
195195
return False
196196
try:

0 commit comments

Comments
 (0)