Skip to content

Redfish

# [optional] view the session service
curl -k 'https://172.27.47.51/redfish/v1/SessionService' --user "foo:bar"
# [optional] change the default session timeout
curl -k --request PATCH 'https://172.27.47.51/redfish/v1/SessionService' --user "foo:bar" --data '{"SessionTimeout": 360}'

# Fetch token, and check the headers.txt(X-Auth-Token)
curl -k --request POST -D /tmp/headers.txt 'https://172.27.47.51/redfish/v1/SessionService/Sessions' --data '{"UserName":"foo","Password":"bar"}'

# Virtual ISO mount
curl -k --request POST -H "X-Auth-Token: gbrfixxdhz3dpsm5woot1e7qbg73fbjq" 'https://172.31.35.186/redfish/v1/Managers/1/VirtualMedia/CD1/Actions/VirtualMedia.InsertMedia' --data '{"Image": "http://172.31.58.225/ISO/ubuntu-22.04.4-live-server-amd64.iso"}'
# unmount
curl -k --request POST -H "X-Auth-Token: gbrfixxdhz3dpsm5woot1e7qbg73fbjq" 'https://172.31.35.186/redfish/v1/Managers/1/VirtualMedia/CD1/Actions/VirtualMedia.EjectMedia' --data '{}'

# Boot Options: USB
curl -k --request PATCH -H "X-Auth-Token: gbrfixxdhz3dpsm5woot1e7qbg73fbjq" 'https://172.27.47.51/redfish/v1/Systems/1' --data '{"Boot":{"BootSourceOverrideEnabled":"Once","BootSourceOverrideMode":"UEFI","BootSourceOverrideTarget":"Usb"}}'

# Boot Options: HDD, Once
curl -k --request PATCH -H "X-Auth-Token: gbrfixxdhz3dpsm5woot1e7qbg73fbjq" 'https://172.27.47.51/redfish/v1/Systems/1' --data '{"Boot":{"BootSourceOverrideEnabled":"Once","BootSourceOverrideMode":"UEFI","BootSourceOverrideTarget":"Hdd"}}'

# Boot Options: Virtual ISO, Once
## https://www.supermicro.com/manuals/other/redfish-ref-guide-html/Content/general-content/bios-configuration.htm?Highlight=BootSourceOverrideTarget
## notes: "BootSourceOverrideTarget":"Cd" is not working
curl -k --request PATCH -H "X-Auth-Token: 39mhmi6mhwv5g0nygfjkmu97e683tv4c" 'https://172.24.118.167/redfish/v1/Systems/1' --data '{"Boot":{"BootSourceOverrideEnabled":"Once","BootSourceOverrideMode":"Legacy","BootSourceOverrideTarget":"UsbCd"}}'
curl -k --request PATCH -H "X-Auth-Token: ruvmm17i0xqgh1b8sm9ho3sf0zk1f0n1" 'https://172.24.118.167/redfish/v1/Systems/1' --data '{"Boot":{"BootSourceOverrideEnabled":"Once","BootSourceOverrideMode":"UEFI","BootSourceOverrideTarget":"UsbCd"}}'

# Boot Options: Pxe, Once
curl -k --request PATCH -H "X-Auth-Token: ruvmm17i0xqgh1b8sm9ho3sf0zk1f0n1" 'https://172.24.118.167/redfish/v1/Systems/1' --data '{"Boot":{"BootSourceOverrideEnabled":"Once","BootSourceOverrideMode":"UEFI","BootSourceOverrideTarget":"Pxe"}}' | python3 -m json.tool
curl -k --request PATCH 'https://172.24.118.167/redfish/v1/Systems/1' --user "foo:bar" --data '{"Boot":{"BootSourceOverrideEnabled":"Once","BootSourceOverrideMode":"UEFI","BootSourceOverrideTarget":"Pxe"}}' | python3 -m json.tool

# Boot Options: HDD, Continuous
curl -k --request PATCH -H "$(cat /tmp/headers.txt | grep X-Auth-Token | dos2unix)" 'https://172.27.47.51/redfish/v1/Systems/1' --data '{"Boot":{"BootSourceOverrideEnabled":"Continuous","BootSourceOverrideMode":"UEFI","BootSourceOverrideTarget":"Hdd"}}'


