Skip to content

Instantly share code, notes, and snippets.

@williamcaban
Last active November 19, 2023 04:20
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save williamcaban/5ae3fa9302e421e3bb5c8b82fb1db5f1 to your computer and use it in GitHub Desktop.
Save williamcaban/5ae3fa9302e421e3bb5c8b82fb1db5f1 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -euoE pipefail
# Redfish commands related to Virtual Media.
# Redfish doc reference: https://www.supermicro.com/manuals/other/RedfishRefGuide.pdf
export BMC_ADDRESS=''
export ISO_IMAGE=http://192.168.117.9:8080/ocp4-rwn-1-small.iso
export username_password='Administrator:superuser'
REDFISH_PATH=$( curl -sku ${username_password} https://$BMC_ADDRESS/redfish/v1/Systems | jq '.Members[0]."@odata.id"' )
"/redfish/v1/Systems/Self"
server_secureboot_delete_keys() {
curl --globoff -L -w "%{http_code} %{url_effective}\\n" -ku ${username_password} \
-H "Content-Type: application/json" -H "Accept: application/json" \
-d '{"ResetKeysType":"DeleteAllKeys"}' \
-X POST https://$BMC_ADDRESS/redfish/v1/Systems/Self/SecureBoot/Actions/SecureBoot.ResetKeys
}
server_get_bios_config(){
# Retrieve BIOS config over Redfish
curl -sku ${username_password} https://$BMC_ADDRESS/redfish/v1/Systems/Self/Bios
}
server_restart() {
# Restart
curl --globoff -L -w "%{http_code} %{url_effective}\\n" -ku ${username_password} \
-H "Content-Type: application/json" -H "Accept: application/json" \
-d '{"ResetType": "ForceRestart"}' \
-X POST https://$BMC_ADDRESS/redfish/v1/Systems/Self/Actions/ComputerSystem.Reset
}
server_power_off() {
# Power off
curl --globoff -L -w "%{http_code} %{url_effective}\\n" -ku ${username_password} \
-H "Content-Type: application/json" -H "Accept: application/json" \
-d '{"ResetType": "ForceOff"}' -X POST https://$BMC_ADDRESS/redfish/v1/Systems/Self/Actions/ComputerSystem.Reset
}
server_power_on() {
# Power on
curl --globoff -L -w "%{http_code} %{url_effective}\\n" -ku ${username_password} \
-H "Content-Type: application/json" -H "Accept: application/json" \
-d '{"ResetType": "On"}' -X POST https://$BMC_ADDRESS/redfish/v1/Systems/Self/Actions/ComputerSystem.Reset
}
server_virtual_media_eject() {
# Eject Media
curl --globoff -L -w "%{http_code} %{url_effective}\\n" -ku ${username_password} \
-H "Content-Type: application/json" -H "Accept: application/json" \
-d '{}' -X POST https://$BMC_ADDRESS/redfish/v1/Managers/Self/VirtualMedia/1/Actions/VirtualMedia.EjectMedia
}
server_virtual_media_status(){
# Media Status
curl -s --globoff -H "Content-Type: application/json" -H "Accept: application/json" \
-k -X GET --user ${username_password} \
https://$BMC_ADDRESS/redfish/v1/Managers/Self/VirtualMedia/1 | jq '.MediaStatus'
}
server_virtual_media_insert(){
# Insert Media from http server and iso file
curl --globoff -L -w "%{http_code} %{url_effective}\\n" -ku ${username_password} \
-H "Content-Type: application/json" -H "Accept: application/json" \
-d '{"Image": "$ISO_IMAGE"}' \
-X POST https://$BMC_ADDRESS/redfish/v1/Managers/Self/VirtualMedia/1/Actions/VirtualMedia.InsertMedia
}
server_set_boot_once_from_cd() {
# Set boot order
curl --globoff -L -w "%{http_code} %{url_effective}\\n" -ku ${username_password} \
-H "Content-Type: application/json" -H "Accept: application/json" \
-d '{"Boot":{ "BootSourceOverrideEnabled": "Once", "BootSourceOverrideTarget": "Cd", "BootSourceOverrideMode": "UEFI"}}' \
-X PATCH http://$BMC_ADDRESS/redfish/v1/Systems/Self
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment