PXE Boot SPICe

Raymond Burns

Member
Apr 2, 2013
333
1
18
Houston, Texas, United States
I am loving this SPICE adpater.
Is it possible to PXE Boot into SPICE?
Maybe something like booting into the small linux distro, which is severely locked down to Firefox using the SPICE Plugin? Then the computer would essentially boot to fullscreen Firefox, but it would look like PXE Booting into a Virtual Desktop
Any ideas?
I want to build out a computer lab.
 
Hi,

you can use try bash script to launch spice console without firefox

Code:
#!/bin/bash

USERNAME=root@pam
PASSWORD=yourpassword
VMID=198
NODE=proxmoxhost1
PROXY=proxmoxhost1.test.com


TICKET=`curl -k -d "username=$USERNAME&password=$PASSWORD"  https://$PROXY:8006/api2/json/access/ticket | sed 's/\\\\\//\//g' | sed 's/[{}]//g' | awk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}' | sed 's/\"\:\"/\|/g' | sed 's/[\,]/ /g' | sed 's/\"// g' | grep -w ticket |  awk -F "|" '{print $2}'`
echo $TICKET
curl -k -b "PVEAuthCookie=$TICKET" https://$PROXY:8006/api2/spiceconfig/nodes/$NODE/qemu/$VMID/spiceproxy?proxy=$PROXY > spiceproxy
remote-viewer spiceproxy

so, just boot with pxe, startX et launch this script :)
 
Is it possible you can explain this script. I'm not a "bash"er but I know a little PHP. I'm trying to figure my way around it, but I get lost around "sed 's/[{}]//"...
Would you place any args in this script? Example, enable sound in a Windows VM?

Also, what does this open? A virt-viewer? Is there a virt viewer available for Linux? I'm not able to grasp what a GTK is at this point, but is that what I will have to install in Linux?
 
Is it possible you can explain this script. I'm not a "bash"er but I know a little PHP. I'm trying to figure my way around it, but I get lost around "sed 's/[{}]//"...
Would you place any args in this script? Example, enable sound in a Windows VM?

Also, what does this open? A virt-viewer? Is there a virt viewer available for Linux? I'm not able to grasp what a GTK is at this point, but is that what I will have to install in Linux?

