Skip to content

Commit

Permalink
add user definable SESSION_0_QUTSELECT_PVE_VMACTION checking and
Browse files Browse the repository at this point in the history
execution
  • Loading branch information
jens-maus committed Nov 19, 2024
1 parent 991418e commit 640106a
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions scripts/qutselect_connect_pve.sh
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,34 @@ if [[ -z "${VMID}" ]] || [[ -z "${VMNODE}" ]] || [[ -z "${VMSTATUS}" ]] || [[ -z
fi

#####
# START VM (if not running yet)
if [[ ${VMSTATUS} == "stopped" ]]; then
echo "WARNING: VM not running. Trying to start"
RESPONSE=$(curl -L -d "" -f -s -S -k -b "PVEAuthCookie=${TICKET}" -H "CSRFPreventionToken: ${CSRF}" "https://${VMNODE}:8006/api2/json/nodes/${VMNODE}/${VMTYPE}/${VMID}/status/start")
# Perform VMACTION based on SESSION_0_QUTSELECT_PVE_VMACTION (default: start)
if [[ -z "${SESSION_0_QUTSELECT_PVE_VMACTION}" ]]; then # start is default
if [[ ${VMSTATUS} == "stopped" ]]; then
VMACTION=start
elif [[ ${VMSTATUS} == "paused" ]]; then
VMACTION=resume
fi
else
VMACTION=${SESSION_0_QUTSELECT_PVE_VMACTION}
fi

# if "ignore" do nothing
if [[ ${VMACTION} == "ignore" ]]; then
VMACTION=
elif [[ ${VMACTION} == "reboot" ]] ||
[[ ${VMACTION} == "reset" ]] ||
[[ ${VMACTION} == "resume" ]]; then

# if VM is stopped start the VM instead
if [[ ${VMSTATUS} == "stopped" ]]; then
VMACTION=start
fi
fi

# perform VMACTION
if [[ -n "${VMACTION}" ]]; then
echo "INFO: Trying to ${VMACTION} VM ${VMID}..."
RESPONSE=$(curl -L -d "" -f -s -S -k -b "PVEAuthCookie=${TICKET}" -H "CSRFPreventionToken: ${CSRF}" "https://${VMNODE}:8006/api2/json/nodes/${VMNODE}/${VMTYPE}/${VMID}/status/${VMACTION}")
echo "Waiting 10 seconds before trying Spice connection ..."
sleep 10
fi
Expand Down

0 comments on commit 640106a

Please sign in to comment.