forked from ozorob2/nodes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython_redfish_v2.py
More file actions
68 lines (41 loc) · 2.24 KB
/
python_redfish_v2.py
File metadata and controls
68 lines (41 loc) · 2.24 KB
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
import requests
import json
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
print("\nUsing Redfish to mount an ISO image.")
print("\nCurrent version assumes no ISO image is attached initially + Server is powered on.")
proxy_url = input("\nEnter your proxy server url, if N/A, please enter none: ")
proxies = {
"http": proxy_url,
"https": proxy_url
}
print("\nProxy used: ", proxy_url)
ilo5_ip = input("\nEnter the iLO5 IP address of your server: ")
iso_url = input("\nEnter the url to your ISO image: ")
# Command 1
url = f"https://{ilo5_ip}/redfish/v1/sessionService/Sessions"
headers = {"Content-Type": "application/json"}
data = {"UserName": "Administrator", "Password": "password"}
response = requests.post(url, headers=headers, data=json.dumps(data), proxies=proxies, verify=False)
# Command 2
url = f"https://{ilo5_ip}/redfish/v1/sessionService/Sessions"
headers = {"Content-Type": "application/json"}
data = {"UserName": "Administrator", "Password": "password"}
response = requests.post(url, headers=headers, data=json.dumps(data), proxies=proxies, verify=False)
token = response.headers.get("X-Auth-Token")
# Command 3
url = f"https://{ilo5_ip}/redfish/v1/Managers/1/VirtualMedia/2/Actions/VirtualMedia.InsertMedia"
headers = {"Content-Type": "application/json", "X-Auth-Token": token}
data = {"Image": iso_url, "Inserted": True, "WriteProtected": True}
response = requests.post(url, headers=headers, data=json.dumps(data), proxies=proxies, verify=False)
# Command 4
url = f"https://{ilo5_ip}/redfish/v1/Managers/1/VirtualMedia/2"
headers = {"Content-Type": "application/json", "X-Auth-Token": token}
data = {"Oem": {"Hpe": {"BootOnNextServerReset": True}}}
response = requests.patch(url, headers=headers, data=json.dumps(data), proxies=proxies, verify=False)
# Command 5
url = f"https://{ilo5_ip}/redfish/v1/Systems/1/Actions/ComputerSystem.Reset"
headers = {"Content-Type": "application/json", "X-Auth-Token": token}
data = {"Action": "Reset", "ResetType": "ForceRestart"}
response = requests.post(url, headers=headers, data=json.dumps(data), proxies=proxies, verify=False)
print("\nISO image mounted successfully, rebooting system now.\n")