# Update BIOS firmware
curl -k -i -X POST \
   -H "Authorization:Basic U01DSTpTdXBlcjEyMw==" \
   -H "Content-Type:multipart/form-data" \
   -F "UpdateParameters={\"Targets\": [\"/redfish/v1/Systems/1/Bios\"],\"@Redfish.OperationApplyTime\": \"Immediate\",\"Oem\": {\"Supermicro\": { \"BIOS\": { \"PreserveME\": true, \"PreserveNVRAM\": true, \"PreserveSMBIOS\": true, \"BackupBIOS\": false }}}};type=application/json" \
   -F "UpdateFile=@\"/tmp/BIOS_BH12SSi-1B8F_20240131_2.8_STDsp.bin\";type=application/octet-stream" \
 'https://172.31.34.164/redfish/v1/UpdateService/upload'

# Update BMC firmware
curl -k -i -X POST \
   -H "Authorization:Basic U01DSTpTdXBlcjEyMw==" \
   -H "Content-Type:multipart/form-data" \
   -F "UpdateParameters={\"Targets\": [\"/redfish/v1/Managers/1\"],\"@Redfish.OperationApplyTime\": \"Immediate\",\"Oem\": {\"Supermicro\": { \"BMC\": { \"PreserveCfg\": true, \"PreserveSdr\": true, \"PreserveSsl\": true, \"BackupBMC\": true }}}};type=application/json" \
   -F "UpdateFile=@\"/tmp/BMC_B12AST2500-ROT-1201MS_20240210_01.04.12_STDsp.bin\";type=application/octet-stream" \
 'https://172.31.34.164/redfish/v1/UpdateService/upload'

# reset
curl -k --request POST -H "X-Auth-Token: gbrfixxdhz3dpsm5woot1e7qbg73fbjq" 'https://172.27.47.51/redfish/v1/Systems/1/Actions/ComputerSystem.Reset' --data '{"ResetType": "GracefulRestart"}' | python3 -m json.tool

The values are allowed to set BootSourceOverrideTarget - BootSourceOVerRideMode: UEFI - Pxe - Cd - Usb - Hdd - BootSourceOVerRideMode: Legacy - None - Pxe - Cd - Floppy - Usb - Hdd - BiosSetup - UsbCd - UefiBootNext

mount and change the virtual iso, as well as reboot

#! /bin/bash

REPO_SERVER=172.31.58.225
ISO=ubuntu-22.04.4-live-server-amd64.iso

read -p "Enter BMC Host: " BMC_HOST
read -p "Enter BMC Account: " ACCOUNT
read -s -p "Enter BMC Password: " PASSWORD
curl -v -k --request POST -D /tmp/headers.txt  "https://${BMC_HOST}/redfish/v1/SessionService/Sessions" --data "{\"UserName\":\"${ACCOUNT}\",\"Password\":\"${PASSWORD}\"}"

TOKEN=$(cat /tmp/headers.txt | grep X-Auth-Token | dos2unix)
echo "Mount ${ISO} on ${BMC_HOST} by token ${TOKEN} and reboot"
curl -v -k --request POST -H "${TOKEN}" "https://${BMC_HOST}/redfish/v1/Managers/1/VirtualMedia/CD1/Actions/VirtualMedia.InsertMedia" --data "{\"Image\": \"http:\/\/${REPO_SERVER}\/ISO\/${ISO}\"}"
curl -v -k --request PATCH -H "${TOKEN}" "https://${BMC_HOST}/redfish/v1/Systems/1" --data '{"Boot":{"BootSourceOverrideEnabled":"Once","BootSourceOverrideMode":"UEFI","BootSourceOverrideTarget":"UsbCd"}}'
#curl -v -k --request POST -H "${TOKEN}" "https://${BMC_HOST}/redfish/v1/Systems/1/Actions/ComputerSystem.Reset" --data '{"ResetType": "GracefulRestart"}'