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 '{ "ApplyTime":"Immediate"}' https://${bmc}/redfish/v1/UpdateService 111``` 112 113or 114 115``` 116curl -k -H "X-Auth-Token: $token" -X PATCH -d '{ "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``` 126curl -k -H "X-Auth-Token: $token" -H "Content-Type: application/octet-stream" -X POST -T <image file path> https://${bmc}/redfish/v1/UpdateService 127``` 128TFTP Firmware update using TransferProtocol: 129Note: The `<image file path>` contains the address of the TFTP service: `xx.xx.xx.xx/obmc-phosphor-xxxxx-xxxxxxxxx.static.mtd.tar` 130 131``` 132curl -k -H "X-Auth-Token: $token" -X POST https://${bmc}/redfish/v1/UpdateService/Actions/UpdateService.SimpleUpdate -d '{"TransferProtocol":"TFTP","ImageURI":"<image file path>"}' 133``` 134TFTP Firmware update with protocol in ImageURI: 135``` 136curl -k -H "X-Auth-Token: $token" -X POST https://${bmc}/redfish/v1/UpdateService/Actions/UpdateService.SimpleUpdate -d '{"ImageURI":"tftp://<image file path>"}' 137``` 138 139--- 140 141## Update "root" password 142Change password to "0penBmc1": 143``` 144curl -k -H "X-Auth-Token: $token" -X PATCH -d '{"Password": "0penBmc1"}' https://${bmc}/redfish/v1/AccountService/Accounts/root 145``` 146 147--- 148 149## BIOS firmware boot control 150Enter into BIOS setup on boot 151``` 152curl -k -H "X-Auth-Token: $token" -X PATCH https://${bmc}/redfish/v1/Systems/system -d '{"Boot":{"BootSourceOverrideEnabled": "Continuous","BootSourceOverrideTarget": "BiosSetup"}}' 153``` 154 155Fully boot 156``` 157curl -k -H "X-Auth-Token: $token" -X PATCH https://${bmc}/redfish/v1/Systems/system -d '{"Boot":{"BootSourceOverrideEnabled": "Disabled","BootSourceOverrideTarget": "None"}}' 158``` 159 160Change Legacy/EFI selector (valid only if host is based on the x86 CPU) 161``` 162curl -k -H "X-Auth-Token: $token" -X PATCH https://${bmc}/redfish/v1/Systems/system -d '{"Boot":{"BootSourceOverrideEnabled": "Once","BootSourceOverrideTarget": "None","BootSourceOverrideMode": "UEFI"}}' 163``` 164 165--- 166 167## Enable NTP 168Add a NTP Server 169``` 170curl -k -H "X-Auth-Token: $token" -X PATCH https://${bmc}/redfish/v1/Managers/bmc/NetworkProtocol -d '{"NTP":{"NTPServers":["time.nist.gov"]}}' 171``` 172 173Now enable NTP 174``` 175curl -k -H "X-Auth-Token: $token" -X PATCH https://${bmc}/redfish/v1/Managers/bmc/NetworkProtocol -d '{"NTP":{"ProtocolEnabled": true}}' 176``` 177 178--- 179 180## Disable IPMI 181``` 182curl -k -H "X-Auth-Token: $token" -X PATCH https://${bmc}/redfish/v1/Managers/bmc/NetworkProtocol -d '{"IPMI":{"ProtocolEnabled": false}}' 183``` 184 185 186[1]: https://www.dmtf.org/standards/redfish 187