add correct logout and watt data
This commit is contained in:
@@ -28,6 +28,7 @@ class HostConfig:
|
|||||||
# New attributes for Redfish stuff
|
# New attributes for Redfish stuff
|
||||||
vendor: str | None = None
|
vendor: str | None = None
|
||||||
session_token: str | None = None
|
session_token: str | None = None
|
||||||
|
session_logout: str | None = None # SessionLocation like /redfish/v1/SessionService/Sessions/marco.lucarelli%40abacus.ch00000000xxx/
|
||||||
|
|
||||||
def should_skip(self) -> bool:
|
def should_skip(self) -> bool:
|
||||||
"""Check if host is still in cool-down window"""
|
"""Check if host is still in cool-down window"""
|
||||||
@@ -120,9 +121,12 @@ async def fetch_with_retry(session, host: HostConfig, url: str) -> dict | None:
|
|||||||
payload = {"UserName": host.username, "Password": host.password}
|
payload = {"UserName": host.username, "Password": host.password}
|
||||||
async with session.post(login_url, json=payload, ssl=False, timeout=10) as login_resp:
|
async with session.post(login_url, json=payload, ssl=False, timeout=10) as login_resp:
|
||||||
if login_resp.status == 201:
|
if login_resp.status == 201:
|
||||||
host.session_token = login_resp.headers.get("X-Auth-Token")
|
host.session_token = login_resp.headers.get("X-Auth-Token") # as response in header
|
||||||
if not host.session_token:
|
if not host.session_token:
|
||||||
raise RuntimeError("No X-Auth-Token in login response")
|
raise RuntimeError("No X-Auth-Token in login response")
|
||||||
|
host.session_logout = login_resp.headers.get("Location") # as response in header
|
||||||
|
if not host.session_logout:
|
||||||
|
raise RuntimeError("No Location in login response")
|
||||||
headers["X-Auth-Token"] = host.session_token
|
headers["X-Auth-Token"] = host.session_token
|
||||||
logging.info("New session token obtained for %s", host.fqdn)
|
logging.info("New session token obtained for %s", host.fqdn)
|
||||||
else:
|
else:
|
||||||
@@ -198,7 +202,12 @@ async def get_power_data(session, host: HostConfig):
|
|||||||
|
|
||||||
for psu in data.get("PowerSupplies", []):
|
for psu in data.get("PowerSupplies", []):
|
||||||
line_input_v = psu.get("LineInputVoltage")
|
line_input_v = psu.get("LineInputVoltage")
|
||||||
watts_input = psu.get("PowerInputWatts")
|
# HPE Redfish uses LastPowerOutputWatts for Watts
|
||||||
|
if host.vendor.strip().upper().startswith("HPE"):
|
||||||
|
watts_input = psu.get("LastPowerOutputWatts")
|
||||||
|
else:
|
||||||
|
# Supermicro uses PowerInputWatts
|
||||||
|
watts_input = psu.get("PowerInputWatts")
|
||||||
serial = psu.get("SerialNumber")
|
serial = psu.get("SerialNumber")
|
||||||
|
|
||||||
amps = (
|
amps = (
|
||||||
@@ -220,9 +229,10 @@ async def logout_host(session, host):
|
|||||||
"""Clean logout for Redfish with session tokens"""
|
"""Clean logout for Redfish with session tokens"""
|
||||||
if not host.session_token:
|
if not host.session_token:
|
||||||
return
|
return
|
||||||
|
if not host.session_logout:
|
||||||
|
return
|
||||||
try:
|
try:
|
||||||
logout_url = f"https://{host.fqdn}/redfish/v1/SessionService/Sessions"
|
logout_url = f"{host.session_logout}" # the full URL is here!
|
||||||
async with session.delete(
|
async with session.delete(
|
||||||
logout_url,
|
logout_url,
|
||||||
headers={"X-Auth-Token": host.session_token},
|
headers={"X-Auth-Token": host.session_token},
|
||||||
|
|||||||
Reference in New Issue
Block a user