diff --git a/platform/mellanox/get_component_versions/get_component_versions.py b/platform/mellanox/get_component_versions/get_component_versions.py index dbab5a7cbd20..ba75bd8a215b 100644 --- a/platform/mellanox/get_component_versions/get_component_versions.py +++ b/platform/mellanox/get_component_versions/get_component_versions.py @@ -26,6 +26,7 @@ PlatformDataProvider = None from sonic_py_common.general import check_output_pipe +from sonic_platform.device_data import DeviceDataManager from tabulate import tabulate COMPONENT_VERSIONS_FILE = "/etc/mlnx/component-versions" @@ -120,13 +121,6 @@ def format_output_table(table): return tabulate(table, HEADERS) -def get_simx_version(): - "SIMX": [["lspci", "-vv"], ["grep", "SimX"], "([0-9]+\\.[0-9]+-[0-9]+)"] - version = check_output_pipe(["lspci", "-vv"], ["grep", "SimX"]) - parsed_version = re.search("([0-9]+\\.[0-9]+-[0-9]+)", version) - return parsed_version.group(1) if parsed_version else "N/A" - - def main(): if os.getuid() != 0: @@ -143,8 +137,8 @@ def main(): output_table.append([comp, compiled_versions[comp], actual]) # Handle if SIMX - simx_actual_ver = get_simx_version() - if simx_actual_ver: + if DeviceDataManager.is_simx_platform(): + simx_actual_ver = DeviceDataManager.get_simx_version() output_table.append(["SIMX", simx_compiled_ver, simx_actual_ver]) platform_versions = UNAVAILABLE_PLATFORM_VERSIONS else: diff --git a/platform/mellanox/mlnx-platform-api/sonic_platform/device_data.py b/platform/mellanox/mlnx-platform-api/sonic_platform/device_data.py index 9ee37af9981d..e5eabc30215c 100644 --- a/platform/mellanox/mlnx-platform-api/sonic_platform/device_data.py +++ b/platform/mellanox/mlnx-platform-api/sonic_platform/device_data.py @@ -18,8 +18,10 @@ import glob import os import time +import re from . import utils +from sonic_py_common.general import check_output_pipe DEFAULT_WD_PERIOD = 65535 @@ -160,6 +162,13 @@ def is_simx_platform(cls): platform_name = cls.get_platform_name() return platform_name and 'simx' in platform_name + @classmethod + @utils.read_only_cache() + def get_simx_version(cls): + version = check_output_pipe(["lspci", "-vv"], ["grep", "SimX"]) + parsed_version = re.search("([0-9]+\\.[0-9]+-[0-9]+)", version) + return parsed_version.group(1) if parsed_version else "N/A" + @classmethod @utils.read_only_cache() def get_fan_drawer_count(cls):