From 59392a1d0700193211a56c37d0268db0275d8fb6 Mon Sep 17 00:00:00 2001 From: Mahesh Maddikayala <10645050+smaheshm@users.noreply.github.com> Date: Thu, 20 Aug 2020 09:14:00 -0700 Subject: [PATCH] [sonic-py-common][multi ASIC] API to get a list of frontend ports (#5221) * [sonic-py-common][multi ASIC] utility to get a list of frontend ports from a given list of ports --- .../sonic_py_common/multi_asic.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/sonic-py-common/sonic_py_common/multi_asic.py b/src/sonic-py-common/sonic_py_common/multi_asic.py index 8fc22141e7c4..2083e3935bb6 100644 --- a/src/sonic-py-common/sonic_py_common/multi_asic.py +++ b/src/sonic-py-common/sonic_py_common/multi_asic.py @@ -135,9 +135,8 @@ def get_namespaces_from_linux(): In a multi asic platform, each ASIC is in a Linux Namespace. This method returns list of all the Namespace present on the device - Note: It is preferable to use this function can be used only - when the config_db is not available. - When configdb is available use get_all_namespaces() + Note: It is preferable to use this function only when config_db is not + available. When configdb is available use get_all_namespaces() Returns: List of the namespaces present in the system @@ -253,6 +252,17 @@ def is_port_internal(port_name, namespace=None): return False +def get_external_ports(port_names, namespace=None): + external_ports = set() + ports_config = get_port_table(namespace) + for port in port_names: + if port in ports_config: + if (PORT_ROLE not in ports_config[port] or + ports_config[port][PORT_ROLE] == EXTERNAL_PORT): + external_ports.add(port) + return external_ports + + def is_port_channel_internal(port_channel, namespace=None): if not is_multi_asic():