Skip to content

Commit

Permalink
Moving get_routing_stack() to a centralized location to avoid code du…
Browse files Browse the repository at this point in the history
…ps (#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.
  • Loading branch information
rodnymolina authored and lguohan committed Aug 7, 2018
1 parent 634814b commit b7eeba8
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/sonic-config-engine/sonic_platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,32 @@ 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:]
aligned_last_byte = format(int(int(last_byte, 16) & 0b11000000), '02x')
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

0 comments on commit b7eeba8

Please sign in to comment.