@@ -123,11 +123,17 @@ def is_multi_asic():
123
123
124
124
125
125
def get_asic_id_from_name (asic_name ):
126
+ """
127
+ Get the asic id from the asic name for multi-asic platforms
128
+ In single ASIC platforms, it would fail and throw an exception.
126
129
130
+ Returns:
131
+ asic id.
132
+ """
127
133
if asic_name .startswith (ASIC_NAME_PREFIX ):
128
134
return asic_name [len (ASIC_NAME_PREFIX ):]
129
135
else :
130
- return None
136
+ raise ValueError ( 'Unknown asic namespace name {}' . format ( asic_name ))
131
137
132
138
# Get the ASIC id from the asic.conf file.
133
139
def get_asic_device_id (asic_id ):
@@ -336,3 +342,33 @@ def is_bgp_session_internal(bgp_neigh_ip, namespace=None):
336
342
else :
337
343
return False
338
344
return False
345
+
346
+ def get_front_end_namespaces ():
347
+ """
348
+ Get the namespaces in the platform. For multi-asic devices we get the namespaces
349
+ mapped to asic which have front-panel interfaces. For single ASIC device it is the
350
+ DEFAULT_NAMESPACE which maps to the linux host.
351
+
352
+ Returns:
353
+ a list of namespaces
354
+ """
355
+ namespaces = [DEFAULT_NAMESPACE ]
356
+ if is_multi_asic ():
357
+ ns_list = get_all_namespaces ()
358
+ namespaces = ns_list ['front_ns' ]
359
+
360
+ return namespaces
361
+
362
+
363
+ def get_asic_index_from_namespace (namespace ):
364
+ """
365
+ Get asic index from the namespace name.
366
+ With single ASIC platform, return asic_index 0, which is mapped to the only asic present.
367
+
368
+ Returns:
369
+ asic_index as an integer.
370
+ """
371
+ if is_multi_asic ():
372
+ return int (get_asic_id_from_name (namespace ))
373
+
374
+ return 0
0 commit comments