Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- set -e
- # Tested with pve-manager 3.1-44
- #In order to connect to Proxmox API we need IP, NODE, user and password
- echo "Proxmox IP:"
- read PROXY
- echo "Proxmox Node:"
- read NODE
- echo "Password:"
- read -s PASSWORD
- #Assume we can use default installation user (or ask for another one instead)
- USERNAME="root@pam"
- #Connect to Proxmox API
- DATA=$(curl -f -s -S -k -d "username=$USERNAME&password=$PASSWORD" https://$PROXY:8006/api2/json/access/ticket)
- echo "AUTH OK"
- TICKET=${DATA//\"/}
- TICKET=${TICKET##*ticket:}
- TICKET=${TICKET%%,*}
- CSRF=${DATA//\"/}
- CSRF=${CSRF##*CSRFPreventionToken:}
- CSRF=${CSRF%%,*}
- #Get a list of available VM
- curl -f -s -S -k -b "PVEAuthCookie=$TICKET" -H "CSRFPreventionToken: $CSRF" https://$PROXY:8006/api2/json/cluster/resources > resources.txt
- cat resources.txt | jq '.data[] | {vmid,name,status}' | jq 'select(.vmid != null)'
- echo "Enter the ID of the VM to which you want to connect:"
- read VMID
- #Connect to the selected VM through SPICE
- echo "Connecting to the VM $VMID..."
- curl -f -s -S -k -b "PVEAuthCookie=$TICKET" -H "CSRFPreventionToken: $CSRF" https://$PROXY:8006/api2/spiceconfig/nodes/$NODE/qemu/$VMID/spiceproxy -d "proxy=$PROXY" > spiceproxy
- #Launch SPICE client with the just downloaded connection file
- remote-viewer spiceproxy
Advertisement
Add Comment
Please, Sign In to add comment