Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add common functions applicable to single/multi asic platforms #5224

Merged
merged 4 commits into from
Aug 22, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion src/sonic-py-common/sonic_py_common/multi_asic.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,17 @@ def is_multi_asic():


def get_asic_id_from_name(asic_name):
"""
Get the asic id from the asic name for multi-asic platforms
jleveque marked this conversation as resolved.
Show resolved Hide resolved
In single ASIC platforms, it would fail and throw an exception.

Returns:
asic id.
"""
if asic_name.startswith(ASIC_NAME_PREFIX):
return asic_name[len(ASIC_NAME_PREFIX):]
else:
return None
raise ValueError('Unknown asic namespace name {}'.format(asic_name))


def get_namespaces_from_linux():
Expand Down Expand Up @@ -298,3 +304,33 @@ def is_bgp_session_internal(bgp_neigh_ip, namespace=None):
else:
return False
return False

def get_front_end_namespaces():
"""
Get the namespaces in the platform. For multi-asic devices we get the namespaces
mapped to asic which have front-panel interfaces. For single ASIC device it is the
DEFAULT_NAMESPACE which maps to the linux host.

Returns:
a list of namespaces
"""
namespaces = [DEFAULT_NAMESPACE]
if is_multi_asic():
ns_list = get_all_namespaces()
namespaces = ns_list['front_ns']

return namespaces


def get_asic_index_from_namespace(namespace):
"""
Get asic index from the namespace name.
With single ASIC platform, return asic_index 0, which is mapped to the only asic present.

Returns:
asic_index as an integer.
"""
if is_multi_asic():
return int(get_asic_id_from_name(namespace))

return 0
arlakshm marked this conversation as resolved.
Show resolved Hide resolved