File tree Expand file tree Collapse file tree
src/sonic-py-common/sonic_py_common Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -123,11 +123,17 @@ def is_multi_asic():
123123
124124
125125def 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.
126129
130+ Returns:
131+ asic id.
132+ """
127133 if asic_name .startswith (ASIC_NAME_PREFIX ):
128134 return asic_name [len (ASIC_NAME_PREFIX ):]
129135 else :
130- return None
136+ raise ValueError ( 'Unknown asic namespace name {}' . format ( asic_name ))
131137
132138
133139def get_namespaces_from_linux ():
@@ -308,3 +314,33 @@ def is_bgp_session_internal(bgp_neigh_ip, namespace=None):
308314 else :
309315 return False
310316 return False
317+
318+ def get_front_end_namespaces ():
319+ """
320+ Get the namespaces in the platform. For multi-asic devices we get the namespaces
321+ mapped to asic which have front-panel interfaces. For single ASIC device it is the
322+ DEFAULT_NAMESPACE which maps to the linux host.
323+
324+ Returns:
325+ a list of namespaces
326+ """
327+ namespaces = [DEFAULT_NAMESPACE ]
328+ if is_multi_asic ():
329+ ns_list = get_all_namespaces ()
330+ namespaces = ns_list ['front_ns' ]
331+
332+ return namespaces
333+
334+
335+ def get_asic_index_from_namespace (namespace ):
336+ """
337+ Get asic index from the namespace name.
338+ With single ASIC platform, return asic_index 0, which is mapped to the only asic present.
339+
340+ Returns:
341+ asic_index as an integer.
342+ """
343+ if is_multi_asic ():
344+ return int (get_asic_id_from_name (namespace ))
345+
346+ return 0
You can’t perform that action at this time.
0 commit comments