Skip to content

Commit

Permalink
Update redfish_api.py
Browse files Browse the repository at this point in the history
  • Loading branch information
pettershao-ragilenetworks authored Jan 20, 2023
1 parent 8dd24a8 commit 0b19c61
Showing 1 changed file with 2 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import json
import traceback
import datetime
import shlex
import os
import ssl
import subprocess
Expand Down Expand Up @@ -50,7 +51,7 @@ def get_full_url(self, url):

def _exec_cmd(self, cmd):
self.redfish_log_debug("Cmd: %s" % cmd)
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
p = subprocess.Popen(shlex.split(cmd), shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
p.wait()
self.redfish_log_debug("Cmd return: %d" % p.returncode)
str_stdout = p.stdout.read().decode('utf-8')
Expand Down Expand Up @@ -189,7 +190,6 @@ def post_thermal(self, playload):
print("post_thermal failed: playload is None")
return None
return self._redfish_post(self.ThermalUrl, playload)
def post_power(self, playload):
"""post power info
:playload: info to post
Expand All @@ -200,7 +200,6 @@ def post_power(self, playload):
print("post_power failed: playload is None")
return None
return self._redfish_post(self.PowerUrl, playload)
def post_thresholdSensors(self, playload):
"""post thresholdSensors info
:playload: info to post
Expand All @@ -211,13 +210,11 @@ def post_thresholdSensors(self, playload):
print("post_thresholdSensors failed: playload is None")
return None
return self._redfish_post(self.ThresholdSensorsUrl, playload)
def get_fanSpeed(self):
"""Get board led info
:returns: class'redfish.rest.v1.RestResponse' or None when failed
"""
return self._redfish_get(self.FanSpeedUrl)
def post_board(self, playload, board_name="indicatorboard"):
"""post board info
:board_name: name of board, default is "indicatorboard"
Expand All @@ -230,7 +227,6 @@ def post_board(self, playload, board_name="indicatorboard"):
print("post failed: playload is None")
return False
return self._redfish_post(self.BoardsUrl + board_name, playload)
def get_boardLed(self, board_name="indicatorboard"):
"""Get boardLed info
:board_name: name of board, default is "indicatorboard"
Expand All @@ -241,39 +237,33 @@ def get_boardLed(self, board_name="indicatorboard"):
print("get failed: board_name is None")
return None
return self._redfish_get(self.BoardsUrl % board_name)
'''

'''
if __name__ == '__main__':
redfish = Redfish_Api()
### get
# boards
ret = redfish.get_board()
if ret is None:
print("get failed: board")
else:
print("get succeeded, board:%s" % ret)
ret = redfish.get_thresholdSensors()
if ret is None:
print("get failed: threshold")
else:
print("get succeeded, threshold:%s" % ret)
ret = redfish.get_power()
if ret is None:
print("get failed: power")
else:
print("get succeeded, power:%s" % ret)
ret = redfish.get_thermal()
if ret is None:
print("get failed:thermal")
else:
print("get succeeded,thermal:%s" % ret)
# get playload
resp = redfish.get_thresholdSensors()
if (resp != None):
Expand All @@ -283,14 +273,12 @@ def get_boardLed(self, board_name="indicatorboard"):
print(resp["Name"])
else:
print("Failed: get_thresholdSensors")
### post
# fanSpeed
playload = {}
playload["FanName"] = 'Fan0'
playload["FanSpeedLevelPercents"] = "70"
print("post fanSpeed:%s" % redfish.post_fanSpeed(playload))
#{"LEDs": [{"IndicatorLEDColor": "green","LEDType": "sys"},{"IndicatorLEDColor": "off","LEDType": "pwr"},{"IndicatorLEDColor": "green","LEDType": "fan"}]}
playload = {}
led = {}
Expand Down

0 comments on commit 0b19c61

Please sign in to comment.