edumgui

Proxmox_Connect_VM_Spice

Apr 2nd, 2018
381
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.30 KB | None | 0 0
  1. #!/bin/bash
  2. set -e
  3. # Tested with pve-manager 3.1-44
  4. #In order to connect to Proxmox API we need IP, NODE, user and password
  5. echo "Proxmox IP:"
  6. read PROXY
  7.  
  8. echo "Proxmox Node:"
  9. read NODE
  10.  
  11. echo "Password:"
  12. read -s PASSWORD
  13.  
  14. #Assume we can use default installation user (or ask for another one instead)
  15. USERNAME="root@pam"
  16.  
  17. #Connect to Proxmox API
  18. DATA=$(curl -f -s -S -k -d "username=$USERNAME&password=$PASSWORD"  https://$PROXY:8006/api2/json/access/ticket)
  19.  
  20. echo "AUTH OK"
  21.  
  22. TICKET=${DATA//\"/}
  23. TICKET=${TICKET##*ticket:}
  24. TICKET=${TICKET%%,*}
  25.  
  26. CSRF=${DATA//\"/}
  27. CSRF=${CSRF##*CSRFPreventionToken:}
  28. CSRF=${CSRF%%,*}
  29.  
  30. #Get a list of available VM
  31. curl -f -s -S -k -b "PVEAuthCookie=$TICKET" -H "CSRFPreventionToken: $CSRF" https://$PROXY:8006/api2/json/cluster/resources > resources.txt
  32. cat resources.txt | jq '.data[] | {vmid,name,status}' | jq 'select(.vmid != null)'
  33. echo "Enter the ID of the VM to which you want to connect:"
  34. read VMID
  35.  
  36. #Connect to the selected VM through SPICE
  37. echo "Connecting to the VM $VMID..."
  38. 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
  39.  
  40. #Launch SPICE client with the just downloaded connection file
  41. remote-viewer spiceproxy
Advertisement
Add Comment
Please, Sign In to add comment