From d10e12f1335492550d558d56c510fdf8ce55a9dc Mon Sep 17 00:00:00 2001
From: "Daniel P. Berrange" <berrange@redhat.com>
Date: Thu, 3 Jan 2013 11:51:42 +0000
Subject: [PATCH] Add support for setting up nova-spicehtml5proxy

Add a new service 'n-spice' which is off by default, but can
be enabled to turn on SPICE support in the Nova libvirt driver.
Also if neither n-novnc or n-xvnc are enabled, then disable
VNC support. This allows running in a SPICE only environment.

The spice-html5 repo will be checked out to support the Horizon
client integration

Change-Id: If74fad33a7b491450afd823758d35b06ebe72cb9
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
---
 files/rpms/n-spice |  1 +
 lib/nova           |  3 ++-
 stack.sh           | 36 +++++++++++++++++++++++++++++++-----
 stackrc            |  4 ++++
 4 files changed, 38 insertions(+), 6 deletions(-)
 create mode 100644 files/rpms/n-spice

diff --git a/files/rpms/n-spice b/files/rpms/n-spice
new file mode 100644
index 0000000000..24ce15ab7e
--- /dev/null
+++ b/files/rpms/n-spice
@@ -0,0 +1 @@
+numpy
diff --git a/lib/nova b/lib/nova
index dd6843215c..ccf93d9ec9 100644
--- a/lib/nova
+++ b/lib/nova
@@ -551,13 +551,14 @@ function start_nova() {
     screen_it n-sch "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-scheduler"
     screen_it n-novnc "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-novncproxy --config-file $NOVA_CONF --web $NOVNC_DIR"
     screen_it n-xvnc "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-xvpvncproxy --config-file $NOVA_CONF"
+    screen_it n-spice "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-spicehtml5proxy --config-file $NOVA_CONF --web $SPICE_DIR"
     screen_it n-cauth "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-consoleauth"
 }
 
 # stop_nova() - Stop running processes (non-screen)
 function stop_nova() {
     # Kill the nova screen windows
-    for serv in n-api n-cpu n-crt n-net n-sch n-novnc n-xvnc n-cauth n-cond; do
+    for serv in n-api n-cpu n-crt n-net n-sch n-novnc n-xvnc n-cauth n-cond n-spice; do
         screen -S $SCREEN_NAME -p $serv -X kill
     done
 }
diff --git a/stack.sh b/stack.sh
index bf473ca7d3..005d88e7b6 100755
--- a/stack.sh
+++ b/stack.sh
@@ -313,6 +313,7 @@ source $TOP_DIR/lib/baremetal
 HORIZON_DIR=$DEST/horizon
 OPENSTACKCLIENT_DIR=$DEST/python-openstackclient
 NOVNC_DIR=$DEST/noVNC
+SPICE_DIR=$DEST/spice-html5
 SWIFT3_DIR=$DEST/swift3
 
 # Should cinder perform secure deletion of volumes?
@@ -716,6 +717,10 @@ if is_service_enabled n-novnc; then
     # a websockets/html5 or flash powered VNC console for vm instances
     git_clone $NOVNC_REPO $NOVNC_DIR $NOVNC_BRANCH
 fi
+if is_service_enabled n-spice; then
+    # a websockets/html5 or flash powered SPICE console for vm instances
+    git_clone $SPICE_REPO $SPICE_DIR $SPICE_BRANCH
+fi
 if is_service_enabled horizon; then
     # dashboard
     install_horizon
@@ -1008,17 +1013,38 @@ if is_service_enabled nova; then
         iniset $NOVA_CONF DEFAULT novncproxy_base_url "$NOVNCPROXY_URL"
         XVPVNCPROXY_URL=${XVPVNCPROXY_URL:-"http://$SERVICE_HOST:6081/console"}
         iniset $NOVA_CONF DEFAULT xvpvncproxy_base_url "$XVPVNCPROXY_URL"
+        SPICEHTML5PROXY_URL=${SPICEHTML5PROXY_URL:-"http://$SERVICE_HOST:6082/spice_auto.html"}
+        iniset $NOVA_CONF spice html5proxy_base_url "$SPICEHTML5PROXY_URL"
     fi
     if [ "$VIRT_DRIVER" = 'xenserver' ]; then
         VNCSERVER_PROXYCLIENT_ADDRESS=${VNCSERVER_PROXYCLIENT_ADDRESS=169.254.0.1}
     else
         VNCSERVER_PROXYCLIENT_ADDRESS=${VNCSERVER_PROXYCLIENT_ADDRESS=127.0.0.1}
     fi
-    # Address on which instance vncservers will listen on compute hosts.
-    # For multi-host, this should be the management ip of the compute host.
-    VNCSERVER_LISTEN=${VNCSERVER_LISTEN=127.0.0.1}
-    iniset $NOVA_CONF DEFAULT vncserver_listen "$VNCSERVER_LISTEN"
-    iniset $NOVA_CONF DEFAULT vncserver_proxyclient_address "$VNCSERVER_PROXYCLIENT_ADDRESS"
+
+    if is_service_enabled n-novnc || is_service_enabled n-xvnc ; then
+      # Address on which instance vncservers will listen on compute hosts.
+      # For multi-host, this should be the management ip of the compute host.
+      VNCSERVER_LISTEN=${VNCSERVER_LISTEN=127.0.0.1}
+      iniset $NOVA_CONF DEFAULT vnc_enabled true
+      iniset $NOVA_CONF DEFAULT vncserver_listen "$VNCSERVER_LISTEN"
+      iniset $NOVA_CONF DEFAULT vncserver_proxyclient_address "$VNCSERVER_PROXYCLIENT_ADDRESS"
+    else
+      iniset $NOVA_CONF DEFAULT vnc_enabled false
+    fi
+
+    if is_service_enabled n-spice; then
+      # Address on which instance spiceservers will listen on compute hosts.
+      # For multi-host, this should be the management ip of the compute host.
+      SPICESERVER_PROXYCLIENT_ADDRESS=${SPICESERVER_PROXYCLIENT_ADDRESS=127.0.0.1}
+      SPICESERVER_LISTEN=${SPICESERVER_LISTEN=127.0.0.1}
+      iniset $NOVA_CONF spice enabled true
+      iniset $NOVA_CONF spice server_listen "$SPICESERVER_LISTEN"
+      iniset $NOVA_CONF spice server_proxyclient_address "$SPICESERVER_PROXYCLIENT_ADDRESS"
+    else
+      iniset $NOVA_CONF spice enabled false
+    fi
+
     iniset $NOVA_CONF DEFAULT ec2_dmz_host "$EC2_DMZ_HOST"
     iniset_rpc_backend nova $NOVA_CONF DEFAULT
     iniset $NOVA_CONF DEFAULT glance_api_servers "$GLANCE_HOSTPORT"
diff --git a/stackrc b/stackrc
index 8d19440587..cfc4d1fb57 100644
--- a/stackrc
+++ b/stackrc
@@ -78,6 +78,10 @@ KEYSTONE_BRANCH=master
 NOVNC_REPO=https://github.com/kanaka/noVNC.git
 NOVNC_BRANCH=master
 
+# a websockets/html5 or flash powered SPICE console for vm instances
+SPICE_REPO=http://anongit.freedesktop.org/git/spice/spice-html5.git
+SPICE_BRANCH=master
+
 # django powered web control panel for openstack
 HORIZON_REPO=${GIT_BASE}/openstack/horizon.git
 HORIZON_BRANCH=master