diff --git a/install.sh b/install.sh
index 5e6c35f8b2..4745ea55ec 100755
--- a/install.sh
+++ b/install.sh
@@ -1518,6 +1518,7 @@ SUNSTONE_MODELS_JSON_FILES="src/sunstone/models/OpenNebulaJSON/HostJSON.rb \
SUNSTONE_VIEWS_FILES="src/sunstone/views/index.erb \
src/sunstone/views/login.erb \
src/sunstone/views/vnc.erb \
+ src/sunstone/views/spice.erb \
src/sunstone/views/_login_standard.erb \
src/sunstone/views/_login_x509.erb"
diff --git a/src/sunstone/OpenNebulaVNC.rb b/src/sunstone/OpenNebulaVNC.rb
index c6c76768fa..9f04a48e6c 100644
--- a/src/sunstone/OpenNebulaVNC.rb
+++ b/src/sunstone/OpenNebulaVNC.rb
@@ -167,7 +167,7 @@ class OpenNebulaVNC
end
if vm_resource['TEMPLATE/GRAPHICS/TYPE'].nil? ||
- vm_resource['TEMPLATE/GRAPHICS/TYPE'].downcase != "vnc"
+ !(["vnc", "spice"].include?(vm_resource['TEMPLATE/GRAPHICS/TYPE'].downcase))
return error(400,"VM has no VNC configured")
end
diff --git a/src/sunstone/public/js/plugins/vms-tab.js b/src/sunstone/public/js/plugins/vms-tab.js
index 42caab052d..cd53f22db0 100644
--- a/src/sunstone/public/js/plugins/vms-tab.js
+++ b/src/sunstone/public/js/plugins/vms-tab.js
@@ -193,6 +193,7 @@ var $create_vm_dialog;
var $deploy_vm_dialog;
var $migrate_vm_dialog;
var $vnc_dialog;
+var $spice_dialog;
var rfb;
var vm_actions = {
@@ -549,6 +550,17 @@ var vm_actions = {
notify: true
},
+ "VM.startspice_action" : {
+ type: "single",
+ call: OpenNebula.VM.startvnc,
+ callback: spiceCallback,
+ error: function(req, resp){
+ onError(req, resp);
+ spice_lock = false;
+ },
+ notify: true
+ },
+
"VM.monitor" : {
type: "monitor",
call : OpenNebula.VM.monitor,
@@ -3026,6 +3038,58 @@ function setupVNC(){
});
}
+
+//setups VNC application
+function setupSPICE(){
+
+ //Append to DOM
+ dialogs_context.append('
');
+ $spice_dialog = $('#spice_dialog',dialogs_context);
+ var dialog = $spice_dialog;
+
+ dialog.html('\
+ \
+ \
+ ×\
+');
+
+ dialog.addClass("reveal-modal large max-height").attr("data-reveal", "");
+
+ $spice_dialog.foundation();
+
+ $("#open_in_a_new_window_spice", dialog).on("click", function(){
+ $spice_dialog.foundation('reveal', 'close');
+ });
+
+ $('.spice').live("click",function(){
+ var id = $(this).attr('vm_id');
+
+ //Ask server for connection params
+ if (!vnc_lock) {
+ spice_lock = true
+ Sunstone.runAction("VM.startspice_action",id);
+ return false;
+ } else {
+ notifyError(tr("SPICE Connection in progress"))
+ return false;
+ }
+ });
+}
+
// Open vnc window
function popUpVnc(){
$.each(getSelectedNodes(dataTable_vMachines), function(index, elem) {
@@ -3073,6 +3137,78 @@ function vncCallback(request,response){
});
}
+function spiceCallback(request,response){
+ var host = null, port = null;
+ var sc;
+
+ function spice_error(e) {
+ disconnect();
+ }
+
+ function disconnect() {
+ if (sc) {
+ sc.stop();
+ }
+ }
+
+ function agent_connected(sc)
+ {
+ window.addEventListener('resize', handle_resize);
+ window.spice_connection = this;
+
+ resize_helper(this);
+ }
+
+ var host, port, password, scheme = "ws://", uri, token, vm_name;
+
+ if (config['user_config']['vnc_wss'] == "yes") {
+ scheme = "wss://";
+ }
+
+ host = window.location.hostname;
+ port = config['system_config']['vnc_proxy_port'];
+ password = response["password"];
+ token = response["token"];
+ vm_name = response["vm_name"];
+
+ if ((!host) || (!port)) {
+ console.log("must specify host and port in URL");
+ return;
+ }
+
+ if (sc) {
+ sc.stop();
+ }
+
+ uri = scheme + host + ":" + port + "?token=" + token;
+
+ try {
+ sc = new SpiceMainConn({uri: uri, screen_id: "spice-screen", dump_id: "debug-div",
+ message_id: "", password: password, onerror: spice_error, onagent: agent_connected });
+ }
+ catch (e) {
+ alert(e.toString());
+ disconnect();
+ }
+
+ var url = "spice?";
+ url += "host=" + host;
+ url += "&port=" + port;
+ url += "&token=" + token;
+ url += "&password=" + password;
+ url += "&encrypt=" + config['user_config']['vnc_wss'];
+ url += "&title=" + vm_name;
+
+ $("#open_in_a_new_window_spice").attr('href', url)
+ $spice_dialog.foundation("reveal", "open");
+ spice_lock = false;
+
+ $spice_dialog.off("closed");
+ $spice_dialog.on("closed", function () {
+ disconnect();
+ });
+}
+
// returns true if the vnc button should be enabled
function enableVnc(vm){
var graphics = vm.TEMPLATE.GRAPHICS;
@@ -3080,7 +3216,17 @@ function enableVnc(vm){
return (graphics &&
graphics.TYPE &&
- graphics.TYPE.toLowerCase() == "vnc" &&
+ graphics.TYPE.toLowerCase() == "vnc" &&
+ $.inArray(state, VNCstates)!=-1);
+}
+
+function enableSPICE(vm){
+ var graphics = vm.TEMPLATE.GRAPHICS;
+ var state = OpenNebula.Helper.resource_state("vm_lcm",vm.LCM_STATE);
+
+ return (graphics &&
+ graphics.TYPE &&
+ graphics.TYPE.toLowerCase() == "spice" &&
$.inArray(state, VNCstates)!=-1);
}
@@ -3091,6 +3237,10 @@ function vncIcon(vm){
gr_icon = '';
gr_icon += '';
}
+ else if (enableSPICE(vm)){
+ gr_icon = '';
+ gr_icon += '';
+ }
else {
gr_icon = '';
}
@@ -3138,6 +3288,7 @@ $(document).ready(function(){
Sunstone.runAction("VM.list");
setupVNC();
+ setupSPICE();
hotpluggingOps();
setup_vm_network_tab();
setup_vm_capacity_tab();
diff --git a/src/sunstone/sunstone-server.rb b/src/sunstone/sunstone-server.rb
index f0f6614463..11df8bfcfb 100755
--- a/src/sunstone/sunstone-server.rb
+++ b/src/sunstone/sunstone-server.rb
@@ -277,7 +277,7 @@ before do
@request_body = request.body.read
request.body.rewind
- unless %w(/ /login /vnc).include?(request.path)
+ unless %w(/ /login /vnc /spice).include?(request.path)
halt 401 unless authorized? && valid_csrftoken?
end
@@ -354,6 +354,15 @@ get '/vnc' do
end
end
+get '/spice' do
+ content_type 'text/html', :charset => 'utf-8'
+ if !authorized?
+ erb :login
+ else
+ erb :spice
+ end
+end
+
##############################################################################
# Login
##############################################################################
diff --git a/src/sunstone/views/index.erb b/src/sunstone/views/index.erb
index 37d2968d0a..18643e3ae7 100644
--- a/src/sunstone/views/index.erb
+++ b/src/sunstone/views/index.erb
@@ -39,6 +39,36 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
<% if session[:lang] %>
<% end %>
diff --git a/src/sunstone/views/spice.erb b/src/sunstone/views/spice.erb
new file mode 100644
index 0000000000..68f707a2c7
--- /dev/null
+++ b/src/sunstone/views/spice.erb
@@ -0,0 +1,182 @@
+
+
+
+
+
+
+ Spice Javascript client
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ SPICE
+
+
+
+
+
+
+
+
+
+
+
+