From 5f3ffac529029ace712121c32d1dd16a9dd08009 Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Tue, 16 Aug 2011 15:17:23 +0200 Subject: [PATCH] feature #720: Update sunstone-server to use the new watch client --- src/sunstone/models/SunstoneServer.rb | 30 +++++++++++++-------------- src/sunstone/sunstone-server.rb | 9 ++++---- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/src/sunstone/models/SunstoneServer.rb b/src/sunstone/models/SunstoneServer.rb index 3aa6b25afc..1547687b75 100644 --- a/src/sunstone/models/SunstoneServer.rb +++ b/src/sunstone/models/SunstoneServer.rb @@ -294,28 +294,26 @@ class SunstoneServer # ############################################################################ - def get_monitoring(id, resource, monitor_resources) - watch_client = OneWatchClient::WatchClient.new - columns = monitor_resources.split(',') - - rc = case resource + def get_monitoring(id, resource, monitor_resources, gid) + watch_client = case resource when "vm","VM" - if id - watch_client.vm_monitoring(id, columns) - else - watch_client.vm_total(columns) - end + OneWatchClient::VmWatchClient.new when "host","HOST" - if id - watch_client.host_monitoring(id, columns) - else - watch_client.host_total(columns) - end + OneWatchClient::HostWatchClient.new else - error = Error.new("Monitoring not supported for this resource: #{resource}") + error = Error.new("Monitoring not supported for this resource: #{resource}") return [200, error.to_json] end + columns = monitor_resources.split(',') + columns.map!{|e| e.to_sym} + + if id + rc = watch_client.resource_monitoring(id.to_i, columns) + else + rc = watch_client.total_monitoring(columns) + end + if rc.nil? error = Error.new("There is no monitoring information for #{resource} #{id}") return [500, error.to_json] diff --git a/src/sunstone/sunstone-server.rb b/src/sunstone/sunstone-server.rb index 6e40ba428e..097b0c0a69 100755 --- a/src/sunstone/sunstone-server.rb +++ b/src/sunstone/sunstone-server.rb @@ -179,14 +179,16 @@ get '/:resource/monitor' do @SunstoneServer.get_monitoring( nil, params[:resource], - params[:monitor_resources]) + params[:monitor_resources], + session[:user_gid]) end get '/:resource/:id/monitor' do @SunstoneServer.get_monitoring( params[:id], params[:resource], - params[:monitor_resources]) + params[:monitor_resources], + session[:user_gid]) end @@ -195,8 +197,7 @@ end ############################################################################## get '/:pool' do @SunstoneServer.get_pool(params[:pool], - session[:user_gid], - settings.config[:pool_filter]) + session[:user_gid]) end ##############################################################################