Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[decode-syseeprom] Optimize platform info fetch #276

Merged
merged 1 commit into from
Jun 26, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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