###redfish https://github.com/openbmc/docs/blob/master/REDFISH-cheatsheet.md ##https://developer.hpe.com/blog/managing-ilo-sessions-with-redfish/ #json init yum install jq -y export bmcip=192.168.1.40 export bmc=https://${bmcip}/redfish/v1/ export username=admin export password='admin@123' export session="{\"UserName\":\"$username\", \"Password\":\"$password\"}" echo $session #Establish Redfish connection session export token=`curl -k -D - -H "Content-Type: application/json" -X POST ${bmc}SessionService/Sessions -d "${session}" | grep "X-Auth-Token: " | awk '{print $2;}' | tr -d '[:space:]'` echo ${token} #View sessions curl -k -H "X-Auth-Token: ${token}" -X GET ${bmc}SessionService/Sessions | jq #View Redfish Objects curl -k -H "X-Auth-Token: ${token}" -X GET ${bmc}Systems/1 | jq curl -k -H "X-Auth-Token: ${token}" -X GET ${bmc}Chassis/1 | jq curl -k -H "X-Auth-Token: ${token}" -X GET ${bmc}Managers/1 | jq #Bios cpu等 curl -k -H "X-Auth-Token: ${token}" -X GET ${bmc}Systems/1/Bios | jq curl -k -H "X-Auth-Token: ${token}" -X GET ${bmc}Systems/1/Processors/1 | jq curl -k -H "X-Auth-Token: ${token}" -X GET ${bmc}Systems/1/Memory | jq curl -k -H "X-Auth-Token: ${token}" -X GET ${bmc}Systems/1/Storages | jq #Host soft power off on reboot curl -k -H "X-Auth-Token: ${token}" -H "Content-Type: application/json" -X POST ${bmc}Systems/system/Actions/ComputerSystem.Reset -d '{"ResetType": "GracefulShutdown"}' curl -k -H "X-Auth-Token: ${token}" -H "Content-Type: application/json" -X POST ${bmc}Systems/system/Actions/ComputerSystem.Reset -d '{"ResetType": "On"}' curl -k -H "X-Auth-Token: ${token}" -H "Content-Type: application/json" -X POST ${bmc}Systems/system/Actions/ComputerSystem.Reset -d '{"ResetType": "GracefulRestart"}' #Boot选项 单次Legacy模式启动PXE一次 #Disabled:不生效 Once:仅生效一次,即下次重启时生效 Continuous:永久有效 export ifmatch=`curl -k -I -H "X-Auth-Token:${token}" -H "Content-Type: application/json" -X GET ${bmc}Systems/1 | grep -i ETag: | awk '{print $2;}' | tr -d '[:space:]'` curl -k -H "X-Auth-Token:${token}" -H "Content-Type: application/json" -H "If-Match: ${ifmatch}" -X PATCH ${bmc}Systems/1 -d '{"BootSourceOverrideMode": "Legacy","BootSourceOverrideTarget": "Pxe","BootSourceOverrideEnabled": "Once"}' |jq #Update "root" password curl -k -H "X-Auth-Token: ${token}" -H "Content-Type: application/json" -X PATCH -d '{"Password": "0penBmc1"}' ${bmc}AccountService/Accounts/root ###https://cloudcult.dev/fishing-for-sushy-with-curl/ #挂载iso url -d \ '{"Image":"'"$ISO_URL"'", "Inserted": true}' \ -H "Content-Type: application/json" \ -X POST \ http://$REDFISH_HOST:$REDFISH_PORT/redfish/v1/Managers/$REDFISH_MANAGER/VirtualMedia/Cd/Actions/VirtualMedia.InsertMedia #RAID curl -k --location --request POST -d "{\"Oem\":{\"Public\":{\"OptimumIOSizeBytes\":65536, \"VolumeName\":\"1\",\"VolumeRaidLevel\":\"RAID0\", \"InitializationMode\": \"UnInit\", \"DriveCachePolicy\":\"Unchanged\", \"DefaultReadPolicy\": \"ReadAhead\", \"DefaultWritePolicy\": \"WriteBack\", \"DefaultCachePolicy\": \"DirectIO\", \"AccessPolicy\":\"ReadWrite\", \"spanDepth\":1, \"SpanNumber\":1, \"Drives\":[0]}}}" https://10.41.183.31/redfish/v1/Systems/1/Storages/RAIDStorage0/Volumes --header "Content-Type: application/json" --header "if-Match: *" --header "Authorization: Basic YWRtaW46YWRtaW4=" #cpu curl -kL -u admin:admin@123 https://192.168.1.40/redfish/v1/Systems/Self/Processors/DevType1_CPU0 | jq #memory curl -kL -u admin:admin@123 https://192.168.1.40/redfish/v1/Systems/Self/Memory/JDIMM1 | jq ###power #!/usr/bin/env bash HOST="192.168.1.40" USER="admin" PASS="admin@123" PSU_LIST=$(curl -ks -u "${USER}:${PASS}" \ "https://${HOST}/redfish/v1/Chassis/Self/PowerSubsystem/PowerSupplies") printf '%s\n' "${PSU_LIST}" | jq -r '.Members[]."@odata.id"' | xargs -I{} curl -ks -u "${USER}:${PASS}" "https://${HOST}{}" | jq -r ' "=== PSU " + .Id + " ===", "Id=" + .Id, "Name=" + .Name, "Manufacturer=" + (.Manufacturer // "N/A"), "Model=" + (.Model // "N/A"), "SN=" + (.SerialNumber // "N/A"), "Firmware=" + (.FirmwareVersion // "N/A"), "Status=" + (.PowerSupplyStatus // "N/A"), "MaxRated=" + (.MaxRatedOutputPower | tostring) + "W", "Input=" + (.InputVoltage | tostring) + "V @" + (.InputCurrent | tostring) + "A " + (.InputPower | tostring) + "W", "Output=" + (.OutputVoltage | tostring) + "V @" + (.OutputCurrent | tostring) + "A " + (.OutputPower | tostring) + "W", "Fan1=" + (.FanRotationSpeedRPM_1 | tostring) + " RPM", "Fan2=" + (.FanRotationSpeedRPM_2 | tostring) + " RPM", "Temp1=" + (.TemperatureReadingsCelsius_1 | tostring) + "°C", "Temp2=" + (.TemperatureReadingsCelsius_2 | tostring) + "°C", ""' # curl -ks -u "${USER}:${PASS}" "https://${HOST}/redfish/v1/Systems/Self" | jq -r 'to_entries[] | select(.value | type == "object" and ."@odata.id") | .value."@odata.id"' curl -ks -u "${USER}:${PASS}" "https://${HOST}/redfish/v1/Systems/Self/Bios" | jq /redfish/v1/Systems/Self/EthernetInterfaces /redfish/v1/Systems/Self/GraphicsControllers /redfish/v1/Systems/Self/LogServices /redfish/v1/Systems/Self/Memory /redfish/v1/Systems/Self/MemoryDomains /redfish/v1/Systems/Self/NetworkInterfaces /redfish/v1/Systems/Self/Processors /redfish/v1/Systems/Self/SecureBoot /redfish/v1/Systems/Self/SimpleStorage /redfish/v1/Systems/Self/Storage /redfish/v1/Systems/Self/USBControllers curl -ks -u "${USER}:${PASS}" "https://${HOST}/redfish/v1/Systems/Self/BootOptions " | jq