mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-21 14:50:08 +03:00
Feature #924: Update Sunstone server to use the new logging system
(cherry picked from commit 7b05c9af6a99bb6414a9cd780f559940c0222205)
This commit is contained in:
parent
26c7333de6
commit
e0f95f9a4b
@ -14,6 +14,8 @@
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
require 'CloudServer'
|
||||
|
||||
require 'OpenNebulaJSON'
|
||||
include OpenNebulaJSON
|
||||
|
||||
@ -22,14 +24,15 @@ require 'OpenNebulaVNC'
|
||||
require 'OpenNebulaJSON/JSONUtils'
|
||||
include JSONUtils
|
||||
|
||||
class SunstoneServer
|
||||
class SunstoneServer < CloudServer
|
||||
# FLAG that will filter the elements retrieved from the Pools
|
||||
POOL_FILTER = Pool::INFO_ALL
|
||||
|
||||
# Secs to sleep between checks to see if image upload to repo is finished
|
||||
IMAGE_POLL_SLEEP_TIME = 5
|
||||
|
||||
def initialize(client)
|
||||
def initialize(client, config, logger)
|
||||
super(config, logger)
|
||||
@client = client
|
||||
end
|
||||
|
||||
@ -194,7 +197,8 @@ class SunstoneServer
|
||||
begin
|
||||
log = File.read(vm_log_file)
|
||||
rescue Exception => e
|
||||
return [200, "Log for VM #{id} not available"]
|
||||
msg = "Log for VM #{id} not available"
|
||||
return [200, {:vm_log => msg}.to_json]
|
||||
end
|
||||
|
||||
return [200, {:vm_log => log}.to_json]
|
||||
@ -210,7 +214,7 @@ class SunstoneServer
|
||||
return [404, resource.to_json]
|
||||
end
|
||||
|
||||
vnc_proxy = OpenNebulaVNC.new(config)
|
||||
vnc_proxy = OpenNebulaVNC.new(config, logger)
|
||||
return vnc_proxy.start(resource)
|
||||
end
|
||||
|
||||
@ -221,7 +225,8 @@ class SunstoneServer
|
||||
begin
|
||||
OpenNebulaVNC.stop(pipe)
|
||||
rescue Exception => e
|
||||
error = Error.new(e.message)
|
||||
logger.error {e.message}
|
||||
error = Error.new("Error stopping VNC. Please check server logs.")
|
||||
return [500, error.to_json]
|
||||
end
|
||||
|
||||
|
@ -32,6 +32,7 @@ else
|
||||
end
|
||||
|
||||
SUNSTONE_AUTH = VAR_LOCATION + "/.one/sunstone_auth"
|
||||
SUNSTONE_LOG = VAR_LOCATION + "/sunstone.log"
|
||||
CONFIGURATION_FILE = ETC_LOCATION + "/sunstone-server.conf"
|
||||
PLUGIN_CONFIGURATION_FILE = ETC_LOCATION + "/sunstone-plugins.yaml"
|
||||
|
||||
@ -54,27 +55,42 @@ require 'CloudAuth'
|
||||
require 'SunstoneServer'
|
||||
require 'SunstonePlugins'
|
||||
|
||||
|
||||
##############################################################################
|
||||
# Configuration
|
||||
##############################################################################
|
||||
|
||||
begin
|
||||
conf = YAML.load_file(CONFIGURATION_FILE)
|
||||
rescue Exception => e
|
||||
puts "Error parsing config file #{CONFIGURATION_FILE}: #{e.message}"
|
||||
STDERR.puts "Error parsing config file #{CONFIGURATION_FILE}: #{e.message}"
|
||||
exit 1
|
||||
end
|
||||
|
||||
##############################################################################
|
||||
# Sinatra Configuration
|
||||
##############################################################################
|
||||
use Rack::Session::Pool, :key => 'sunstone'
|
||||
conf[:debug_level] ||= 3
|
||||
|
||||
CloudServer.print_configuration(conf)
|
||||
|
||||
#Sinatra configuration
|
||||
|
||||
set :config, conf
|
||||
set :bind, settings.config[:host]
|
||||
set :port, settings.config[:port]
|
||||
|
||||
use Rack::Session::Pool, :key => 'sunstone'
|
||||
|
||||
# Enable logger
|
||||
|
||||
include CloudLogger
|
||||
enable_logging SUNSTONE_LOG, settings.config[:debug_level].to_i
|
||||
|
||||
begin
|
||||
ENV["ONE_CIPHER_AUTH"] = SUNSTONE_AUTH
|
||||
cloud_auth = CloudAuth.new(settings.config)
|
||||
rescue => e
|
||||
puts "Error initializing authentication system"
|
||||
puts e.message
|
||||
settings.logger.error {
|
||||
"Error initializing authentication system" }
|
||||
settings.logger.error { e.message }
|
||||
exit -1
|
||||
end
|
||||
|
||||
@ -93,10 +109,12 @@ helpers do
|
||||
settings.cloud_auth.update_userpool_cache
|
||||
result = settings.cloud_auth.auth(request.env, params)
|
||||
rescue Exception => e
|
||||
error 500, e.message
|
||||
error 500, ""
|
||||
logger.error { e.message }
|
||||
end
|
||||
|
||||
if result.nil?
|
||||
logger.info { "Unauthorized login attempt" }
|
||||
return [401, ""]
|
||||
else
|
||||
client = settings.cloud_auth.client(result)
|
||||
@ -105,7 +123,7 @@ helpers do
|
||||
user = OpenNebula::User.new_with_id(user_id, client)
|
||||
rc = user.info
|
||||
if OpenNebula.is_error?(rc)
|
||||
# Add a log message
|
||||
logger.error { rc.message }
|
||||
return [500, ""]
|
||||
end
|
||||
|
||||
@ -157,7 +175,9 @@ before do
|
||||
halt 401 unless authorized?
|
||||
|
||||
@SunstoneServer = SunstoneServer.new(
|
||||
settings.cloud_auth.client(session[:user]))
|
||||
settings.cloud_auth.client(session[:user]),
|
||||
settings.config,
|
||||
settings.logger)
|
||||
end
|
||||
end
|
||||
|
||||
@ -244,7 +264,10 @@ end
|
||||
post '/config' do
|
||||
begin
|
||||
body = JSON.parse(request.body.read)
|
||||
rescue
|
||||
rescue Exception => e
|
||||
msg = "Error parsing configuration JSON"
|
||||
logger.error { msg }
|
||||
logger.error { e.message }
|
||||
[500, OpenNebula::Error.new(msg).to_json]
|
||||
end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user