1
1
import json
2
+ import os
2
3
3
4
import click
4
5
import utilities_common .cli as clicommon
5
6
import utilities_common .multi_asic as multi_asic_util
6
7
from natsort import natsorted
7
8
from tabulate import tabulate
8
9
from sonic_py_common import multi_asic
10
+ from sonic_py_common import device_info
11
+ from swsssdk import ConfigDBConnector
12
+ from portconfig import get_child_ports
9
13
10
14
from . import portchannel
15
+ from collections import OrderedDict
16
+
17
+ HWSKU_JSON = 'hwsku.json'
18
+
19
+ # Read given JSON file
20
+ def readJsonFile (fileName ):
21
+ try :
22
+ with open (fileName ) as f :
23
+ result = json .load (f )
24
+ except Exception as e :
25
+ click .echo (str (e ))
26
+ raise click .Abort ()
27
+ return result
11
28
12
29
def try_convert_interfacename_from_alias (ctx , interfacename ):
13
30
"""try to convert interface name from alias"""
@@ -144,13 +161,14 @@ def breakout(ctx):
144
161
145
162
if ctx .invoked_subcommand is None :
146
163
# Get port capability from platform and hwsku related files
147
- platform_path , hwsku_path = device_info .get_paths_to_platform_and_hwsku_dirs ()
148
- platform_file = os . path . join ( platform_path , PLATFORM_JSON )
164
+ hwsku_path = device_info .get_path_to_hwsku_dir ()
165
+ platform_file = device_info . get_path_to_port_config_file ( )
149
166
platform_dict = readJsonFile (platform_file )['interfaces' ]
150
- hwsku_dict = readJsonFile (os .path .join (hwsku_path , HWSKU_JSON ))['interfaces' ]
167
+ hwsku_file = os .path .join (hwsku_path , HWSKU_JSON )
168
+ hwsku_dict = readJsonFile (hwsku_file )['interfaces' ]
151
169
152
170
if not platform_dict or not hwsku_dict :
153
- click .echo ("Can not load port config from {} or {} file" .format (PLATFORM_JSON , HWSKU_JSON ))
171
+ click .echo ("Can not load port config from {} or {} file" .format (platform_file , hwsku_file ))
154
172
raise click .Abort ()
155
173
156
174
for port_name in platform_dict :
@@ -161,9 +179,9 @@ def breakout(ctx):
161
179
platform_dict [port_name ]["Current Breakout Mode" ] = cur_brkout_mode
162
180
163
181
# List all the child ports if present
164
- child_port_dict = get_child_ports (port_name , cur_brkout_mode , platformFile )
182
+ child_port_dict = get_child_ports (port_name , cur_brkout_mode , platform_file )
165
183
if not child_port_dict :
166
- click .echo ("Cannot find ports from {} file " .format (PLATFORM_JSON ))
184
+ click .echo ("Cannot find ports from {} file " .format (platform_file ))
167
185
raise click .Abort ()
168
186
169
187
child_ports = natsorted (list (child_port_dict .keys ()))
0 commit comments