Hi, the script connect to proxmox api using login/pass
then parse the json (that's why a lot of sed ;) to get the proxmox session ticket.
the call the api the generate the spice connection file
then launch remote-viewer using spice connection file.

Currently no tunning is availaible in proxmox for client default option, need to be done.

but to enable sound, you just need to add a virtual audio card.
and yes, of course you need virt-viewer/remote-viewer on linux.
(I think you need to read the proxmox wiki about spice)


I'm using archlinux as reference as packages are updated very fast.
 
With this script, is it possible to select a non used VMID within a range. For example, can the script see which VMID between 1001-1020 does not have a SPICE session and use that one.
From my understanding of PXE, the single PXE image would be booted to multiple PC's, however, the same VMID script would love as well, and all PC's would try to connect to the one VMID.
I would either need to locally install the Linux distro in each machine, or have separate PXE images.
OAN: You recommend Archlinux, but it seems pretty UI intensive. I need to lock it down as much as possible to the virt-viewer. I do not want the Public PC's to have access to the desktop or terminal of the clients. Can you lock down Archlinux?
 
With this script, is it possible to select a non used VMID within a range. For example, can the script see which VMID between 1001-1020 does not have a SPICE session and use that one.
From my understanding of PXE, the single PXE image would be booted to multiple PC's, however, the same VMID script would love as well, and all PC's would try to connect to the one VMID.
I would either need to locally install the Linux distro in each machine, or have separate PXE images.
for now, they are no api to find a free/no connected spice vm.
What you can do, is to create 1vm for 1pxe box.
then I think you could with dhcp, set an hostname for each pxe box like = "vmXXXX".
and use in my script $HOSTNAME instead $VMID


OAN: You recommend Archlinux, but it seems pretty UI intensive. I need to lock it down as much as possible to the virt-viewer. I do not want the Public PC's to have access to the desktop or terminal of the clients. Can you lock down Archlinux?

UI intensive ? when you install archlinux, you don't have Xorg installed and no desktop....
So just install Xorg, no desktop, and start directly the bash script.

But distro choice is yours, but keep in mind than a new spice version is release around each 3month.
you can use ubuntu raring, package are enough recent.
fedora19 should be ok too.
debian wheezy is too old.
 
No, I'm going with the recommendation, I was just trying to see if it would be too "expert" for me. I need to do this in baby steps. I go to work sometimes, and can't remember how to spell my name from trying to decipher different code. I'm self taught which is taking it's toll. Just want to be sure I can handle this.
 
I can't figure this out. I have pfSense properly serving DHCP.
I have the configuration right for PXE Booting from IP 10.1.12.55
I have a CentOS installation x64 without startX on IP 10.1.12.55
I have installed XINEtd and some other packages to facilitate PXE Booting.
I have items properly loaded in the /tftpboot directory, and everything seems to run fine.
PXE environment starts without an issue, but ArchLinux will not load. HOW DO I PXE BOOT ARCHLINUX, or do I need ArchLinux to PXE Boot ArchLinux? I cannot figure this out, but I will need this to work, because I want to use older hardware to deploy 45 computers and have all the computers use VM's through Proxmox. This is ideal, I think, but I cannot get past the first part. Getting the machine to PXE Boot. I'm trying to stick with ArchLinux as recommended, but are there any clear and concise instruction to setting up ArchLinux for PXE Booting using a Centos Xinetd PXE Environment?
 
Hit another road block. Not as easy to deploy GNOME within a CentOS container.
I am trying to find a way to boot desktop PC's from Spice enabled VM's. Is there anything or workflow available to me?
Something that is similar to zero-client?
This removes the need to have PC's that are capable of running the OS, and uses the server's resource instead!
 
Another Road Block. I tried to connect using a standard Centos VM with GUI Desktop.
When I run the script, I get an error about "Cannot determine connection type from URI"
Please see attached. I ran the script as is, and replaced the top part with proper password, VMID, node, and proxy. For the proxy, I had to use the IP address because the hostname does not resolve on my network.

If ANYONE CAN HELP PLEASE. I just want to have some zero clients for a lab
spice_attempt.jpg
 
Another Road Block. I tried to connect using a standard Centos VM with GUI Desktop.
When I run the script, I get an error about "Cannot determine connection type from URI"

Check the version of virt-viewer CentOs is using, the required minimum on linux is 0.5.6, otherwise you will get that error.

I ran into the exact same problem on ubuntu 12.10
 
OK.
I have finally succumb to admitting that I may not be smart enough to "figure" this out.
I have a working PXE Boot environment working with CentOS 6 using xinetd, httpd, and tftp-server.

I can't figure out what images to use. I tried to PXE Boot the LiveCD for Fedora, but that was unsuccessful. I don't even know what to download for ArchLinux, and I assume virt-viewer is not optimized for DSL (I don't swear, so it will stay in acronym form).
Please, someone point me in the right direction.

All I want to do is PXE Boot a thinclient into a SPICE VM. I understand this can be achieved with the Bash Script above, but I cannot wrap my head around the image part. I will have a separate SPICE VM for each thinclient, and I plan on using a template VM to build them. I understand the downfalls of all of this, but the benefits much outweigh this.

PLEASE. Any help. This is not Proxmox direct I understand, but I promise to do a wiki writeup and video tutorial on this. This has become the biggest "headache" project I've had. And I've done a lot of custom stuff.
 
I've some solution for init spice via proxmox api (with some help from proxmox forum in parsing api reqests, thanks spirit)
It uses proxmox auth mechanisms. (You'll need user with rights to SINGLE VM)
Scripts will find accessible VM and NODE in cluster or single server environment after auth and run remote-viewer with needed params.

Envireonment:
install: python python-pip remote-viewer
install proxmoxer and requests via pip
install easygui from http://sourceforge.net/projects/easygui/?source=dlp

Authorization GUI writen in Python:
script.py
import re
import urllib2
import subprocess
import getpass
import sys
from proxmoxer import ProxmoxAPI
from easygui import *


msg = "Hello!"
title = "VDI Authorization"
fieldNames = ["User ID", "Password"]
fieldValues = []
fieldValues = multpasswordbox(msg,title, fieldNames)


while 1:
if fieldValues == None: break
errmsg = ""
for i in range(len(fieldNames)):
if fieldValues.strip() == "":
errmsg = errmsg + ('"%s" is a required field.\n\n' % fieldNames)
if errmsg == "": break # no problems found
fieldValues = multpasswordbox(errmsg, title, fieldNames, fieldValues)


USR = fieldValues[0]
PASS = fieldValues[1]
HOST = 'XXX.XXX.XXX.XXX' #IP of pve node
REALM = '@pve' # @pve or @adds.domain
USER = str(USR + REALM)


print (USER + "> > > CONNECTING > > >" + HOST)


proxmox = ProxmoxAPI(HOST, user=USER, password=PASS, verify_ssl=False)
cluster = proxmox.cluster()
print "------------------------------------------------------------------------------"
for node in cluster.resources.get():
tnode = "{0}" .format(node['node'])
ttnode = tnode.replace("node/","")
tvmid = "{0}" .format(node['id'])
ttvmid = tvmid.replace("qemu/", "")
ttvmid = ttvmid.replace("node/", "")
if ttvmid == ttnode:
print ("There is no accessible VM's on " + ttnode)
else:
accvmid = ttvmid
accnode = ttnode
print "------------------------------------------------------------------------------"
print ("Using VM " + accvmid + " on Node " + accnode)
print "------------------------------------------------------------------------------"
print ("Generating SPICE configuration...")


spicerun = ("./spiceinit.h " + HOST + " " + USER + " " + PASS + " " + accnode + " " + accvmid)
print spicerun
subprocess.call(spicerun, shell=True)
subprocess.call("remote-viewer spiceproxy", shell=True)

Bash script:
spiceinit.h
#!/bin/bash -e


USERNAME=$2
PASSWORD=$3
VMID=$5
NODE=$4
PROXY=$1


TICKET=`curl -k -d "username=$USERNAME&password=$PASSWORD" https://$PROXY:8006/api2/json/access/ticket | sed 's/\\\\\//\//g' | sed 's/[{}]//g' | awk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a}' | sed 's/\"\:\"/\|/g' | sed 's/[\,]/ /g' | sed 's/\"// g' | grep -w ticket | awk -F "|" '{print $2}'`
curl -k -b "PVEAuthCookie=$TICKET" https://$PROXY:8006/api2/spiceconfig/nodes/$NODE/qemu/$VMID/spiceproxy?proxy=$PROXY > spiceproxy
echo "fullscreen=1" >> spiceproxy

an at last bash script (start once at each boot):
watcher.sh
#!/bin/bash


while :
do
sleep 1
if ! pgrep remote-viewer > /dev/null
then
clear
( python script.py )
fi
done

WORKS FINE ON FC19/20
 
Last edited:
Hi,

you can use try bash script to launch spice console without firefox

Code:
#!/bin/bash

USERNAME=root@pam
PASSWORD=yourpassword
VMID=198
NODE=proxmoxhost1
PROXY=proxmoxhost1.test.com


TICKET=`curl -k -d "username=$USERNAME&password=$PASSWORD"  https://$PROXY:8006/api2/json/access/ticket | sed 's/\\\\\//\//g' | sed 's/[{}]//g' | awk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}' | sed 's/\"\:\"/\|/g' | sed 's/[\,]/ /g' | sed 's/\"// g' | grep -w ticket |  awk -F "|" '{print $2}'`
echo $TICKET
curl -k -b "PVEAuthCookie=$TICKET" https://$PROXY:8006/api2/spiceconfig/nodes/$NODE/qemu/$VMID/spiceproxy?proxy=$PROXY > spiceproxy
remote-viewer spiceproxy

so, just boot with pxe, startX et launch this script :)
Trying this but can't get to work it out. When changing the 2nd curl command from spiceconfig to json then all I get is {data:null} as response. The 1st command works and the ticket looks right, but I get no spice configuration. I can bring it to work with the pvesh and with the php client (https://github.com/CpuID/pve2-api-php-client) but not some more simple way. Maybe some1 has a hint?
 
Trying this but can't get to work it out. When changing the 2nd curl command from spiceconfig to json then all I get is {data:null} as response. The 1st command works and the ticket looks right, but I get no spice configuration. I can bring it to work with the pvesh and with the php client (https://github.com/CpuID/pve2-api-php-client) but not some more simple way. Maybe some1 has a hint?

there were some changes in pve API.
I've got it working some months ago.
look in that direction
 
Hi all,
I'm trying to implement a spice vdi thin client starting from your hints and scripts. I'm stuck at the very end of my script calling remote-viewer.
remote-viewer accept a ini-formatted config file while pve api returns a json formatted file.
I tried to edit json file with some sed before calling remote-viewer, but I always receive "** invalid file" error from remote-viewer.
There's a lot of escaped \n in the json, I tried to fix them too, but the result is always the same.
What can I do?

Thanks,
Luigi
 
I tried to work with this in php. That script here

<?php
require("pve2_api.class.php");

$pve2 = new PVE2_API("proxmox.example.net", "root", "pam", "qwertz");
# realm above can be pve, pam or any other realm available.

if ($pve2->constructor_success()) {
/* Optional - enable debugging. It print()'s any results currently */
// $pve2->set_debug(true);

if ($pve2->login()) {
$result = $pve2->post("/nodes/proxmox/qemu/101/spiceproxy","proxy=192.168.11.2");

$myFile = "phpspiceproxy.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
fwrite($fh,"[virt-viewer]\r\n");
foreach ($result as $key => $data) {
fwrite($fh, $key."=".$data."\r\n");
}
fclose($fh);

} else {
print("Login to Proxmox Host failed.\n");
exit;
}
} else {
print("Could not create PVE2_API object.\n");
exit;
}
?>

run fine and produced me ühüsüiceproxy.txt file which I could open seamlessly with "remote-viewer phpspiceproxy.txt".

Hope this helps you fixing your problem. We came to the conclusion (2015) that there is no "free" 3D acceleration support and surfing to all the flash websites didn't worked out well. We sticked with fat clients till now.
 
Thanks!
I commented "if ($pve2->constructor_success())..." if statement to get it work.
This is the useful part:
fwrite($fh,"[virt-viewer]\r\n");
foreach ($result as $key => $data) {
fwrite($fh, $key."=".$data."\r\n");
I was trying to do with sed in my bash script.

Luigi
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!