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