simple script for testing

This commit is contained in:
2026-01-30 14:09:19 +01:00
parent cee64faaa8
commit ce6e2e7f26

View File

@@ -4,14 +4,14 @@ import urllib3
urllib3.disable_warnings() urllib3.disable_warnings()
username = "marco.lucarelli@abacus.ch" username = "admin"
password = "secret" password = "admin"
# host = sys.argv[1] # host = sys.argv[1]
def get_power_data(host): def get_power_data(host):
"""Redfish API Chassis Power""" """Redfish API Chassis Power"""
url = f"https://{host}.mgmt.wtb1.ch.abainfra.net/redfish/v1/" url = f"https://{host}/redfish/v1/"
response = requests.get(url, verify=False) response = requests.get(url, verify=False)
response.raise_for_status() response.raise_for_status()
data = response.json() data = response.json()
@@ -19,7 +19,7 @@ def get_power_data(host):
is_hpe = vendor.strip().upper().startswith("HPE") is_hpe = vendor.strip().upper().startswith("HPE")
if is_hpe: if is_hpe:
response = "" # just to be sure response = "" # just to be sure
login_url = f"https://{host}.mgmt.wtb1.ch.abainfra.net/redfish/v1/SessionService/Sessions" login_url = f"https://{host}/redfish/v1/SessionService/Sessions"
payload = {"UserName": username, "Password": password} payload = {"UserName": username, "Password": password}
response = requests.post(login_url, json=payload, verify=False, timeout=10) response = requests.post(login_url, json=payload, verify=False, timeout=10)
print(response) print(response)
@@ -29,7 +29,7 @@ def get_power_data(host):
if not token: if not token:
raise RuntimeError("No X-Auth-Token in login response") raise RuntimeError("No X-Auth-Token in login response")
headers = {"X-Auth-Token": token} headers = {"X-Auth-Token": token}
url = f"https://{host}.mgmt.wtb1.ch.abainfra.net/redfish/v1/Chassis/1/Power" url = f"https://{host}/redfish/v1/Chassis/1/Power"
response = requests.get(url, verify=False, headers=headers) response = requests.get(url, verify=False, headers=headers)
if response.status_code == 200: if response.status_code == 200:
data = response.json() data = response.json()
@@ -37,19 +37,20 @@ def get_power_data(host):
print(response) print(response)
print(vendor) print(vendor)
print(is_hpe) print(is_hpe)
quit()
url = f"https://{host}.mgmt.wtb1.ch.abainfra.net/redfish/v1/Chassis/1/Power"
url = f"https://{host}/redfish/v1/Chassis/1/Power"
response = requests.get(url, auth=(username, password), verify=False) response = requests.get(url, auth=(username, password), verify=False)
if response.status_code == 200: if response.status_code == 200:
data = response.json() data = response.json()
for idx, psu in enumerate(data.get("PowerSupplies", [])): for idx, psu in enumerate(data.get("PowerSupplies", [])):
print(idx)
line_input_v = psu.get("LineInputVoltage") line_input_v = psu.get("LineInputVoltage")
watts_input = psu.get("PowerInputWatts") watts_input = psu.get("PowerInputWatts")
serial = psu.get("SerialNumber") serial = psu.get("SerialNumber")
print( print(
f"PSU {idx}, {serial}: {host}, {line_input_v} V, {watts_input} W, {round(watts_input / line_input_v, 2)} A" f"PSU {idx}, {serial}: {host}, {line_input_v} V, {watts_input} W"
) )
else: else:
print(f"Error {response.status_code}: {response.text}") print(f"Error {response.status_code}: {response.text}")
@@ -57,7 +58,7 @@ def get_power_data(host):
# loop over each hosts # loop over each hosts
hosts = [ hosts = [
"srv1-110", "22-kvm.abao.ch",
] ]
for host in hosts: for host in hosts:
get_power_data(host) get_power_data(host)