@@ -37,10 +37,12 @@ from functools import partial
37
37
from minigraph import minigraph_encoder
38
38
from minigraph import parse_xml
39
39
from minigraph import parse_device_desc_xml
40
+ from minigraph import parse_asic_sub_role
40
41
from portconfig import get_port_config
41
42
from sonic_device_util import get_machine_info
42
43
from sonic_device_util import get_platform_info
43
44
from sonic_device_util import get_system_mac
45
+ from sonic_device_util import get_npu_id_from_name
44
46
from config_samples import generate_sample_config
45
47
from config_samples import get_available_config
46
48
from swsssdk import SonicV2Connector , ConfigDBConnector
@@ -195,6 +197,7 @@ def main():
195
197
group .add_argument ("-m" , "--minigraph" , help = "minigraph xml file" , nargs = '?' , const = '/etc/sonic/minigraph.xml' )
196
198
group .add_argument ("-M" , "--device-description" , help = "device description xml file" )
197
199
group .add_argument ("-k" , "--hwsku" , help = "HwSKU" )
200
+ parser .add_argument ("-n" , "--namespace" , help = "namespace name, used with -m or -k" , nargs = '?' , const = None )
198
201
parser .add_argument ("-p" , "--port-config" , help = "port config file, used with -m or -k" , nargs = '?' , const = None )
199
202
parser .add_argument ("-y" , "--yaml" , help = "yaml file that contains additional variables" , action = 'append' , default = [])
200
203
parser .add_argument ("-j" , "--json" , help = "json file that contains additional variables" , action = 'append' , default = [])
@@ -222,13 +225,18 @@ def main():
222
225
223
226
data = {}
224
227
hwsku = args .hwsku
228
+ asic_name = args .namespace
229
+ asic_id = None
230
+ if asic_name is not None :
231
+ asic_id = get_npu_id_from_name (asic_name )
232
+
225
233
226
234
if hwsku is not None :
227
235
hardware_data = {'DEVICE_METADATA' : {'localhost' : {
228
236
'hwsku' : hwsku
229
237
}}}
230
238
deep_update (data , hardware_data )
231
- (ports , _ ) = get_port_config (hwsku , platform , args .port_config )
239
+ (ports , _ , _ ) = get_port_config (hwsku , platform , args .port_config , asic_id )
232
240
if not ports :
233
241
print ('Failed to get port config' , file = sys .stderr )
234
242
sys .exit (1 )
@@ -242,11 +250,11 @@ def main():
242
250
minigraph = args .minigraph
243
251
if platform :
244
252
if args .port_config != None :
245
- deep_update (data , parse_xml (minigraph , platform , args .port_config ))
253
+ deep_update (data , parse_xml (minigraph , platform , args .port_config , asic_name = asic_name ))
246
254
else :
247
- deep_update (data , parse_xml (minigraph , platform ))
255
+ deep_update (data , parse_xml (minigraph , platform , asic_name = asic_name ))
248
256
else :
249
- deep_update (data , parse_xml (minigraph , port_config_file = args .port_config ))
257
+ deep_update (data , parse_xml (minigraph , port_config_file = args .port_config , asic_name = asic_name ))
250
258
251
259
if args .device_description != None :
252
260
deep_update (data , parse_device_desc_xml (args .device_description ))
@@ -267,11 +275,28 @@ def main():
267
275
configdb .connect ()
268
276
deep_update (data , FormatConverter .db_to_output (configdb .get_config ()))
269
277
278
+
279
+ # the minigraph file must be provided to get the mac address for backend asics
270
280
if args .platform_info :
281
+ asic_role = None
282
+ if asic_name is not None :
283
+ if args .minigraph is not None :
284
+ asic_role = parse_asic_sub_role (args .minigraph , asic_name )
285
+
286
+ if asic_role is not None and asic_role .lower () == "backend" :
287
+ mac = get_system_mac (namespace = asic_name )
288
+ else :
289
+ mac = get_system_mac ()
290
+ else :
291
+ mac = get_system_mac ()
292
+
271
293
hardware_data = {'DEVICE_METADATA' : {'localhost' : {
272
294
'platform' : platform ,
273
- 'mac' : get_system_mac ()
295
+ 'mac' : mac ,
274
296
}}}
297
+ # The ID needs to be passed to the SAI to identify the asic.
298
+ if asic_name is not None :
299
+ hardware_data ['DEVICE_METADATA' ]['localhost' ].update (asic_id = asic_id )
275
300
deep_update (data , hardware_data )
276
301
277
302
if args .template is not None :
0 commit comments