test hpe redfish implementation
This commit is contained in:
@@ -4,13 +4,41 @@ import urllib3
|
|||||||
|
|
||||||
urllib3.disable_warnings()
|
urllib3.disable_warnings()
|
||||||
|
|
||||||
username = "<user>"
|
username = "marco.lucarelli@abacus.ch"
|
||||||
password = "<password>"
|
password = "secret"
|
||||||
# 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/"
|
||||||
|
response = requests.get(url, verify=False)
|
||||||
|
response.raise_for_status()
|
||||||
|
data = response.json()
|
||||||
|
vendor = data.get("Vendor", "")
|
||||||
|
is_hpe = vendor.strip().upper().startswith("HPE")
|
||||||
|
if is_hpe:
|
||||||
|
response = "" # just to be sure
|
||||||
|
login_url = f"https://{host}.mgmt.wtb1.ch.abainfra.net/redfish/v1/SessionService/Sessions"
|
||||||
|
payload = {"UserName": username, "Password": password}
|
||||||
|
response = requests.post(login_url, json=payload, verify=False, timeout=10)
|
||||||
|
print(response)
|
||||||
|
response.raise_for_status()
|
||||||
|
if response.status_code == 201:
|
||||||
|
token = response.headers.get("X-Auth-Token")
|
||||||
|
if not token:
|
||||||
|
raise RuntimeError("No X-Auth-Token in login response")
|
||||||
|
headers = {"X-Auth-Token": token}
|
||||||
|
url = f"https://{host}.mgmt.wtb1.ch.abainfra.net/redfish/v1/Chassis/1/Power"
|
||||||
|
response = requests.get(url, verify=False, headers=headers)
|
||||||
|
if response.status_code == 200:
|
||||||
|
data = response.json()
|
||||||
|
print(data)
|
||||||
|
print(response)
|
||||||
|
print(vendor)
|
||||||
|
print(is_hpe)
|
||||||
|
quit()
|
||||||
|
|
||||||
url = f"https://{host}.mgmt.wtb1.ch.abainfra.net/redfish/v1/Chassis/1/Power"
|
url = f"https://{host}.mgmt.wtb1.ch.abainfra.net/redfish/v1/Chassis/1/Power"
|
||||||
response = requests.get(url, auth=(username, password), verify=False)
|
response = requests.get(url, auth=(username, password), verify=False)
|
||||||
|
|
||||||
@@ -29,7 +57,7 @@ def get_power_data(host):
|
|||||||
|
|
||||||
# loop over each hosts
|
# loop over each hosts
|
||||||
hosts = [
|
hosts = [
|
||||||
"srv1-112",
|
"srv1-110",
|
||||||
]
|
]
|
||||||
for host in hosts:
|
for host in hosts:
|
||||||
get_power_data(host)
|
get_power_data(host)
|
||||||
|
|||||||
Reference in New Issue
Block a user