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

[pull] master from Azure:master #948

Merged
merged 1 commit into from
Aug 28, 2020
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
45 changes: 22 additions & 23 deletions src/sonic-py-common/sonic_py_common/device_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,25 @@
BACKEND_ASIC_SUB_ROLE = "BackEnd"


def get_localhost_info(field):
try:
config_db = ConfigDBConnector()
config_db.connect()

metadata = config_db.get_table('DEVICE_METADATA')

if 'localhost' in metadata and field in metadata['localhost']:
return metadata['localhost'][field]
except Exception:
pass

return None


def get_hostname():
return get_localhost_info('hostname')


def get_machine_info():
"""
Retreives data from the machine configuration file
Expand Down Expand Up @@ -80,18 +99,8 @@ def get_platform():
# container in SONiC, where the /host directory is not mounted. In this
# case the value should already be populated in Config DB so we finally
# try reading it from there.
try:
config_db = ConfigDBConnector()
config_db.connect()

metadata = config_db.get_table('DEVICE_METADATA')

if 'localhost' in metadata and 'platform' in metadata['localhost']:
return metadata['localhost']['platform']
except Exception:
pass

return None

return get_localhost_info('platform')


def get_hwsku():
Expand All @@ -101,18 +110,8 @@ def get_hwsku():
Returns:
A string containing the device's hardware SKU identifier
"""
try:
config_db = ConfigDBConnector()
config_db.connect()

metadata = config_db.get_table('DEVICE_METADATA')

if 'localhost' in metadata and 'hwsku' in metadata['localhost']:
return metadata['localhost']['hwsku']
except Exception:
pass

return None
return get_localhost_info('hwsku')


def get_platform_and_hwsku():
Expand Down