From 03555f6437c4f796700c53f2e914b257db4dd62b Mon Sep 17 00:00:00 2001 From: Andriy Moroz Date: Thu, 19 Oct 2017 18:09:01 +0300 Subject: [PATCH] Add get_presence implementation for SFP on Mellanox platforms Signed-off-by: Andriy Moroz --- .../x86_64-mlnx_msn2410-r0/plugins/sfputil.py | 17 ++++++++++++++++- .../x86_64-mlnx_msn2700-r0/plugins/sfputil.py | 17 ++++++++++++++++- .../x86_64-mlnx_msn2740-r0/plugins/sfputil.py | 17 ++++++++++++++++- 3 files changed, 48 insertions(+), 3 deletions(-) diff --git a/device/mellanox/x86_64-mlnx_msn2410-r0/plugins/sfputil.py b/device/mellanox/x86_64-mlnx_msn2410-r0/plugins/sfputil.py index db71cb423503..0d7870b785fa 100644 --- a/device/mellanox/x86_64-mlnx_msn2410-r0/plugins/sfputil.py +++ b/device/mellanox/x86_64-mlnx_msn2410-r0/plugins/sfputil.py @@ -46,8 +46,23 @@ def __init__(self): SfpUtilBase.__init__(self) def get_presence(self, port_num): + # Check for invalid port_num + if port_num < self.port_start or port_num > self.port_end: + return False - raise NotImplementedError + try: + reg_file = open("/bsp/qsfp/qsfp%d_status" % (port_num+1)) + except IOError as e: + print "Error: unable to open file: %s" % str(e) + return False + + content = reg_file.readline().rstrip() + + # content is a string with the qsfp status + if content == "good": + return True + + return False def get_low_power_mode(self, port_num): diff --git a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfputil.py b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfputil.py index b746af219917..b768cc44022d 100644 --- a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfputil.py +++ b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfputil.py @@ -46,8 +46,23 @@ def __init__(self): SfpUtilBase.__init__(self) def get_presence(self, port_num): + # Check for invalid port_num + if port_num < self.port_start or port_num > self.port_end: + return False - raise NotImplementedError + try: + reg_file = open("/bsp/qsfp/qsfp%d_status" % (port_num+1)) + except IOError as e: + print "Error: unable to open file: %s" % str(e) + return False + + content = reg_file.readline().rstrip() + + # content is a string with the qsfp status + if content == "good": + return True + + return False def get_low_power_mode(self, port_num): diff --git a/device/mellanox/x86_64-mlnx_msn2740-r0/plugins/sfputil.py b/device/mellanox/x86_64-mlnx_msn2740-r0/plugins/sfputil.py index b746af219917..b768cc44022d 100644 --- a/device/mellanox/x86_64-mlnx_msn2740-r0/plugins/sfputil.py +++ b/device/mellanox/x86_64-mlnx_msn2740-r0/plugins/sfputil.py @@ -46,8 +46,23 @@ def __init__(self): SfpUtilBase.__init__(self) def get_presence(self, port_num): + # Check for invalid port_num + if port_num < self.port_start or port_num > self.port_end: + return False - raise NotImplementedError + try: + reg_file = open("/bsp/qsfp/qsfp%d_status" % (port_num+1)) + except IOError as e: + print "Error: unable to open file: %s" % str(e) + return False + + content = reg_file.readline().rstrip() + + # content is a string with the qsfp status + if content == "good": + return True + + return False def get_low_power_mode(self, port_num):