Some checks failed
Test / test (push) Has been cancelled
Co-authored-by: Cursor <cursoragent@cursor.com>
125 lines
3.2 KiB
Bash
Executable File
125 lines
3.2 KiB
Bash
Executable File
#!/bin/bash
|
|
source ~/.bashrc
|
|
# Set Boot Order via API - Alternative method
|
|
|
|
set -e
|
|
|
|
# Colors
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
BLUE='\033[0;34m'
|
|
NC='\033[0m'
|
|
|
|
log_info() {
|
|
echo -e "${GREEN}[INFO]${NC} $1"
|
|
}
|
|
|
|
log_step() {
|
|
echo -e "${BLUE}[STEP]${NC} $1"
|
|
}
|
|
|
|
# Load environment variables
|
|
if [ -f .env ]; then
|
|
set -a
|
|
source <(grep -v '^#' .env | grep -v '^$' | sed 's/#.*$//' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//' | grep '=')
|
|
set +a
|
|
fi
|
|
|
|
PVE_USERNAME="${PVE_USERNAME:-root@pam}"
|
|
PVE_PASSWORD="${PVE_ROOT_PASS:-}"
|
|
PROXMOX_URL="https://192.168.1.206:8006"
|
|
PROXMOX_NODE="pve"
|
|
|
|
# Get authentication ticket
|
|
get_ticket() {
|
|
local response=$(curl -k -s -d "username=$PVE_USERNAME&password=$PVE_PASSWORD" \
|
|
"$PROXMOX_URL/api2/json/access/ticket")
|
|
|
|
local ticket=$(echo "$response" | grep -o '"ticket":"[^"]*' | cut -d'"' -f4)
|
|
local csrf=$(echo "$response" | grep -o '"CSRFPreventionToken":"[^"]*' | cut -d'"' -f4)
|
|
|
|
if [ -z "$ticket" ] || [ -z "$csrf" ]; then
|
|
return 1
|
|
fi
|
|
|
|
echo "$ticket|$csrf"
|
|
}
|
|
|
|
# Set boot order via API
|
|
set_boot_order() {
|
|
local auth=$1
|
|
local vmid=$2
|
|
|
|
local ticket=$(echo "$auth" | cut -d'|' -f1)
|
|
local csrf=$(echo "$auth" | cut -d'|' -f2)
|
|
|
|
log_step "Setting boot order for VM $vmid..."
|
|
|
|
# Try different boot order formats
|
|
# Format 1: boot=order=ide2;scsi0
|
|
log_info "Trying boot order: ide2;scsi0"
|
|
local response1=$(curl -k -s -X PUT \
|
|
-H "Cookie: PVEAuthCookie=$ticket" \
|
|
-H "CSRFPreventionToken: $csrf" \
|
|
-d "boot=order=ide2;scsi0" \
|
|
"$PROXMOX_URL/api2/json/nodes/$PROXMOX_NODE/qemu/$vmid/config" 2>&1)
|
|
|
|
if ! echo "$response1" | grep -q '"errors"'; then
|
|
log_info "✓ Boot order set successfully"
|
|
return 0
|
|
fi
|
|
|
|
# Format 2: boot=order=ide2
|
|
log_info "Trying boot order: ide2"
|
|
local response2=$(curl -k -s -X PUT \
|
|
-H "Cookie: PVEAuthCookie=$ticket" \
|
|
-H "CSRFPreventionToken: $csrf" \
|
|
-d "boot=order=ide2" \
|
|
"$PROXMOX_URL/api2/json/nodes/$PROXMOX_NODE/qemu/$vmid/config" 2>&1)
|
|
|
|
if ! echo "$response2" | grep -q '"errors"'; then
|
|
log_info "✓ Boot order set successfully"
|
|
return 0
|
|
fi
|
|
|
|
# Format 3: bootdisk=ide2
|
|
log_info "Trying bootdisk: ide2"
|
|
local response3=$(curl -k -s -X PUT \
|
|
-H "Cookie: PVEAuthCookie=$ticket" \
|
|
-H "CSRFPreventionToken: $csrf" \
|
|
-d "bootdisk=ide2" \
|
|
"$PROXMOX_URL/api2/json/nodes/$PROXMOX_NODE/qemu/$vmid/config" 2>&1)
|
|
|
|
if ! echo "$response3" | grep -q '"errors"'; then
|
|
log_info "✓ Boot disk set successfully"
|
|
return 0
|
|
fi
|
|
|
|
log_info "⚠ API method didn't work. Use Web UI method below."
|
|
return 1
|
|
}
|
|
|
|
main() {
|
|
echo "========================================="
|
|
echo "Set Boot Order via API"
|
|
echo "========================================="
|
|
echo ""
|
|
|
|
auth=$(get_ticket)
|
|
if [ $? -ne 0 ]; then
|
|
echo "Authentication failed"
|
|
exit 1
|
|
fi
|
|
|
|
for vmid in 100 101 102 103; do
|
|
set_boot_order "$auth" "$vmid"
|
|
echo ""
|
|
done
|
|
|
|
echo "If API didn't work, use Web UI method:"
|
|
echo " Options tab → Boot Order → Use 'order' field"
|
|
}
|
|
|
|
main "$@"
|
|
|