From 8ecc77cd78652d9d7c4215e8811932c3acf9e17e Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Mon, 13 Feb 2012 18:23:05 +0100 Subject: [PATCH] feature #1076: UI configuration returned as XML --- src/cloud/occi/etc/occi-server.conf | 4 +-- src/cloud/occi/lib/OCCIServer.rb | 13 ++++----- src/cloud/occi/lib/occi-server.rb | 44 +++++++++++++++-------------- 3 files changed, 31 insertions(+), 30 deletions(-) diff --git a/src/cloud/occi/etc/occi-server.conf b/src/cloud/occi/etc/occi-server.conf index 90ea4df134..7d42afbf3d 100644 --- a/src/cloud/occi/etc/occi-server.conf +++ b/src/cloud/occi/etc/occi-server.conf @@ -52,9 +52,8 @@ :cpu: 8 :memory: 8192 - ############################################################# -### SelfService UI Settings +# OCCI UI Settings (SelfService) ############################################################# # Default language setting @@ -70,6 +69,7 @@ # vnc_proxy_cert: Certificate to encrypt wss connections. # vnc_proxy_key: Key for wss connections. Only necessary if not included in cert. :vnc_enable: no + :vnc_proxy_base_port: 33876 :vnc_proxy_path: :vnc_proxy_support_wss: no diff --git a/src/cloud/occi/lib/OCCIServer.rb b/src/cloud/occi/lib/OCCIServer.rb index 12035fe18a..f762fe1fbc 100755 --- a/src/cloud/occi/lib/OCCIServer.rb +++ b/src/cloud/occi/lib/OCCIServer.rb @@ -512,15 +512,13 @@ class OCCIServer < CloudServer ############################################################################ def startvnc(id,config) - vm = VirtualMachineOCCI.new( - VirtualMachine.build_xml(id), - @client) - + vm = VirtualMachineOCCI.new(VirtualMachine.build_xml(id), @client) rc = vm.info + if OpenNebula.is_error?(rc) - error = "Error starting VNC session, " - error += "could not retrieve Virtual Machine" - return [404,error] + error = "Error starting VNC session, " + error << "could not retrieve Virtual Machine" + return [404, error] end vnc_proxy = OpenNebulaVNC.new(config,{:json_errors => false}) @@ -533,6 +531,7 @@ class OCCIServer < CloudServer rescue Exception => e return [500, e.message] end + return [200,nil] end end diff --git a/src/cloud/occi/lib/occi-server.rb b/src/cloud/occi/lib/occi-server.rb index b64016525d..047fe55cad 100755 --- a/src/cloud/occi/lib/occi-server.rb +++ b/src/cloud/occi/lib/occi-server.rb @@ -306,19 +306,22 @@ get '/user/:id' do end ############################################## -## UI +## OCCI UI (Self-Service) ############################################## -get '/ui/config/:opt' do - case params[:opt] - when "lang" then session[:lang] - when "wss" - wss = settings.config[:vnc_proxy_support_wss] - wss = (wss == true || wss == "yes" || wss == "only" ? "yes" : "no") - return wss - when "vnc" then settings.config[:vnc_enable] ? "yes" : "no" - else [404, "Unknown configuration option"] - end +get '/ui/config' do + wss = settings.config[:vnc_proxy_support_wss] + wss = (wss == true || wss == "yes" || wss == "only" ? "yes" : "no") + + vnc = settings.config[:vnc_enable] ? "yes" : "no" + + config = "" + config << " #{session[:lang]}" + congig << " #{wss}" + congig << " #{vnc}" + config << "" + + return [200, config] end post '/ui/config' do @@ -333,6 +336,7 @@ post '/ui/config' do when "lang" then session[:lang]=value end end + return 200 end @@ -374,12 +378,11 @@ post '/ui/startvnc/:id' do return [403, "VNC sessions are disabled"] end - vm_id = params[:id] - + vm_id = params[:id] vnc_hash = session['vnc'] if !vnc_hash - session['vnc']= {} + session['vnc'] = {} elsif vnc_hash[vm_id] #return existing information info = vnc_hash[vm_id].clone @@ -395,10 +398,10 @@ post '/ui/startvnc/:id' do session['vnc'][vm_id] = info.clone info.delete(:pipe) - [200, info.to_json] - else - rc + rc = [200, info.to_json] end + + return rc end post '/ui/stopvnc/:id' do @@ -406,12 +409,11 @@ post '/ui/stopvnc/:id' do return [403, "VNC sessions are disabled"] end - vm_id = params[:id] + vm_id = params[:id] vnc_hash = session['vnc'] if !vnc_hash || !vnc_hash[vm_id] - msg = "It seems there is no VNC proxy running for this machine" - return [403, msg] + return [403, "It seems there is no VNC proxy running for this machine"] end rc = @occi_server.stopvnc(vnc_hash[vm_id][:pipe]) @@ -420,5 +422,5 @@ post '/ui/stopvnc/:id' do session['vnc'].delete(vm_id) end - rc + return rc end