Skip to content

Commit

Permalink
Optimize platform info fetch (sonic-net#276)
Browse files Browse the repository at this point in the history
Signed-off-by: Andriy Moroz <c_andriym@mellanox.com>
  • Loading branch information
andriymoroz-mlnx authored and lguohan committed Jun 26, 2018
1 parent 27ae651 commit be4f03e
Showing 1 changed file with 3 additions and 21 deletions.
24 changes: 3 additions & 21 deletions scripts/decode-syseeprom
Original file line number Diff line number Diff line change
Expand Up @@ -17,40 +17,22 @@ try:
import imp
from sonic_eeprom import eeprom_dts
import glob
from sonic_platform import get_machine_info
from sonic_platform import get_platform_info
except ImportError, e:
raise ImportError (str(e) + "- required module not found")


SONIC_CFGGEN = '/usr/local/bin/sonic-cfggen'
PLATFORM_KEY = 'DEVICE_METADATA.localhost.platform'

PLATFORM_ROOT = '/usr/share/sonic/device'

CACHE_ROOT = '/var/cache/sonic/decode-syseeprom'
CACHE_FILE = 'syseeprom_cache'

# Returns platform and HW SKU
def get_platform():
try:
proc = subprocess.Popen([SONIC_CFGGEN, '-H', '-v', PLATFORM_KEY],
stdout=subprocess.PIPE,
shell=False,
stderr=subprocess.STDOUT)
stdout = proc.communicate()[0]
proc.wait()
platform = stdout.rstrip('\n')
except OSError, e:
raise OSError("Cannot detect platform")

return platform

def main():

if not os.geteuid() == 0:
raise RuntimeError("must be root to run")

# Get platform name
platform = get_platform()
platform = get_platform_info(get_machine_info())

platform_path = '/'.join([PLATFORM_ROOT, platform])

Expand Down

0 comments on commit be4f03e

Please sign in to comment.