Add common functions applicable to single/multi asic platforms (#5224)
* Add common functions applicable to single/multi asic platforms * Raise exception if invalid namespace is given as input.
This commit is contained in:
parent
bb57ccecd4
commit
cbb46e426b
@ -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
|
||||
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():
|
||||
@ -308,3 +314,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
|
||||
|
Reference in New Issue
Block a user