xref: /openbmc/docs/REDFISH-cheatsheet.md (revision 8d4906ee)
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 update
128
129Firmware update: Note the `<image file path>` must be a tarball.
130
131```
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
137TFTP Firmware update using TransferProtocol: Note: The `<image file path>`
138contains the address of the TFTP service:
139`xx.xx.xx.xx/obmc-phosphor-xxxxx-xxxxxxxxx.static.mtd.tar`
140
141```
142curl -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>"}'
143```
144
145TFTP Firmware update with protocol in ImageURI:
146
147```
148curl -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>"}'
149```
150
151---
152
153## Update "root" password
154
155Change password to "0penBmc1":
156
157```
158curl -k -H "X-Auth-Token: $token" -H "Content-Type: application/json" -X PATCH -d '{"Password": "0penBmc1"}' https://${bmc}/redfish/v1/AccountService/Accounts/root
159```
160
161---
162
163## BIOS firmware boot control
164
165Enter into BIOS setup on boot
166
167```
168curl -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"}}'
169```
170
171Fully boot
172
173```
174curl -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"}}'
175```
176
177Change Legacy/EFI selector (valid only if host is based on the x86 CPU)
178
179```
180curl -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"}}'
181```
182
183---
184
185## Enable NTP
186
187Add a NTP Server
188
189```
190curl -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"]}}'
191```
192
193Now enable NTP
194
195```
196curl -k -H "X-Auth-Token: $token" -H "Content-Type: application/json" -X PATCH https://${bmc}/redfish/v1/Managers/bmc/NetworkProtocol -d '{"NTP":{"ProtocolEnabled": true}}'
197```
198
199---
200
201## Disable IPMI
202
203```
204curl -k -H "X-Auth-Token: $token" -H "Content-Type: application/json" -X PATCH https://${bmc}/redfish/v1/Managers/bmc/NetworkProtocol -d '{"IPMI":{"ProtocolEnabled": false}}'
205```
206
207[1]: https://www.dmtf.org/standards/redfish
208