-
Notifications
You must be signed in to change notification settings - Fork 0
/
intelRedfish.py
92 lines (61 loc) · 3.07 KB
/
intelRedfish.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import re
import urllib3
import urllib.parse
import requests
import sys
from redfishwrapper.redfish import Redfish
class IntelRedfish(Redfish):
# vendor-specific API endpoints:
VENDOR_THERMAL_SUFFIX = 'Baseboard/Thermal'
VENDOR_POWER_SUFFIX = 'Baseboard/Power'
SYSTEM_I = 0
def getAllMetrics(self) -> dict:
# get all metrics defined for node
power_cons_dict = {'NodeTotalPower': self.getPowerCons()}
result = {}
result = Redfish.mergeDicts(result, self.getSystemMetrics())
result = Redfish.mergeDicts(result, self.getThermalDict())
result = Redfish.mergeDicts(result, power_cons_dict)
return result
def getPowerCons(self) -> int:
# intel-specific PSU power read-out
url = Redfish.mergeUrlElements([self._getChassisURL(self.SYSTEM_I),self.VENDOR_POWER_SUFFIX])
r = requests.get(url, auth=self.auth_tuple, verify=self.verifySSL)
power_cons = int(r.json()['PowerControl'][0]['PowerConsumedWatts'])
return power_cons
def resetBMC(self):
# Intel specific BMC reset action
# - /redfish/v1/Managers/BMC/Actions/Manager.Reset
API_ENDPOINT = "Actions/Manager.Reset"
url = Redfish.mergeUrlElements([self._getManagerURL(self.SYSTEM_I), API_ENDPOINT])
json={"ResetType": "ForceRestart"}
r = requests.post(url,auth=self.auth_tuple, verify=self.verifySSL, json=json)
def powerAction(self,action:str):
# Intel specific chassis power action
# - /redfish/v1/Systems/{systemID}/Actions/ComputerSystem.Reset
POWER_ACTIONS = [ "PushPowerButton", "On", "GracefulShutdown", "ForceRestmergeUrlElementseOn", "ForceOff" ]
API_ENDPOINT = "Actions/ComputerSystem.Reset"
if action not in POWER_ACTIONS:
NotImplementedError(f"Action {action} not defined. Only [{','.join(POWER_ACTIONS)}] allowed.")
url = Redfish.mergeUrlElements([self._getSystemURL(self.SYSTEM_I), API_ENDPOINT ])
json={"ResetType": action }
r = requests.post(url,auth=self.auth_tuple, verify=self.verifySSL, json=json)
def getSystemMetrics(self) -> int:
# intel-specific metrics
# - /redfish/v1/Systems/{systemID}/Metrics
url = Redfish.mergeUrlElements([self._getSystemURL(self.SYSTEM_I), "Metrics"])
r = requests.get(url, auth=self.auth_tuple, verify=self.verifySSL)
result = {}
fields = ["ProcessorPowerWatt", "MemoryPowerWatt", "ProcessorBandwidthPercent", "MemoryBandwidthPercent","IOBandwidthGBps" ]
for field in fields:
value = r.json()[field]
try:
value_float = float(value)
except ValueError:
value_float = None
if value_float:
result[field] = value_float
return(result)
#NOTES:
# * /redfish/v1/Managers/BMC/VirtualMedia/WebISO/Actions/VirtualMedia.InsertMedia - BROKEN in intel implementation of RedFIsh
# * /redfish/v1/Managers/BMC/VirtualMedia/WebISO/Actions/VirtualMedia.EjectMedia - BROKEN in intel implementation of RedFIsh