From 9983689e96789ce60f46b61bd8dc21acc649a973 Mon Sep 17 00:00:00 2001 From: Tino Vazquez Date: Fri, 7 Feb 2014 17:12:17 +0100 Subject: [PATCH] Refactor get pool method from sunstone --- src/sunstone/models/SunstoneServer.rb | 40 ++------------------------- src/sunstone/sunstone-server.rb | 25 ++++++++--------- 2 files changed, 15 insertions(+), 50 deletions(-) diff --git a/src/sunstone/models/SunstoneServer.rb b/src/sunstone/models/SunstoneServer.rb index 54c01110f6..35f2fb58d1 100644 --- a/src/sunstone/models/SunstoneServer.rb +++ b/src/sunstone/models/SunstoneServer.rb @@ -42,43 +42,9 @@ class SunstoneServer < CloudServer ############################################################################ # ############################################################################ - def get_pool(kind,gid) - if gid == "0" - user_flag = Pool::INFO_ALL - else - user_flag = POOL_FILTER - end + def get_pool(kind,gid, client=nil) + client = @client if !client - pool = case kind - when "group" then GroupPoolJSON.new(@client) - when "cluster" then ClusterPoolJSON.new(@client) - when "host" then HostPoolJSON.new(@client) - when "image" then ImagePoolJSON.new(@client, user_flag) - when "vmtemplate" 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) - when "acl" then AclPoolJSON.new(@client) - when "datastore" then DatastorePoolJSON.new(@client) - when "zone" then ZonePoolJSON.new(@client) - else - error = Error.new("Error: #{kind} resource not supported") - return [404, error.to_json] - end - - rc = pool.get_hash - - if OpenNebula.is_error?(rc) - return [500, rc.to_json] - else - return [200, rc.to_json] - end - end - - ############################################################################ - # - ############################################################################ - def get_pool_in_zone(kind,gid,client) if gid == "0" user_flag = Pool::INFO_ALL else @@ -109,7 +75,7 @@ class SunstoneServer < CloudServer else return [200, rc.to_json] end - end + end ############################################################################ # diff --git a/src/sunstone/sunstone-server.rb b/src/sunstone/sunstone-server.rb index 8f4ab4b7d8..2cc48f47dc 100755 --- a/src/sunstone/sunstone-server.rb +++ b/src/sunstone/sunstone-server.rb @@ -405,21 +405,20 @@ end # GET Pool information ############################################################################## get '/:pool' do + zone_client = nil -if params[:zone_id] - zone = OpenNebula::Zone.new_with_id(params[:zone_id].to_i, - $cloud_auth.client(session[:user])) - rc = zone.info - return [500, rc.message] if OpenNebula.is_error?(rc) - zone_client = $cloud_auth.client(session[:user], - zone['TEMPLATE/ENDPOINT']) - @SunstoneServer.get_pool_in_zone(params[:pool], - session[:user_gid], - zone_client) -else - @SunstoneServer.get_pool(params[:pool], session[:user_gid]) -end + if params[:zone_id] + zone = OpenNebula::Zone.new_with_id(params[:zone_id].to_i, + $cloud_auth.client(session[:user])) + rc = zone.info + return [500, rc.message] if OpenNebula.is_error?(rc) + zone_client = $cloud_auth.client(session[:user], + zone['TEMPLATE/ENDPOINT']) + end + @SunstoneServer.get_pool(params[:pool], + session[:user_gid], + zone_client) end ##############################################################################