vm_control_init

This commit is contained in:
mmaster 2019-08-31 21:41:33 +02:00
commit dc7e235922
1 changed files with 52 additions and 0 deletions

52
vm_control.sh Normal file
View File

@ -0,0 +1,52 @@
#!/bin/sh
USERNAME="$1"
PASSWORD="$2"
REALM="$3"
TARGET_VMID="$4"
HOST="https://vmsrv01.viewanime.net"
NODE="proxmox"
JQ=$(which jq)
if [ -z "$JQ" ]; then
echo "Please install jq!"; exit 0
fi
CURL=$(which curl)
if [ -z "$CURL" ]; then
echo "Please install curl!"; exit 0
fi
if [ "$5" = "current" ]; then
TARGET_ACTION="$5"
elif [ "$5" = "reset" ]; then
TARGET_ACTION="$5"
elif [ "$5" = "resume" ]; then
TARGET_ACTION="$5"
elif [ "$5" = "shutdown" ]; then
TARGET_ACTION="$5"
elif [ "$5" = "start" ]; then
TARGET_ACTION="$5"
elif [ "$5" = "stop" ]; then
TARGET_ACTION="$5"
elif [ "$5" = "suspend" ]; then
TARGET_ACTION="$5"
fi
OUTPUT=$($CURL -s -k -d "username=$USERNAME@$REALM&password=$PASSWORD" "$HOST/api2/json/access/ticket")
TICKET=$(echo "$OUTPUT" | jq -r '.data | .ticket')
CSRF=$(echo "$OUTPUT" | jq -r '.data | .CSRFPreventionToken')
START_TASK_DATA=$($CURL -s -k -b "PVEAuthCookie=$TICKET" -H "CSRFPreventionToken: $CSRF" -X POST $HOST/api2/json/nodes/$NODE/qemu/$TARGET_VMID/status/$TARGET_ACTION)
echo "$START_TASK_DATA" | $JQ