forked from sonic-net/sonic-buildimage
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Mellanox] Support max/min speed for PSU fan (sonic-net#5682)
As new hw-mgmt expose the sysfs for PSU fan max speed, we need support max/min speed for PSU fan in mellanox platform API. Conflicts: platform/mellanox/mlnx-platform-api/sonic_platform/fan.py
- Loading branch information
1 parent
5a80253
commit 540ef44
Showing
2 changed files
with
83 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
platform/mellanox/mlnx-platform-api/sonic_platform/utils.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
def read_str_from_file(file_path, default='', raise_exception=False): | ||
""" | ||
Read string content from file | ||
:param file_path: File path | ||
:param default: Default return value if any exception occur | ||
:param raise_exception: Raise exception to caller if True else just return default value | ||
:return: String content of the file | ||
""" | ||
try: | ||
with open(file_path, 'r') as f: | ||
value = f.read().strip() | ||
except (ValueError, IOError) as e: | ||
if not raise_exception: | ||
value = default | ||
else: | ||
raise e | ||
|
||
return value | ||
|
||
|
||
def read_int_from_file(file_path, default=0, raise_exception=False): | ||
""" | ||
Read content from file and cast it to integer | ||
:param file_path: File path | ||
:param default: Default return value if any exception occur | ||
:param raise_exception: Raise exception to caller if True else just return default value | ||
:return: Integer value of the file content | ||
""" | ||
try: | ||
with open(file_path, 'r') as f: | ||
value = int(f.read().strip()) | ||
except (ValueError, IOError) as e: | ||
if not raise_exception: | ||
value = default | ||
else: | ||
raise e | ||
|
||
return value | ||
|
||
|
||
def write_file(file_path, content, raise_exception=False): | ||
""" | ||
Write the given value to a file | ||
:param file_path: File path | ||
:param content: Value to write to the file | ||
:param raise_exception: Raise exception to caller if True | ||
:return: True if write success else False | ||
""" | ||
try: | ||
with open(file_path, 'w') as f: | ||
f.write(str(content)) | ||
except (ValueError, IOError) as e: | ||
if not raise_exception: | ||
return False | ||
else: | ||
raise e | ||
return True |