From 4c739e9d79d5300d16a1bf267641a5499beeadda Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Thu, 4 Aug 2011 13:49:03 +0200 Subject: [PATCH] feature #763: Add configuration parameter to Sunstone; list group or mine (FILTER_POOL) --- src/sunstone/etc/sunstone-server.conf | 4 ++++ src/sunstone/models/SunstoneServer.rb | 26 ++++++++++++++++---------- src/sunstone/sunstone-server.rb | 14 ++++++++------ 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/src/sunstone/etc/sunstone-server.conf b/src/sunstone/etc/sunstone-server.conf index a1d8b64246..76b5d7d24e 100644 --- a/src/sunstone/etc/sunstone-server.conf +++ b/src/sunstone/etc/sunstone-server.conf @@ -6,3 +6,7 @@ PORT=9869 VNC_PROXY_BASE_PORT=29876 NOVNC_PATH= +# FLAG that will filter the elements retrieved from the Pools +# MINE : Connected user's resources +# GROUP : Connected user's and his group's resources +POOL_FILTER = "GROUP" \ No newline at end of file diff --git a/src/sunstone/models/SunstoneServer.rb b/src/sunstone/models/SunstoneServer.rb index f1cec51f60..3aa6b25afc 100644 --- a/src/sunstone/models/SunstoneServer.rb +++ b/src/sunstone/models/SunstoneServer.rb @@ -56,25 +56,31 @@ class SunstoneServer ############################################################################ # ############################################################################ - def get_pool(kind,gid) + def get_pool(kind,gid,filter) + if gid == "0" + user_flag = Pool::INFO_ALL + else + user_flag = case filter + when "MINE" then Pool::INFO_MINE + when "GROUP" then Pool::INFO_GROUP + else Pool::INFO_GROUP + end + end + pool = case kind when "group" then GroupPoolJSON.new(@client) when "host" then HostPoolJSON.new(@client) - when "image" then ImagePoolJSON.new(@client) - when "template" then TemplatePoolJSON.new(@client) - when "vm" then VirtualMachinePoolJSON.new(@client) - when "vnet" then VirtualNetworkPoolJSON.new(@client) + when "image" then ImagePoolJSON.new(@client, user_flag) + when "template" then TemplatePoolJSON.new(@client, user_flag) + when "vm" then VirtualMachinePoolJSON.new(@client, user_flag) + when "vnet" then VirtualNetworkPoolJSON.new(@client, user_flag) when "user" then UserPoolJSON.new(@client) else error = Error.new("Error: #{kind} resource not supported") return [404, error.to_json] end - rc = case kind - when "group","host","user" then pool.info - else - gid != "0" ? pool.info_group : pool.info_all - end + rc = pool.info if OpenNebula.is_error?(rc) return [500, rc.to_json] diff --git a/src/sunstone/sunstone-server.rb b/src/sunstone/sunstone-server.rb index cadc3eaad2..07e5600533 100755 --- a/src/sunstone/sunstone-server.rb +++ b/src/sunstone/sunstone-server.rb @@ -183,16 +183,14 @@ get '/:resource/monitor' do @SunstoneServer.get_monitoring( nil, params[:resource], - params[:monitor_resources] - ) + params[:monitor_resources]) end get '/:resource/:id/monitor' do @SunstoneServer.get_monitoring( params[:id], params[:resource], - params[:monitor_resources] - ) + params[:monitor_resources]) end @@ -200,7 +198,9 @@ end # GET Pool information ############################################################################## get '/:pool' do - @SunstoneServer.get_pool(params[:pool],session[:user_gid]) + @SunstoneServer.get_pool(params[:pool], + session[:user_gid], + settings.config[:pool_filter]) end ############################################################################## @@ -283,5 +283,7 @@ end # Perform an action on a Resource ############################################################################## post '/:resource/:id/action' do - @SunstoneServer.perform_action(params[:resource], params[:id], request.body.read) + @SunstoneServer.perform_action(params[:resource], + params[:id], + request.body.read) end