From d19692b28e5154512b95e49ed590d2cd175137f3 Mon Sep 17 00:00:00 2001 From: Mahesh Maddikayala Date: Wed, 19 Aug 2020 14:23:56 -0700 Subject: [PATCH 1/3] [sonic-py-common][multi ASIC] utility to get a list of external ports from a given list of ports --- src/sonic-py-common/sonic_py_common/multi_asic.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 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 966b5d238e25..4cc4e981e814 100644 --- a/src/sonic-py-common/sonic_py_common/multi_asic.py +++ b/src/sonic-py-common/sonic_py_common/multi_asic.py @@ -135,8 +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. + 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() Returns: @@ -253,6 +253,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(): From 9d92da7df66cfbdaa7a6824ac11b59fb5e3ee841 Mon Sep 17 00:00:00 2001 From: Mahesh Maddikayala Date: Wed, 19 Aug 2020 17:33:46 -0700 Subject: [PATCH 2/3] fix formatting --- src/sonic-py-common/sonic_py_common/multi_asic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 4cc4e981e814..ac230725e080 100644 --- a/src/sonic-py-common/sonic_py_common/multi_asic.py +++ b/src/sonic-py-common/sonic_py_common/multi_asic.py @@ -259,7 +259,7 @@ def get_external_ports(port_names, namespace=None): 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): + ports_config[port][PORT_ROLE] == EXTERNAL_PORT): external_ports.add(port) return external_ports From d4d2b86bd023e48bf05f37a39946d5b01d3208c0 Mon Sep 17 00:00:00 2001 From: Mahesh Maddikayala Date: Wed, 19 Aug 2020 17:40:56 -0700 Subject: [PATCH 3/3] fix comment --- src/sonic-py-common/sonic_py_common/multi_asic.py | 5 ++--- 1 file changed, 2 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 ac230725e080..3b2173193c0a 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