xref: /openbmc/docs/REDFISH-cheatsheet.md (revision e1399e5c)
1# Redfish cheat sheet
2
3This document is intended to provide a set of example [Redfish][1] client
4commands for OpenBMC usage. This document uses cURL. This document assumes
5several ids, such as ManagerId, "bmc", and ComputerSystemId, "system". Assuming
6an id is not correct and any software written to use the Redfish API should not.
7From the Redfish Specification, DSP0266, "Clients shall not make assumptions
8about the URIs for the members of a resource collection."
9
10## Query Redfish Service Root
11
12```
13export bmc=xx.xx.xx.xx
14curl -k https://${bmc}/redfish/v1
15```
16
17---
18
19## Establish Redfish connection session
20
21##### Method 1
22
23```
24export bmc=xx.xx.xx.xx
25curl --insecure -H "Content-Type: application/json" -X POST -D headers.txt https://${bmc}/redfish/v1/SessionService/Sessions -d    '{"UserName":"root", "Password":"0penBmc"}'
26```
27
28A file, headers.txt, will be created. Find the `"X-Auth-Token"` in that file.
29Save it away in an env variable like so:
30
31```
32export bmc_token=<token>
33```
34
35##### Method 2
36
37```
38export bmc=xx.xx.xx.xx
39export token=`curl -k -H "Content-Type: application/json" -X POST https://${bmc}/login -d '{"username" :  "root", "password" :  "0penBmc"}' | grep token | awk '{print $2;}' | tr -d '"'`
40curl -k -H "X-Auth-Token: $token" https://${bmc}/redfish/v1/...
41```
42
43Note: Method 2 is used in this document.
44
45---
46
47## View Redfish Objects
48
49```
50curl -k -H "X-Auth-Token: $token" -X GET https://${bmc}/redfish/v1/Chassis
51curl -k -H "X-Auth-Token: $token" -X GET https://${bmc}/redfish/v1/Managers
52curl -k -H "X-Auth-Token: $token" -X GET https://${bmc}/redfish/v1/Systems
53```
54
55---
56
57## View sessions
58
59```
60curl -k -H "X-Auth-Token: $token" https://${bmc}/redfish/v1/SessionService/Sessions
61```
62
63---
64
65## Host power
66
67Host soft power off:
68
69```
70curl -k -H "X-Auth-Token: $token" -H "Content-Type: application/json" -X POST https://${bmc}/redfish/v1/Systems/system/Actions/ComputerSystem.Reset -d '{"ResetType": "GracefulShutdown"}'
71```
72
73Host hard power off:
74
75```
76curl -k -H "X-Auth-Token: $token" -H "Content-Type: application/json" -X POST https://${bmc}/redfish/v1/Systems/system/Actions/ComputerSystem.Reset -d '{"ResetType": "ForceOff"}'
77```
78
79Host power on:
80
81```
82curl -k -H "X-Auth-Token: $token" -H "Content-Type: application/json" -X POST https://${bmc}/redfish/v1/Systems/system/Actions/ComputerSystem.Reset -d '{"ResetType": "On"}'
83```
84
85Reboot Host:
86
87```
88curl -k -H "X-Auth-Token: $token" -H "Content-Type: application/json" -X POST https://${bmc}/redfish/v1/Systems/system/Actions/ComputerSystem.Reset -d '{"ResetType": "GracefulRestart"}'
89```
90
91---
92
93## BMC reboot
94
95```
96curl -k -H "X-Auth-Token: $token" -H "Content-Type: application/json" -X POST https://${bmc}/redfish/v1/Managers/bmc/Actions/Manager.Reset -d '{"ResetType": "GracefulRestart"}'
97```
98
99---
100
101## BMC factory reset
102
103Proceed with caution:
104
105```
106curl -k -H "X-Auth-Token: $token" -H "Content-Type: application/json" -X POST https://${bmc}/redfish/v1/Managers/bmc/Actions/Manager.ResetToDefaults -d '{"ResetType": "ResetAll"}'
107```
108
109---
110
111## Log entry
112
113Display logging entries:
114
115```
116curl -k -H "X-Auth-Token: $token" -X GET https://${bmc}/redfish/v1/Systems/system/LogServices/EventLog/Entries
117```
118
119Delete logging entries:
120
121```
122curl -k -H "X-Auth-Token: $token" -H "Content-Type: application/json" -X POST https://${bmc}/redfish/v1/Systems/system/LogServices/EventLog/Actions/LogService.Reset
123```
124
125---
126
127## Firmware ApplyTime:
128
129```
130curl -k -H "X-Auth-Token: $token" -H "Content-Type: application/json" -X PATCH -d '{"HttpPushUriOptions":{"HttpPushUriApplyTime":{"ApplyTime":"Immediate"}}}' https://${bmc}/redfish/v1/UpdateService
131```
132
133or
134
135```
136curl -k -H "X-Auth-Token: $token" -H "Content-Type: application/json" -X PATCH -d '{"HttpPushUriOptions":{"HttpPushUriApplyTime":{"ApplyTime":"OnReset"}}}' https://${bmc}/redfish/v1/UpdateService
137```
138
139---
140
141## Firmware update
142
143Firmware update: Note the `<image file path>` must be a tarball.
144
145```
146uri=$(curl -k -H "X-Auth-Token: $token" https://${bmc}/redfish/v1/UpdateService | jq -r ' .HttpPushUri')
147
148curl -k -H "X-Auth-Token: $token" -H "Content-Type: application/octet-stream" -X POST -T <image file path> https://${bmc}${uri}
149```
150
151TFTP Firmware update using TransferProtocol: Note: The `<image file path>`
152contains the address of the TFTP service:
153`xx.xx.xx.xx/obmc-phosphor-xxxxx-xxxxxxxxx.static.mtd.tar`
154
155```
156curl -k -H "X-Auth-Token: $token" -H "Content-Type: application/json" -X POST https://${bmc}/redfish/v1/UpdateService/Actions/UpdateService.SimpleUpdate -d '{"TransferProtocol":"TFTP","ImageURI":"<image file path>"}'
157```
158
159TFTP Firmware update with protocol in ImageURI:
160
161```
162curl -k -H "X-Auth-Token: $token" -H "Content-Type: application/json" -X POST https://${bmc}/redfish/v1/UpdateService/Actions/UpdateService.SimpleUpdate -d '{"ImageURI":"tftp://<image file path>"}'
163```
164
165---
166
167## Update "root" password
168
169Change password to "0penBmc1":
170
171```
172curl -k -H "X-Auth-Token: $token" -H "Content-Type: application/json" -X PATCH -d '{"Password": "0penBmc1"}' https://${bmc}/redfish/v1/AccountService/Accounts/root
173```
174
175---
176
177## BIOS firmware boot control
178
179Enter into BIOS setup on boot
180
181```
182curl -k -H "X-Auth-Token: $token" -H "Content-Type: application/json" -X PATCH https://${bmc}/redfish/v1/Systems/system -d '{"Boot":{"BootSourceOverrideEnabled": "Continuous","BootSourceOverrideTarget": "BiosSetup"}}'
183```
184
185Fully boot
186
187```
188curl -k -H "X-Auth-Token: $token" -H "Content-Type: application/json" -X PATCH https://${bmc}/redfish/v1/Systems/system -d '{"Boot":{"BootSourceOverrideEnabled": "Disabled","BootSourceOverrideTarget": "None"}}'
189```
190
191Change Legacy/EFI selector (valid only if host is based on the x86 CPU)
192
193```
194curl -k -H "X-Auth-Token: $token" -H "Content-Type: application/json" -X PATCH https://${bmc}/redfish/v1/Systems/system -d '{"Boot":{"BootSourceOverrideEnabled": "Once","BootSourceOverrideTarget": "None","BootSourceOverrideMode": "UEFI"}}'
195```
196
197---
198
199## Enable NTP
200
201Add a NTP Server
202
203```
204curl -k -H "X-Auth-Token: $token" -H "Content-Type: application/json" -X PATCH https://${bmc}/redfish/v1/Managers/bmc/NetworkProtocol -d '{"NTP":{"NTPServers":["time.nist.gov"]}}'
205```
206
207Now enable NTP
208
209```
210curl -k -H "X-Auth-Token: $token" -H "Content-Type: application/json" -X PATCH https://${bmc}/redfish/v1/Managers/bmc/NetworkProtocol -d '{"NTP":{"ProtocolEnabled": true}}'
211```
212
213---
214
215## Disable IPMI
216
217```
218curl -k -H "X-Auth-Token: $token" -H "Content-Type: application/json" -X PATCH https://${bmc}/redfish/v1/Managers/bmc/NetworkProtocol -d '{"IPMI":{"ProtocolEnabled": false}}'
219```
220
221[1]: https://www.dmtf.org/standards/redfish
222