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 137Firmware update using multi-part form data: Note the `<apply time>` can be 138`OnReset` or `Immediate`. 139 140``` 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``` 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``` 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``` 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``` 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``` 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``` 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``` 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``` 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``` 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[1]: https://www.dmtf.org/standards/redfish 217