From b7eeba8b917ad2e7baa81dd0d347945c0118706a Mon Sep 17 00:00:00 2001 From: Rodny Molina Date: Tue, 7 Aug 2018 09:03:35 -0700 Subject: [PATCH] Moving get_routing_stack() to a centralized location to avoid code dups (#1714) * Moving get_routing_stack() to a centralized location to avoid code duplication Various areas of sonic-utilities are now demanding this functionality so i'm simply moving this routing to a centralized location. After spending some time debating about the ideal location for this function, we thought about sonic-config-engine/sonic_platform.py as the closest match. Functional tests' output will be provided as part of the equivalent PR to be submitted shortly within sonic-utilities repo. * Adding comment to function. --- src/sonic-config-engine/sonic_platform.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/sonic-config-engine/sonic_platform.py b/src/sonic-config-engine/sonic_platform.py index 55ad2325f5db..20890d765cab 100644 --- a/src/sonic-config-engine/sonic_platform.py +++ b/src/sonic-config-engine/sonic_platform.py @@ -54,7 +54,7 @@ def get_system_mac(): return None mac = mac.strip() - + # Align last byte of MAC if necessary if version_info and (version_info['asic_type'] == 'mellanox' or version_info['asic_type'] == 'centec'): last_byte = mac[-2:] @@ -62,3 +62,24 @@ def get_system_mac(): mac = mac[:-2] + aligned_last_byte return mac +# +# Function to obtain the routing-stack being utilized. Function is not +# platform-specific; it's being placed in this file temporarily till a more +# suitable location is identified as part of upcoming refactoring efforts. +# +def get_system_routing_stack(): + command = "sudo docker ps | grep bgp | awk '{print$2}' | cut -d'-' -f3 | cut -d':' -f1" + + try: + proc = subprocess.Popen(command, + stdout=subprocess.PIPE, + shell=True, + stderr=subprocess.STDOUT) + stdout = proc.communicate()[0] + proc.wait() + result = stdout.rstrip('\n') + + except OSError, e: + raise OSError("Cannot detect routing-stack") + + return result