diff --git a/src/sunstone/models/SunstoneServer.rb b/src/sunstone/models/SunstoneServer.rb index 9892e53b7a..ee4e3160b3 100644 --- a/src/sunstone/models/SunstoneServer.rb +++ b/src/sunstone/models/SunstoneServer.rb @@ -284,6 +284,34 @@ class SunstoneServer < CloudServer return [200, rc.to_json] end + def get_resource_monitoring(id, resource, meters) + pool_element = case resource + when "vm", "VM" + VirtualMachine.new_with_id(id, @client) + when "host", "HOST" + Host.new_with_id(id, @client) + else + error = Error.new("Monitoring not supported for #{resource}") + return [200, error.to_json] + end + + meters_a = meters.split(',') + + rc = pool_element.monitoring(meters_a) + + if OpenNebula.is_error?(rc) + error = Error.new(rc,message) + return [500, error.to_json] + end + + meters_h = Hash.new + meters_h[:resource] = resource + meters_h[:id] = id + meters_h[:monitoring] = rc + + return [200, meters_h.to_json] + end + private ############################################################################ diff --git a/src/sunstone/sunstone-server.rb b/src/sunstone/sunstone-server.rb index 1dbd19c367..2446242618 100755 --- a/src/sunstone/sunstone-server.rb +++ b/src/sunstone/sunstone-server.rb @@ -298,15 +298,12 @@ get '/:resource/monitor' do end get '/:resource/:id/monitor' do - @SunstoneServer.get_monitoring( + @SunstoneServer.get_resource_monitoring( params[:id], params[:resource], - params[:monitor_resources], - :uid => session[:user_id].to_i, - :gid => session[:user_gid].to_i) + params[:monitor_resources]) end - ############################################################################## # GET Pool information ##############################################################################