Hi guys,
I'm trying to create a script to automatically create a VM. I'm using the PVE API to do it. I get a PVE cookie but if I try to use it, I have the following error : HTTP/1.1 401 Permission denied - invalid csrf token.
This is the script I created :
For the moment, I just want to have a connection to my PVE. Afte, I'll create the part to clone the template and edit the new VM.
Just to be clear, I have to create a token ID ? That's correct ?
If someone have an idea, I'm listening to you !
Thanks everyone,
Alex
I'm trying to create a script to automatically create a VM. I'm using the PVE API to do it. I get a PVE cookie but if I try to use it, I have the following error : HTTP/1.1 401 Permission denied - invalid csrf token.
This is the script I created :
Bash:
#echo "Adresse IP : $2"
#echo "Macaddress : $3"
#echo "Hostname : $4"
export NEWID
if [ $1 == 'auth' ]
then
export NEWID=$2
echo "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -"
echo "Requesting an authorization cookie..."
echo > cookie
curl -k -d "username=USER@pam&password=PASSWORD" https://DOMAIN:8006/api2/json/access/ticket | jq --raw-output '.data.ticket' > cookie | sed 's/^/PVEAuthCookie=/' > cookie
echo "Cookie requested !"
cat cookie
echo " "
echo "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -"
echo "Requesting CSRFPreventionToken...."
echo > csrftoken
curl -k -d "username=USER@pam&password=PASSWORD" https://DOMAIN:8006/api2/json/access/ticket | jq --raw-output '.data.CSRFPreventionToken' | sed 's/^/CSRFPreventionToken:/' > csrftoken
echo "CSRFPreventionToken requested !"
cat csrftoken
echo " "
echo "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -"
echo "Informations : "
curl --insecure --cookie "$(<cookie)" https://DOMAIN:8006/api2/json/nodes/NODE/qemu/status | jq '.'
else
export NEWID=$1
fi
echo "Requesting with following parameters :"
echo "Nouvel ID : $1"
echo " "
echo "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -"
echo "Informations : "
curl --insecure --cookie "$(<cookie)" https://DOMAIN:8006/api2/json/nodes/NODE/qemu/status | jq '.'
echo " "
echo "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -"
curl -v -k --cookie "PVEAuthCookie=$(<cookie)" --header "CSRFPreventionToken=$(<csrftoken)" -X POST \
--data name:"VM-Test"\
--data newid:"$NEWID"\
--date node:"NODE"\
https://DOMAIN:8006/api2/json/nodes/NODE/qemu/1000/clone
For the moment, I just want to have a connection to my PVE. Afte, I'll create the part to clone the template and edit the new VM.
Just to be clear, I have to create a token ID ? That's correct ?
If someone have an idea, I'm listening to you !
Thanks everyone,
Alex