xref: /openbmc/docs/REDFISH-cheatsheet.md (revision 007e73b8e8f889bc6490dccbf02b41abd97cbfee)
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```bash
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```bash
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```bash
32export bmc_token=<token>
33```
34
35### Method 2
36
37```bash
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```bash
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```bash
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```bash
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```bash
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```bash
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```bash
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```bash
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```bash
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```bash
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```bash
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 update
128
129Firmware update: Note the `<image file path>` must be a tarball.
130
131```bash
132uri=$(curl -k -H "X-Auth-Token: $token" https://${bmc}/redfish/v1/UpdateService | jq -r ' .HttpPushUri')
133
134curl -k -H "X-Auth-Token: $token" -H "Content-Type: application/octet-stream" -X POST -T <image file path> https://${bmc}${uri}
135```
136
137Firmware update using multi-part form data: Note the `<apply time>` can be
138`OnReset` or `Immediate`.
139
140```bash
141uri=$(curl -k -H "X-Auth-Token: $token" https://${bmc}/redfish/v1/UpdateService | jq -r ' .MultipartHttpPushUri')
142
143curl -k -H "X-Auth-Token: $token" -H "Content-Type:multipart/form-data" -X POST -F UpdateParameters="{\"Targets\":[\"/redfish/v1/Managers/bmc\"],\"@Redfish.OperationApplyTime\":<apply time>};type=application/json" -F "UpdateFile=@<image file path>;type=application/octet-stream" https://${bmc}${uri}
144```
145
146TFTP Firmware update using TransferProtocol: Note: The `<image file path>`
147contains the address of the TFTP service:
148`xx.xx.xx.xx/obmc-phosphor-xxxxx-xxxxxxxxx.static.mtd.tar`
149
150```bash
151curl -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>"}'
152```
153
154TFTP Firmware update with protocol in ImageURI:
155
156```bash
157curl -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>"}'
158```
159
160---
161
162## Update "root" password
163
164Change password to "0penBmc1":
165
166```bash
167curl -k -H "X-Auth-Token: $token" -H "Content-Type: application/json" -X PATCH -d '{"Password": "0penBmc1"}' https://${bmc}/redfish/v1/AccountService/Accounts/root
168```
169
170---
171
172## BIOS firmware boot control
173
174Enter into BIOS setup on boot
175
176```bash
177curl -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"}}'
178```
179
180Fully boot
181
182```bash
183curl -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"}}'
184```
185
186Change Legacy/EFI selector (valid only if host is based on the x86 CPU)
187
188```bash
189curl -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"}}'
190```
191
192---
193
194## Enable NTP
195
196Add a NTP Server
197
198```bash
199curl -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"]}}'
200```
201
202Now enable NTP
203
204```bash
205curl -k -H "X-Auth-Token: $token" -H "Content-Type: application/json" -X PATCH https://${bmc}/redfish/v1/Managers/bmc/NetworkProtocol -d '{"NTP":{"ProtocolEnabled": true}}'
206```
207
208---
209
210## Disable IPMI
211
212```bash
213curl -k -H "X-Auth-Token: $token" -H "Content-Type: application/json" -X PATCH https://${bmc}/redfish/v1/Managers/bmc/NetworkProtocol -d '{"IPMI":{"ProtocolEnabled": false}}'
214```
215
216## Manage subscriptions
217
218List configured subscriptions:
219
220```bash
221curl -k -H "X-Auth-Token: $token" -H "Content-Type: application/json" https://${bmc}/redfish/v1/EventService/Subscriptions/
222```
223
224Setup subscription
225
226```bash
227curl -k -H "X-Auth-Token: $token" -H "Content-Type: application/json" -X POST https://${bmc}/redfish/v1/EventService/Subscriptions -d '{"Context": "My context", "DeliveryRetryPolicy": "RetryForever", "Destination": "http://yy.yy.yy.yy:8888/events", "EventFormatType": "Event", "Protocol": "Redfish", "SubscriptionType": "RedfishEvent"}"
228```
229
230Store the ID of the first subscription in an environment variable:
231
232```bash
233export subscription_id=$(curl -k -H "X-Auth-Token: $token" -H "Content-Type: application/json" https://${bmc}/redfish/v1/EventService/Subscriptions/ |jq '.Members[0]."@odata.id"' | cut -d '/' -f 6| cut -d '"' -f 1)
234```
235
236Display information for the subscription associated with the stored ID:
237
238```bash
239curl -k -H "X-Auth-Token: $token" -H "Content-Type: application/json" https://${bmc}/redfish/v1/EventService/Subscriptions/${subscription_id}
240```
241
242Update the subscription corresponding to the stored ID:
243
244```bash
245curl -k -H "X-Auth-Token: $token" -H "Content-Type: application/json" https://${bmc}/redfish/v1/EventService/Subscriptions/${subscription_id} -X PATCH -d '{"VerifyCertificate": false}'
246```
247
248Remove the subscription identified by the stored ID:
249
250```bash
251curl -k -H "X-Auth-Token: $token" -H "Content-Type: application/json" https://${bmc}/redfish/v1/EventService/Subscriptions/${subscription_id} -X DELETE
252```
253
254### Test subscriptions
255
256Send a test event using embedded into Redfish Event Service facility:
257
258```bash
259curl -k -H "X-Auth-Token: $token" -H "Content-Type: application/json" https://${bmc}/redfish/v1/EventService/Actions/EventService.SubmitTestEvent -X POST -d '{"EventTimestamp":"2023-02-13T14:49:20Z","Severity":"Warning","Message":"This is a test event message 2","MessageId":"iLOResourceEvents.1.3.DrvArrLogDrvErasing","MessageArgs":["1","slot 3"],"OriginOfCondition":"/redfish/v1/Systems/1/Storage"}'
260```
261
262Send a test DBus event, it should be picked up by the bmcweb and send event to
263the subscriber (the command should be executed on the BMC):
264
265```bash
266busctl call xyz.openbmc_project.Logging \
267/xyz/openbmc_project/logging \
268xyz.openbmc_project.Logging.Create \
269Create 'ssa{ss}' \
270OpenBMC.0.1.PowerButtonPressed \
271xyz.openbmc_project.Logging.Entry.Level.Error 0
272```
273
274[1]: https://www.dmtf.org/standards/redfish
275