1f1ee823dSGeorge Keishing# OpenBMC REST cheat sheet 2f1ee823dSGeorge Keishing 3f4febd00SPatrick WilliamsThis document is intended to provide a set of REST client commands for OpenBMC 4*37071746SGunnar Millsusage. OpenBMC REST is disabled by default in bmcweb. For more information, see 5*37071746SGunnar Millshttps://github.com/openbmc/bmcweb/commit/47c9e106e0057dd70133d50e928e48cbc68e709a. 6*37071746SGunnar MillsMost of the functionality previously provided by OpenBMC REST is available in 7*37071746SGunnar MillsRedfish. 8f1ee823dSGeorge Keishing 9f1ee823dSGeorge Keishing## Using CURL commands 103c864e92SMatt Spinler 113c864e92SMatt Spinler### Notes on authentication: 12f4febd00SPatrick Williams 133c864e92SMatt SpinlerThe original REST server, from the phosphor-rest-server repository, uses 14f4febd00SPatrick Williamsauthentication handled by the curl cookie jar files. The bmcweb REST server can 15f4febd00SPatrick Williamsuse the same cookie jar files for read-only REST methods like GET, but requires 16f4febd00SPatrick Williamseither an authentication token or the username and password passed in as part of 17f4febd00SPatrick Williamsthe URL for non-read-only methods. 183c864e92SMatt Spinler 19df6b9c27SGunnar MillsStarting with the 2.7 OpenBMC release (August 2019), bmcweb is the default REST 20*37071746SGunnar Millsserver. The phosphor-rest-server repository was archived in October 2022. 213c864e92SMatt Spinler 223c864e92SMatt Spinler### Establish REST connection session 23f4febd00SPatrick Williams 24f4febd00SPatrick Williams- Using just the cookie jar files for the phosphor-rest server: 25f1ee823dSGeorge Keishing ``` 26f1ee823dSGeorge Keishing $ export bmc=xx.xx.xx.xx 27f1ee823dSGeorge Keishing $ curl -c cjar -b cjar -k -H "Content-Type: application/json" -X POST https://${bmc}/login -d "{\"data\": [ \"root\", \"0penBmc\" ] }" 28f1ee823dSGeorge Keishing ``` 29f4febd00SPatrick Williams- If passing in the username/password as part of the URL, no unique login call 303c864e92SMatt Spinler is required. The URL format is: 31b41aff0fSXiaochao Ma 323c864e92SMatt Spinler ``` 333c864e92SMatt Spinler <username>:<password>@<hostname>/<path>... 343c864e92SMatt Spinler ``` 35f4febd00SPatrick Williams 363c864e92SMatt Spinler For example: 37f4febd00SPatrick Williams 383c864e92SMatt Spinler ``` 393c864e92SMatt Spinler $ export bmc=xx.xx.xx.xx 40b41aff0fSXiaochao Ma $ curl -k -X GET https://root:0penBmc@${bmc}/xyz/openbmc_project/list 413c864e92SMatt Spinler ``` 42f4febd00SPatrick Williams 43f4febd00SPatrick Williams- Token based authentication. 443c864e92SMatt Spinler 453c864e92SMatt Spinler ``` 463c864e92SMatt Spinler $ export bmc=xx.xx.xx.xx 47b41aff0fSXiaochao Ma $ export 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 '"'` 48b41aff0fSXiaochao Ma $ curl -k -H "X-Auth-Token: $token" https://${bmc}/xyz/openbmc_project/... 493c864e92SMatt Spinler ``` 503c864e92SMatt Spinler 51b41aff0fSXiaochao Ma The third method is recommended. 52b41aff0fSXiaochao Ma 533c864e92SMatt Spinler### Commands 54f4febd00SPatrick Williams 553c864e92SMatt SpinlerNote: To keep the syntax below common between the phosphor-rest and bmcweb 56f4febd00SPatrick Williamsimplementations as described above, this assumes that if bmcweb is used it is 57f4febd00SPatrick Williamsusing the 'Token based' login method as described above: 58b41aff0fSXiaochao Ma 593c864e92SMatt Spinler``` 60b41aff0fSXiaochao Ma$ export bmc=xx.xx.xx.xx 61b41aff0fSXiaochao Ma$ export 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 '"'` 62b41aff0fSXiaochao Ma$ curl -k -H "X-Auth-Token: $token" https://$bmc/xyz/openbmc_project/... 633c864e92SMatt Spinler``` 64f1ee823dSGeorge Keishing 65f4febd00SPatrick Williams- List and enumerate: 66f4febd00SPatrick Williams 67f1ee823dSGeorge Keishing ``` 68b41aff0fSXiaochao Ma $ curl -k -H "X-Auth-Token: $token" https://${bmc}/xyz/openbmc_project/list 69b41aff0fSXiaochao Ma $ curl -k -H "X-Auth-Token: $token" https://${bmc}/xyz/openbmc_project/enumerate 70f1ee823dSGeorge Keishing ``` 71f1ee823dSGeorge Keishing 72f4febd00SPatrick Williams- List sub-objects: 73f4febd00SPatrick Williams 74f1ee823dSGeorge Keishing ``` 75b41aff0fSXiaochao Ma $ curl -k -H "X-Auth-Token: $token" https://${bmc}/xyz/openbmc_project/ 76b41aff0fSXiaochao Ma $ curl -k -H "X-Auth-Token: $token" https://${bmc}/xyz/openbmc_project/state/ 77f1ee823dSGeorge Keishing ``` 78f1ee823dSGeorge Keishing 79f4febd00SPatrick Williams- Host soft power off: 80f4febd00SPatrick Williams 81f1ee823dSGeorge Keishing ``` 82b41aff0fSXiaochao Ma $ curl -k -H "X-Auth-Token: $token" -H "Content-Type: application/json" -d '{"data": "xyz.openbmc_project.State.Host.Transition.Off"}' -X PUT https://${bmc}/xyz/openbmc_project/state/host0/attr/RequestedHostTransition 83f1ee823dSGeorge Keishing ``` 84f1ee823dSGeorge Keishing 85f4febd00SPatrick Williams- Host hard power off: 86f4febd00SPatrick Williams 87f1ee823dSGeorge Keishing ``` 88b41aff0fSXiaochao Ma $ curl -k -H "X-Auth-Token: $token" -H "Content-Type: application/json" -X PUT -d '{"data":"xyz.openbmc_project.State.Chassis.Transition.Off"}' https://${bmc}//xyz/openbmc_project/state/chassis0/attr/RequestedPowerTransition 89f1ee823dSGeorge Keishing ``` 90d2431e93SGeorge Keishing 91f4febd00SPatrick Williams- Host power on: 92f4febd00SPatrick Williams 93f1ee823dSGeorge Keishing ``` 94b41aff0fSXiaochao Ma $ curl -k -H "X-Auth-Token: $token" -H "Content-Type: application/json" -d '{"data": "xyz.openbmc_project.State.Host.Transition.On"}' -X PUT https://${bmc}/xyz/openbmc_project/state/host0/attr/RequestedHostTransition 95f1ee823dSGeorge Keishing ``` 96f1ee823dSGeorge Keishing 97f4febd00SPatrick Williams- Reboot Host: 98f4febd00SPatrick Williams 99d2431e93SGeorge Keishing ``` 100b41aff0fSXiaochao Ma $ curl -k -H "X-Auth-Token: $token" -H "Content-Type: application/json" -X PUT -d '{"data":"xyz.openbmc_project.State.Host.Transition.Reboot"}' https://${bmc}/xyz/openbmc_project/state/host0/attr/RequestedHostTransition 101d2431e93SGeorge Keishing ``` 102d2431e93SGeorge Keishing 103f4febd00SPatrick Williams- Reboot BMC: 104f4febd00SPatrick Williams 105f1ee823dSGeorge Keishing ``` 1066a0c41c4SGunnar Mills $ curl -k -H "X-Auth-Token: $token" -H "Content-Type: application/json" -X PUT -d '{"data":"xyz.openbmc_project.State.BMC.Transition.Reboot"}' https://${bmc}/xyz/openbmc_project/state/bmc0/attr/RequestedBMCTransition 107f1ee823dSGeorge Keishing ``` 108d2431e93SGeorge Keishing 109f4febd00SPatrick Williams- Display logging entries: 110f4febd00SPatrick Williams 111d986cb1fSAndrew Geissler ``` 112b41aff0fSXiaochao Ma $ curl -k -H "X-Auth-Token: $token" -H "Content-Type: application/json" -X GET https://${bmc}/xyz/openbmc_project/logging/entry/enumerate 113d986cb1fSAndrew Geissler ``` 114d986cb1fSAndrew Geissler 115f4febd00SPatrick Williams- Delete logging entries: 116f4febd00SPatrick Williams 117f1ee823dSGeorge Keishing ``` 118b41aff0fSXiaochao Ma $ curl -k -H "X-Auth-Token: $token" -H "Content-Type: application/json" -X DELETE https://${bmc}/xyz/openbmc_project/logging/entry/<entry_id> 119b41aff0fSXiaochao Ma $ curl -k -H "X-Auth-Token: $token" -H 'Content-Type: application/json' -X POST -d '{"data":[]}' https://${bmc}/xyz/openbmc_project/logging/action/DeleteAll 120f1ee823dSGeorge Keishing ``` 121d2431e93SGeorge Keishing 122f4febd00SPatrick Williams- Delete dump entries: 123f4febd00SPatrick Williams 124d8260bfbSGeorge Keishing ``` 125b41aff0fSXiaochao Ma $ curl -k -H "X-Auth-Token: $token" -H "Content-Type: application/json" -X DELETE https://${bmc}/xyz/openbmc_project/dump/entry/<entry_id> 126b41aff0fSXiaochao Ma $ curl -k -H "X-Auth-Token: $token" -H 'Content-Type: application/json' -X POST -d '{"data":[]}' https://${bmc}/xyz/openbmc_project/dump/action/DeleteAll 127d8260bfbSGeorge Keishing ``` 128d8260bfbSGeorge Keishing 129f4febd00SPatrick Williams- Delete images from system: 13085b67c0eSGeorge Keishing 13185b67c0eSGeorge Keishing - Delete image: 132f4febd00SPatrick Williams 13385b67c0eSGeorge Keishing ``` 134b41aff0fSXiaochao Ma $ curl -k -H "X-Auth-Token: $token" -H "Content-Type: application/json" -X POST -d '{"data": []}' https://${bmc}/xyz/openbmc_project/software/<image id>/action/Delete 13585b67c0eSGeorge Keishing ``` 13685b67c0eSGeorge Keishing 13785b67c0eSGeorge Keishing - Delete all non-running images: 138f4febd00SPatrick Williams 13985b67c0eSGeorge Keishing ``` 140b41aff0fSXiaochao Ma $ curl -k -H "X-Auth-Token: $token" -H "Content-Type: application/json" -X POST -d '{"data": []}' https://${bmc}/xyz/openbmc_project/software/action/DeleteAll 14185b67c0eSGeorge Keishing ``` 14285b67c0eSGeorge Keishing 143f4febd00SPatrick Williams- Clear gard records: 144f4febd00SPatrick Williams 145d2431e93SGeorge Keishing ``` 146b41aff0fSXiaochao Ma $ curl -k -H "X-Auth-Token: $token" -H "Content-Type: application/json" -X POST -d '{"data":[]}' https://${bmc}/org/open_power/control/gard/action/Reset 147d2431e93SGeorge Keishing ``` 148d2431e93SGeorge Keishing 149f4febd00SPatrick Williams- Control boot source override: 150264d4e0fSKonstantin Aladyshev 151264d4e0fSKonstantin Aladyshev - Read current boot source override settings: 152f4febd00SPatrick Williams 153f1ee823dSGeorge Keishing ``` 154264d4e0fSKonstantin Aladyshev $ curl -k -H "X-Auth-Token: $token" https://${bmc}/xyz/openbmc_project/control/host0/boot/enumerate 155f1ee823dSGeorge Keishing ``` 156d2431e93SGeorge Keishing 157264d4e0fSKonstantin Aladyshev - Set boot source: 158f4febd00SPatrick Williams 159f1ee823dSGeorge Keishing ``` 160264d4e0fSKonstantin Aladyshev $ curl -k -H "X-Auth-Token: $token" -H "Content-Type: application/json" -X PUT https://${bmc}/xyz/openbmc_project/control/host0/boot/attr/BootSource -d '{"data": "xyz.openbmc_project.Control.Boot.Source.Sources.Default"}' 161264d4e0fSKonstantin Aladyshev ``` 162264d4e0fSKonstantin Aladyshev 163264d4e0fSKonstantin Aladyshev - Set boot mode: 164f4febd00SPatrick Williams 165264d4e0fSKonstantin Aladyshev ``` 166264d4e0fSKonstantin Aladyshev $ curl -k -H "X-Auth-Token: $token" -H "Content-Type: application/json" -X PUT https://${bmc}/xyz/openbmc_project/control/host0/boot/attr/BootMode -d '{"data": "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular"}' 167264d4e0fSKonstantin Aladyshev ``` 168264d4e0fSKonstantin Aladyshev 169264d4e0fSKonstantin Aladyshev - Set boot type (valid only if host is based on the x86 CPU): 170f4febd00SPatrick Williams 171264d4e0fSKonstantin Aladyshev ``` 172264d4e0fSKonstantin Aladyshev $ curl -k -H "X-Auth-Token: $token" -H "Content-Type: application/json" -X PUT https://${bmc}/xyz/openbmc_project/control/host0/boot/attr/BootType -d '{"data": "xyz.openbmc_project.Control.Boot.Type.Types.EFI"}' 173264d4e0fSKonstantin Aladyshev ``` 174264d4e0fSKonstantin Aladyshev 175264d4e0fSKonstantin Aladyshev - Set boot source override persistent: 176f4febd00SPatrick Williams 177264d4e0fSKonstantin Aladyshev ``` 178264d4e0fSKonstantin Aladyshev $ curl -k -H "X-Auth-Token: $token" -H "Content-Type: application/json" -X PUT https://${bmc}/xyz/openbmc_project/control/host0/boot/one_time/attr/Enabled -d '{"data": "false"}' 179264d4e0fSKonstantin Aladyshev ``` 180264d4e0fSKonstantin Aladyshev 181264d4e0fSKonstantin Aladyshev - Enable boot source override: 182f4febd00SPatrick Williams 183264d4e0fSKonstantin Aladyshev ``` 184264d4e0fSKonstantin Aladyshev $ curl -k -H "X-Auth-Token: $token" -H "Content-Type: application/json" -X PUT https://${bmc}/xyz/openbmc_project/control/host0/boot/attr/Enabled -d '{"data": "true"}' 185f1ee823dSGeorge Keishing ``` 186d2431e93SGeorge Keishing 187f4febd00SPatrick Williams- Set NTP and Nameserver: 1882760941bSGeorge Keishing 1892760941bSGeorge Keishing Examples using public server. 190f4febd00SPatrick Williams 1912760941bSGeorge Keishing - NTP Server: 192f4febd00SPatrick Williams 1932760941bSGeorge Keishing ``` 194b41aff0fSXiaochao Ma $ curl -k -H "X-Auth-Token: $token" -H "Content-Type: application/json" -X PUT -d '{"data": ["pool.ntp.org"] }' https://${bmc}/xyz/openbmc_project/network/eth0/attr/NTPServers 1952760941bSGeorge Keishing ``` 1962760941bSGeorge Keishing 1972760941bSGeorge Keishing - Name Server: 198f4febd00SPatrick Williams 1992760941bSGeorge Keishing ``` 200b41aff0fSXiaochao Ma $ curl -k -H "X-Auth-Token: $token" -H "Content-Type: application/json" -X PUT -d '{"data": ["time.google.com"] }' https://${bmc}/xyz/openbmc_project/network/eth0/attr/Nameservers 2012760941bSGeorge Keishing ``` 202d2431e93SGeorge Keishing 203f4febd00SPatrick Williams- Configure time ownership and time sync method: 204cd429568SAndrew Geissler 205b41aff0fSXiaochao Ma The introduction about time setting is here: 206b41aff0fSXiaochao Ma https://github.com/openbmc/phosphor-time-manager 207cd429568SAndrew Geissler 208f4febd00SPatrick Williams Note: Starting from OpenBMC 2.6 (with systemd v239), systemd's timedated 209f4febd00SPatrick Williams introduces a new beahvior that it checks the NTP services' status during 210f4febd00SPatrick Williams setting time, instead of checking the NTP setting: 211b41aff0fSXiaochao Ma 212f4febd00SPatrick Williams -When NTP server is set to disabled, and the NTP service is stopping but not 213f4febd00SPatrick Williams stopped, setting time will get an error. 214b41aff0fSXiaochao Ma 215f4febd00SPatrick Williams Before OpenBMC 2.4 (with systemd v236), the above will always succeed. This 216f4febd00SPatrick Williams results in 217f4febd00SPatrick Williams [openbmc/openbmc#3459](https://github.com/openbmc/openbmc/issues/3459), and 218f4febd00SPatrick Williams the related test cases are updated to cooperate with this behavior change. 219b41aff0fSXiaochao Ma 220f4febd00SPatrick Williams - Read: 221f4febd00SPatrick Williams 222b41aff0fSXiaochao Ma ``` 223b41aff0fSXiaochao Ma $ curl -k -H "X-Auth-Token: $token" -X GET https://${bmc}/xyz/openbmc_project/time/owner/attr/TimeOwner 224b41aff0fSXiaochao Ma $ curl -k -H "X-Auth-Token: $token" -X GET https://${bmc}/xyz/openbmc_project/time/sync_method/attr/TimeSyncMethod 225b41aff0fSXiaochao Ma ``` 226b41aff0fSXiaochao Ma 227f4febd00SPatrick Williams - Write: 228b41aff0fSXiaochao Ma 229b41aff0fSXiaochao Ma Time owner: 230f4febd00SPatrick Williams 231b41aff0fSXiaochao Ma ``` 232b41aff0fSXiaochao Ma $ curl -k -H "X-Auth-Token: $token" -H "Content-Type: application/json" -X PUT -d '{"data": "xyz.openbmc_project.Time.Owner.Owners.BMC" }' https://${bmc}/xyz/openbmc_project/time/owner/attr/TimeOwner 233b41aff0fSXiaochao Ma $ curl -k -H "X-Auth-Token: $token" -H "Content-Type: application/json" -X PUT -d '{"data": "xyz.openbmc_project.Time.Owner.Owners.Host" }' https://${bmc}/xyz/openbmc_project/time/owner/attr/TimeOwner 234b41aff0fSXiaochao Ma $ curl -k -H "X-Auth-Token: $token" -H "Content-Type: application/json" -X PUT -d '{"data": "xyz.openbmc_project.Time.Owner.Owners.Split" }' https://${bmc}/xyz/openbmc_project/time/owner/attr/TimeOwner 235b41aff0fSXiaochao Ma $ curl -k -H "X-Auth-Token: $token" -H "Content-Type: application/json" -X PUT -d '{"data": "xyz.openbmc_project.Time.Owner.Owners.Both" }' https://${bmc}/xyz/openbmc_project/time/owner/attr/TimeOwner 236b41aff0fSXiaochao Ma ``` 237b41aff0fSXiaochao Ma 238b41aff0fSXiaochao Ma Time sync method: 239f4febd00SPatrick Williams 240b41aff0fSXiaochao Ma ``` 241b41aff0fSXiaochao Ma $ curl -k -H "X-Auth-Token: $token" -H "Content-Type: application/json" -X PUT -d '{"data": "xyz.openbmc_project.Time.Synchronization.Method.NTP" }' https://${bmc}/xyz/openbmc_project/time/sync_method/attr/TimeSyncMethod 242b41aff0fSXiaochao Ma $ curl -k -H "X-Auth-Token: $token" -H "Content-Type: application/json" -X PUT -d '{"data": "xyz.openbmc_project.Time.Synchronization.Method.Manual" }' https://${bmc}/xyz/openbmc_project/time/sync_method/attr/TimeSyncMethod 243cd429568SAndrew Geissler ``` 2442f2b14a3SGeorge Keishing 245f4febd00SPatrick Williams- Power Supply Redundancy: 2462f2b14a3SGeorge Keishing 2472f2b14a3SGeorge Keishing - Read: 248f4febd00SPatrick Williams 2492f2b14a3SGeorge Keishing ``` 250b41aff0fSXiaochao Ma $ curl -k -H "X-Auth-Token: $token" -X GET https://${bmc}/xyz/openbmc_project/control/power_supply_redundancy 2512f2b14a3SGeorge Keishing ``` 2522f2b14a3SGeorge Keishing 2532f2b14a3SGeorge Keishing - Write (Enable/Disable): 254f4febd00SPatrick Williams 2552f2b14a3SGeorge Keishing ``` 256b41aff0fSXiaochao Ma $ curl -k -H "X-Auth-Token: $token" -H "Content-Type: application/json" -X PUT https://${bmc}/xyz/openbmc_project/control/power_supply_redundancy/attr/PowerSupplyRedundancyEnabled -d '{"data": 1}' 257b41aff0fSXiaochao Ma $ curl -k -H "X-Auth-Token: $token" -H "Content-Type: application/json" -X PUT https://${bmc}/xyz/openbmc_project/control/power_supply_redundancy/attr/PowerSupplyRedundancyEnabled -d '{"data": 0}' 258325f4358SGeorge Keishing ``` 259811d3a73SGeorge Keishing 260f4febd00SPatrick Williams- Factory Reset: 261811d3a73SGeorge Keishing 262811d3a73SGeorge Keishing - Factory reset host and BMC software: 263f4febd00SPatrick Williams 264811d3a73SGeorge Keishing ``` 265b41aff0fSXiaochao Ma $ curl -k -H "X-Auth-Token: $token" -H 'Content-Type: application/json' -X POST -d '{"data":[]}' https://${bmc}/xyz/openbmc_project/software/action/Reset 266811d3a73SGeorge Keishing ``` 267811d3a73SGeorge Keishing 268811d3a73SGeorge Keishing - Factory reset network setting: 269f4febd00SPatrick Williams 270811d3a73SGeorge Keishing ``` 271b41aff0fSXiaochao Ma $ curl -k -H "X-Auth-Token: $token" -H 'Content-Type: application/json' -X POST -d '{"data":[]}' https://${bmc}/xyz/openbmc_project/network/action/Reset 272811d3a73SGeorge Keishing ``` 273811d3a73SGeorge Keishing 274811d3a73SGeorge Keishing - Enable field mode: 275f4febd00SPatrick Williams 276811d3a73SGeorge Keishing ``` 277b41aff0fSXiaochao Ma $ curl -k -H "X-Auth-Token: $token" -H 'Content-Type: application/json' -X PUT -d '{"data":1}' https://${bmc}/xyz/openbmc_project/software/attr/FieldModeEnabled 278811d3a73SGeorge Keishing ``` 279f4febd00SPatrick Williams 280811d3a73SGeorge Keishing and then reboot BMC. 281