Commit 5e27326e authored by Vitaly Lipatov's avatar Vitaly Lipatov

pve: add pve-console.sh to open SPICE console to a VM

Generates a one-time .vv file via PVE spiceproxy API and launches remote-viewer. Uses short hostname for proxy and includes host-subject as required for TLS. VMs only (qemu), must be running. Co-Authored-By: 's avatarClaude Opus 4.7 (1M context) <noreply@anthropic.com>
parent e4ff65bc
#!/bin/sh
# Open SPICE console to a PVE VM
# Usage: pve-console.sh VMID [--display DISPLAY]
#
# Requires: remote-viewer, jq
# Generates a .vv file and opens it with remote-viewer.
set -e
MYDIR=$(dirname "$0")
. "$MYDIR/functions"
VMID=""
DISPLAY_NUM="${DISPLAY:-:0.0}"
while [ $# -gt 0 ] ; do
case "$1" in
--display) DISPLAY_NUM="$2" ; shift 2 ;;
--help|-h)
echo "Usage: $(basename "$0") VMID [--display DISPLAY]"
echo "Open SPICE console to a PVE VM."
exit 0
;;
-*) fatal "unknown option: $1" ;;
*) VMID="$1" ; shift ;;
esac
done
if [ -z "$VMID" ] ; then
echo "Usage: $(basename "$0") VMID [--display DISPLAY]" >&2
exit 1
fi
resolve_vmid "$VMID"
if [ "$RES_TYPE" != "qemu" ] ; then
fatal "SPICE console is only available for VMs (qemu), not $RES_TYPE"
fi
if [ "$RES_STATUS" != "running" ] ; then
fatal "VM $VMID ($RES_NAME) is $RES_STATUS — must be running for SPICE"
fi
log "Getting SPICE proxy data for VM $VMID ($RES_NAME) on $RES_NODE ..."
DATA=$(ssh "root@$RES_NODE" "pvesh create /nodes/$RES_NODE/qemu/$VMID/spiceproxy --proxy gefest.office.etersoft.ru --output-format=json") \
|| fatal "cannot get SPICE proxy data"
VV_DIR="$HOME/tmp/claude"
mkdir -p "$VV_DIR"
VV_FILE="$VV_DIR/pve-$VMID.vv"
# Build .vv file
# CRITICAL: proxy must use short hostname (gefest, not FQDN)
# CRITICAL: host-subject is required for TLS
cat > "$VV_FILE" << EOF
[virt-viewer]
password=$(echo "$DATA" | jq -r '.password')
host=$(echo "$DATA" | jq -r '.host')
toggle-fullscreen=Shift+F11
secure-attention=Ctrl+Alt+Ins
release-cursor=Ctrl+Alt+R
title=$(echo "$DATA" | jq -r '.title')
delete-this-file=0
host-subject=$(echo "$DATA" | jq -r '.["host-subject"]')
ca=$(echo "$DATA" | jq -r '.ca')
proxy=http://gefest:3128
tls-port=$(echo "$DATA" | jq -r '.["tls-port"]')
type=spice
EOF
log "Opening SPICE console ..."
DISPLAY="$DISPLAY_NUM" remote-viewer "$VV_FILE"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment