mirror of
https://github.com/OpenNebula/one.git
synced 2025-01-14 19:24:10 +03:00
Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
536cc1634a
@ -1079,8 +1079,7 @@ ETC_CLIENT_FILES="src/cli/etc/group.default"
|
||||
# Sunstone files
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
SUNSTONE_FILES="src/sunstone/config.ru \
|
||||
src/sunstone/sunstone-server.rb \
|
||||
SUNSTONE_FILES="src/sunstone/sunstone-server.rb \
|
||||
src/sunstone/OpenNebulaVNC.rb"
|
||||
|
||||
SUNSTONE_BIN_FILES="src/sunstone/bin/sunstone-server"
|
||||
@ -1225,8 +1224,7 @@ src/sunstone/public/locale/ru/ru_datatable.txt"
|
||||
# Ozones files
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
OZONES_FILES="src/ozones/Server/config.ru \
|
||||
src/ozones/Server/ozones-server.rb"
|
||||
OZONES_FILES="src/ozones/Server/ozones-server.rb"
|
||||
|
||||
OZONES_BIN_FILES="src/ozones/Server/bin/ozones-server"
|
||||
|
||||
|
@ -39,11 +39,12 @@ class CloudAuth
|
||||
# Tokens will be generated if time > EXPIRE_TIME - EXPIRE_MARGIN
|
||||
EXPIRE_MARGIN = 300
|
||||
|
||||
attr_reader :client, :token
|
||||
attr_reader :client, :token, :logger
|
||||
|
||||
# conf a hash with the configuration attributes as symbols
|
||||
def initialize(conf)
|
||||
def initialize(conf, logger=nil)
|
||||
@conf = conf
|
||||
@logger = logger
|
||||
|
||||
@token_expiration_time = Time.now.to_i + EXPIRE_DELTA
|
||||
|
||||
|
@ -37,7 +37,7 @@ class CloudServer
|
||||
##########################################################################
|
||||
# Public attributes
|
||||
##########################################################################
|
||||
attr_reader :config
|
||||
attr_reader :config, :logger
|
||||
|
||||
# Initializes the Cloud server based on a config file
|
||||
# config_file:: _String_ for the server. MUST include the following
|
||||
@ -45,9 +45,10 @@ class CloudServer
|
||||
# AUTH
|
||||
# VM_TYPE
|
||||
# XMLRPC
|
||||
def initialize(config)
|
||||
def initialize(config, logger=nil)
|
||||
# --- Load the Cloud Server configuration file ---
|
||||
@config = config
|
||||
@logger = logger
|
||||
end
|
||||
#
|
||||
# Prints the configuration of the server
|
||||
@ -82,3 +83,54 @@ class CloudServer
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
module CloudLogger
|
||||
require 'logger'
|
||||
|
||||
DEBUG_LEVEL = [
|
||||
Logger::ERROR, # 0
|
||||
Logger::WARN, # 1
|
||||
Logger::INFO, # 2
|
||||
Logger::DEBUG # 3
|
||||
]
|
||||
|
||||
# Mon Feb 27 06:02:30 2012 [Clo] [E]: Error message example
|
||||
MSG_FORMAT = %{%s [%s]: %s\n}
|
||||
|
||||
# Mon Feb 27 06:02:30 2012
|
||||
DATE_FORMAT = "%a %b %d %H:%M:%S %Y"
|
||||
|
||||
# Patch logger class to be compatible with Rack::CommonLogger
|
||||
class ::Logger
|
||||
def write(msg)
|
||||
info msg.chop
|
||||
end
|
||||
end
|
||||
|
||||
def enable_logging(path=nil, debug_level=3)
|
||||
path ||= $stdout
|
||||
logger = ::Logger.new(path)
|
||||
logger.level = DEBUG_LEVEL[debug_level]
|
||||
logger.formatter = proc do |severity, datetime, progname, msg|
|
||||
MSG_FORMAT % [
|
||||
datetime.strftime(DATE_FORMAT),
|
||||
severity[0..0],
|
||||
msg ]
|
||||
end
|
||||
|
||||
# Add the logger instance to the Sinatra settings
|
||||
set :logger, logger
|
||||
|
||||
# The logging will be configured in Rack, not in Sinatra
|
||||
disable :logging
|
||||
|
||||
# Use the logger instance in the Rack methods
|
||||
use Rack::CommonLogger, logger
|
||||
|
||||
helpers do
|
||||
def logger
|
||||
settings.logger
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -34,6 +34,9 @@
|
||||
# x509, for x509 certificate encryption of tokens
|
||||
:core_auth: cipher
|
||||
|
||||
# 0 = ERROR, 1 = WARNING, 2 = INFO, 3 = DEBUG
|
||||
:debug_level: 3
|
||||
|
||||
# VM types allowed and its template file (inside templates directory)
|
||||
:instance_types:
|
||||
:m1.small:
|
||||
|
@ -61,8 +61,8 @@ class EC2QueryServer < CloudServer
|
||||
|
||||
###########################################################################
|
||||
|
||||
def initialize(client, config)
|
||||
super(config)
|
||||
def initialize(client, config, logger)
|
||||
super(config, logger)
|
||||
|
||||
@client = client
|
||||
end
|
||||
|
@ -20,19 +20,23 @@
|
||||
ONE_LOCATION=ENV["ONE_LOCATION"]
|
||||
|
||||
if !ONE_LOCATION
|
||||
RUBY_LIB_LOCATION = "/usr/lib/one/ruby"
|
||||
LOG_LOCATION = "/var/log/one"
|
||||
VAR_LOCATION = "/var/lib/one"
|
||||
CONFIGURATION_FILE = "/etc/one/econe.conf"
|
||||
TEMPLATE_LOCATION = "/etc/one/ec2query_templates"
|
||||
ETC_LOCATION = "/etc/one"
|
||||
RUBY_LIB_LOCATION = "/usr/lib/one/ruby"
|
||||
else
|
||||
RUBY_LIB_LOCATION = ONE_LOCATION+"/lib/ruby"
|
||||
VAR_LOCATION = ONE_LOCATION+"/var"
|
||||
CONFIGURATION_FILE = ONE_LOCATION+"/etc/econe.conf"
|
||||
TEMPLATE_LOCATION = ONE_LOCATION+"/etc/ec2query_templates"
|
||||
VAR_LOCATION = ONE_LOCATION + "/var"
|
||||
LOG_LOCATION = ONE_LOCATION + "/var"
|
||||
ETC_LOCATION = ONE_LOCATION + "/etc"
|
||||
RUBY_LIB_LOCATION = ONE_LOCATION+"/lib/ruby"
|
||||
end
|
||||
|
||||
VIEWS_LOCATION = RUBY_LIB_LOCATION + "/cloud/econe/views"
|
||||
EC2_AUTH = VAR_LOCATION + "/.one/ec2_auth"
|
||||
EC2_AUTH = VAR_LOCATION + "/.one/ec2_auth"
|
||||
EC2_LOG = LOG_LOCATION + "/econe-server.log"
|
||||
CONFIGURATION_FILE = ETC_LOCATION + "/occi-server.conf"
|
||||
|
||||
TEMPLATE_LOCATION = ETC_LOCATION + "/occi_templates"
|
||||
VIEWS_LOCATION = RUBY_LIB_LOCATION + "/cloud/econe/views"
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << RUBY_LIB_LOCATION+"/cloud"
|
||||
@ -57,12 +61,13 @@ include OpenNebula
|
||||
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
|
||||
|
||||
conf[:template_location] = TEMPLATE_LOCATION
|
||||
conf[:views] = VIEWS_LOCATION
|
||||
conf[:debug_level] ||= 3
|
||||
|
||||
CloudServer.print_configuration(conf)
|
||||
|
||||
@ -70,21 +75,28 @@ CloudServer.print_configuration(conf)
|
||||
# Sinatra Configuration
|
||||
##############################################################################
|
||||
set :config, conf
|
||||
set :bind, settings.config[:server]
|
||||
set :port, settings.config[:port]
|
||||
|
||||
include CloudLogger
|
||||
enable_logging EC2_LOG, settings.config[:debug_level].to_i
|
||||
|
||||
if CloudServer.is_port_open?(settings.config[:server],
|
||||
settings.config[:port])
|
||||
puts "Port busy, please shutdown the service or move econe server port."
|
||||
exit 1
|
||||
settings.logger.error {
|
||||
"Port #{settings.config[:port]} busy, please shutdown " <<
|
||||
"the service or move occi server port."
|
||||
}
|
||||
exit -1
|
||||
end
|
||||
|
||||
set :bind, settings.config[:server]
|
||||
set :port, settings.config[:port]
|
||||
|
||||
begin
|
||||
ENV["ONE_CIPHER_AUTH"] = EC2_AUTH
|
||||
cloud_auth = CloudAuth.new(settings.config)
|
||||
cloud_auth = CloudAuth.new(settings.config, settings.logger)
|
||||
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
|
||||
|
||||
@ -116,6 +128,7 @@ before do
|
||||
params['econe_path'] = settings.econe_path
|
||||
username = settings.cloud_auth.auth(request.env, params)
|
||||
rescue Exception => e
|
||||
logger.error {e.message}
|
||||
error 500, error_xml("AuthFailure", 0)
|
||||
end
|
||||
|
||||
@ -123,7 +136,7 @@ before do
|
||||
error 401, error_xml("AuthFailure", 0)
|
||||
else
|
||||
client = settings.cloud_auth.client(username)
|
||||
@econe_server = EC2QueryServer.new(client, settings.config)
|
||||
@econe_server = EC2QueryServer.new(client, settings.config, settings.logger)
|
||||
end
|
||||
end
|
||||
|
||||
@ -179,6 +192,7 @@ def do_http_request(params)
|
||||
end
|
||||
|
||||
if OpenNebula::is_error?(result)
|
||||
logger.error(result.message)
|
||||
error rc, error_xml(result.message, 0)
|
||||
end
|
||||
|
||||
|
@ -34,8 +34,8 @@
|
||||
# x509, for x509 certificate encryption of tokens
|
||||
:core_auth: cipher
|
||||
|
||||
# Life-time in seconds for token renewal (that used to handle OpenNebula auths)
|
||||
:token_expiration_delta: 1800
|
||||
# 0 = ERROR, 1 = WARNING, 2 = INFO, 3 = DEBUG
|
||||
:debug_level: 3
|
||||
|
||||
# VM types allowed and its template file (inside templates directory)
|
||||
:instance_types:
|
||||
|
@ -52,8 +52,8 @@ class OCCIServer < CloudServer
|
||||
# Server initializer
|
||||
# config_file:: _String_ path of the config file
|
||||
# template:: _String_ path to the location of the templates
|
||||
def initialize(client, config)
|
||||
super(config)
|
||||
def initialize(client, config, logger)
|
||||
super(config, logger)
|
||||
|
||||
if config[:ssl_server]
|
||||
@base_url=config[:ssl_server]
|
||||
@ -568,7 +568,7 @@ class OCCIServer < CloudServer
|
||||
return [404, error]
|
||||
end
|
||||
|
||||
vnc_proxy = OpenNebulaVNC.new(config,{:json_errors => false})
|
||||
vnc_proxy = OpenNebulaVNC.new(config, logger, {:json_errors => false})
|
||||
return vnc_proxy.start(vm)
|
||||
end
|
||||
|
||||
@ -576,7 +576,8 @@ class OCCIServer < CloudServer
|
||||
begin
|
||||
OpenNebulaVNC.stop(pipe)
|
||||
rescue Exception => e
|
||||
return [500, e.message]
|
||||
logger.error {e.message}
|
||||
return [500, "Error stopping VNC. Please check server logs."]
|
||||
end
|
||||
|
||||
return [200,nil]
|
||||
|
@ -25,18 +25,22 @@
|
||||
ONE_LOCATION=ENV["ONE_LOCATION"]
|
||||
|
||||
if !ONE_LOCATION
|
||||
RUBY_LIB_LOCATION="/usr/lib/one/ruby"
|
||||
LOG_LOCATION = "/var/log/one"
|
||||
VAR_LOCATION = "/var/lib/one"
|
||||
TEMPLATE_LOCATION="/etc/one/occi_templates"
|
||||
CONFIGURATION_FILE = "/etc/one/occi-server.conf"
|
||||
ETC_LOCATION = "/etc/one"
|
||||
RUBY_LIB_LOCATION = "/usr/lib/one/ruby"
|
||||
else
|
||||
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
|
||||
VAR_LOCATION = ONE_LOCATION+"/var"
|
||||
TEMPLATE_LOCATION=ONE_LOCATION+"/etc/occi_templates"
|
||||
CONFIGURATION_FILE = ONE_LOCATION+"/etc/occi-server.conf"
|
||||
VAR_LOCATION = ONE_LOCATION + "/var"
|
||||
LOG_LOCATION = ONE_LOCATION + "/var"
|
||||
ETC_LOCATION = ONE_LOCATION + "/etc"
|
||||
RUBY_LIB_LOCATION = ONE_LOCATION+"/lib/ruby"
|
||||
end
|
||||
|
||||
OCCI_AUTH = VAR_LOCATION + "/.one/occi_auth"
|
||||
OCCI_AUTH = VAR_LOCATION + "/.one/occi_auth"
|
||||
OCCI_LOG = LOG_LOCATION + "/occi-server.log"
|
||||
CONFIGURATION_FILE = ETC_LOCATION + "/occi-server.conf"
|
||||
|
||||
TEMPLATE_LOCATION = ETC_LOCATION + "/occi_templates"
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << RUBY_LIB_LOCATION+"/cloud/occi"
|
||||
@ -59,42 +63,55 @@ require 'CloudAuth'
|
||||
include OpenNebula
|
||||
|
||||
##############################################################################
|
||||
# Parse Configuration file
|
||||
# Configuration
|
||||
##############################################################################
|
||||
# Set Configuration settings
|
||||
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
|
||||
|
||||
conf[:template_location] = TEMPLATE_LOCATION
|
||||
conf[:debug_level] ||= 3
|
||||
|
||||
CloudServer.print_configuration(conf)
|
||||
|
||||
##############################################################################
|
||||
# Sinatra Configuration
|
||||
##############################################################################
|
||||
set :config, conf
|
||||
|
||||
|
||||
# Enable Logger
|
||||
include CloudLogger
|
||||
enable_logging OCCI_LOG, settings.config[:debug_level].to_i
|
||||
|
||||
|
||||
# Set Sinatra configuration
|
||||
use Rack::Session::Pool, :key => 'occi'
|
||||
|
||||
set :public, Proc.new { File.join(root, "ui/public") }
|
||||
set :views, settings.root + '/ui/views'
|
||||
set :config, conf
|
||||
|
||||
if CloudServer.is_port_open?(settings.config[:server],
|
||||
settings.config[:port])
|
||||
puts "Port busy, please shutdown the service or move occi server port."
|
||||
exit
|
||||
settings.logger.error {
|
||||
"Port #{settings.config[:port]} busy, please shutdown " <<
|
||||
"the service or move occi server port."
|
||||
}
|
||||
exit -1
|
||||
end
|
||||
|
||||
set :bind, settings.config[:server]
|
||||
set :port, settings.config[:port]
|
||||
|
||||
|
||||
# Create CloudAuth
|
||||
begin
|
||||
ENV["ONE_CIPHER_AUTH"] = OCCI_AUTH
|
||||
cloud_auth = CloudAuth.new(settings.config)
|
||||
cloud_auth = CloudAuth.new(settings.config, settings.logger)
|
||||
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
|
||||
|
||||
@ -110,17 +127,21 @@ before do
|
||||
begin
|
||||
username = settings.cloud_auth.auth(request.env, params)
|
||||
rescue Exception => e
|
||||
error 500, e.message
|
||||
logger.error {e.message}
|
||||
error 500, ""
|
||||
end
|
||||
else
|
||||
username = session[:user]
|
||||
end
|
||||
|
||||
if username.nil? #unable to authenticate
|
||||
logger.error {"User not authorized"}
|
||||
error 401, ""
|
||||
else
|
||||
client = settings.cloud_auth.client(username)
|
||||
@occi_server = OCCIServer.new(client, settings.config)
|
||||
@occi_server = OCCIServer.new(client,
|
||||
settings.config,
|
||||
settings.logger)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -147,20 +168,24 @@ helpers do
|
||||
begin
|
||||
username = settings.cloud_auth.auth(request.env, params)
|
||||
rescue Exception => e
|
||||
error 500, e.message
|
||||
logger.error {e.message}
|
||||
error 500, ""
|
||||
end
|
||||
|
||||
if username.nil?
|
||||
logger.error {"User not authorized"}
|
||||
error 401, ""
|
||||
else
|
||||
client = settings.cloud_auth.client(username)
|
||||
@occi_server = OCCIServer.new(client, settings.config)
|
||||
@occi_server = OCCIServer.new(client,
|
||||
settings.config,
|
||||
settings.logger)
|
||||
|
||||
user_id = OpenNebula::User::SELF
|
||||
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
|
||||
|
||||
@ -190,6 +215,7 @@ helpers do
|
||||
|
||||
def treat_response(result,rc)
|
||||
if OpenNebula::is_error?(result)
|
||||
logger.error {result.message}
|
||||
halt rc, result.message
|
||||
end
|
||||
|
||||
|
@ -19,14 +19,14 @@
|
||||
if [ -z "$ONE_LOCATION" ]; then
|
||||
OZONES_PID=/var/run/one/ozones.pid
|
||||
OZONES_LOCATION=/usr/lib/one/ozones
|
||||
OZONES_SERVER=$OZONES_LOCATION/config.ru
|
||||
OZONES_SERVER=$OZONES_LOCATION/ozones-server.rb
|
||||
OZONES_LOCK_FILE=/var/lock/one/.ozones.lock
|
||||
OZONES_LOG=/var/log/one/ozones-server.log
|
||||
OZONES_CONF=/etc/one/ozones-server.conf
|
||||
else
|
||||
OZONES_PID=$ONE_LOCATION/var/ozones.pid
|
||||
OZONES_LOCATION=$ONE_LOCATION/lib/ozones
|
||||
OZONES_SERVER=$OZONES_LOCATION/config.ru
|
||||
OZONES_SERVER=$OZONES_LOCATION/ozones-server.rb
|
||||
OZONES_LOCK_FILE=$ONE_LOCATION/var/.ozones.lock
|
||||
OZONES_LOG=$ONE_LOCATION/var/ozones-server.log
|
||||
OZONES_CONF=$ONE_LOCATION/etc/ozones-server.conf
|
||||
@ -58,29 +58,26 @@ start()
|
||||
exit 1
|
||||
fi
|
||||
|
||||
HOST=`cat $OZONES_CONF|grep ^\:host\:|cut -d' ' -f 2`
|
||||
PORT=`cat $OZONES_CONF|grep ^\:port\:|cut -d' ' -f 2`
|
||||
|
||||
lsof -i:$PORT &> /dev/null
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "The port $PORT is being used. Please specify a different one."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Start the ozones daemon
|
||||
touch $OZONES_LOCK_FILE
|
||||
rackup $OZONES_SERVER -s thin -p $PORT -o $HOST \
|
||||
-P $OZONES_PID &> $OZONES_LOG &
|
||||
ruby $OZONES_SERVER > $OZONES_LOG 2>&1 &
|
||||
LASTPID=$!
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error executing $OZONES_SERVER, please check the log $OZONES_LOG"
|
||||
exit 1
|
||||
else
|
||||
echo $LASTPID > $OZONES_PID
|
||||
fi
|
||||
|
||||
sleep 2
|
||||
ps -p $(cat $OZONES_PID 2>/dev/null) > /dev/null 2>&1
|
||||
ps $LASTPID &> /dev/null
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error executing $OZONES_SERVER, please check the log $OZONES_LOG"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "ozones-server listening on $HOST:$PORT"
|
||||
echo "ozones-server started"
|
||||
}
|
||||
|
||||
#
|
||||
|
@ -1,23 +0,0 @@
|
||||
#!/usr/bin/ruby
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
$: << File.dirname(__FILE__)
|
||||
|
||||
require 'ozones-server.rb'
|
||||
|
||||
run Sinatra::Application
|
@ -19,7 +19,7 @@
|
||||
##############################################
|
||||
|
||||
######################
|
||||
# DB Options
|
||||
# DB Options
|
||||
######################
|
||||
|
||||
:databasetype: sqlite
|
||||
@ -27,6 +27,9 @@
|
||||
#:htaccess: /var/www/.htaccess
|
||||
:dbdebug: no
|
||||
|
||||
# 0 = ERROR, 1 = WARNING, 2 = INFO, 3 = DEBUG
|
||||
:debug_level: 3
|
||||
|
||||
#####################
|
||||
# Server Configuration
|
||||
#####################
|
||||
|
@ -14,13 +14,16 @@
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
require 'CloudServer'
|
||||
|
||||
require 'JSONUtils'
|
||||
|
||||
|
||||
class OzonesServer
|
||||
class OzonesServer < CloudServer
|
||||
include OpenNebulaJSON::JSONUtils
|
||||
|
||||
def initialize(cipher)
|
||||
def initialize(cipher, config, logger)
|
||||
super(config, logger)
|
||||
#Set cipher for Zone classes
|
||||
OZones::Zones.cipher = cipher
|
||||
end
|
||||
|
@ -19,19 +19,25 @@
|
||||
ONE_LOCATION=ENV["ONE_LOCATION"]
|
||||
|
||||
if !ONE_LOCATION
|
||||
ETC_LOCATION="/etc/one"
|
||||
LIB_LOCATION="/usr/lib/one"
|
||||
RUBY_LIB_LOCATION="/usr/lib/one/ruby"
|
||||
VAR_LOCATION="/var/lib/one"
|
||||
LOG_LOCATION = "/var/log/one"
|
||||
VAR_LOCATION = "/var/lib/one"
|
||||
ETC_LOCATION = "/etc/one"
|
||||
LIB_LOCATION = "/usr/lib/one"
|
||||
RUBY_LIB_LOCATION = "/usr/lib/one/ruby"
|
||||
else
|
||||
ETC_LOCATION=ONE_LOCATION+"/etc"
|
||||
LIB_LOCATION=ONE_LOCATION+"/lib"
|
||||
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
|
||||
VAR_LOCATION=ONE_LOCATION+"/var"
|
||||
VAR_LOCATION = ONE_LOCATION + "/var"
|
||||
LOG_LOCATION = ONE_LOCATION + "/var"
|
||||
ETC_LOCATION = ONE_LOCATION + "/etc"
|
||||
LIB_LOCATION = ONE_LOCATION+"/lib"
|
||||
RUBY_LIB_LOCATION = ONE_LOCATION+"/lib/ruby"
|
||||
end
|
||||
|
||||
OZONES_LOG = LOG_LOCATION + "/ozones-server.log"
|
||||
CONFIGURATION_FILE = ETC_LOCATION + "/ozones-server.conf"
|
||||
|
||||
$: << LIB_LOCATION + "/sunstone/models"
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << RUBY_LIB_LOCATION+'/cloud'
|
||||
$: << LIB_LOCATION+'/ozones/models'
|
||||
$: << LIB_LOCATION+'/ozones/lib'
|
||||
$: << RUBY_LIB_LOCATION+"/cli"
|
||||
@ -52,8 +58,16 @@ require 'OzonesServer'
|
||||
##############################################################################
|
||||
# Read configuration
|
||||
##############################################################################
|
||||
config_data=File.read(ETC_LOCATION+'/ozones-server.conf')
|
||||
config=YAML::load(config_data)
|
||||
begin
|
||||
config=YAML::load_file(CONFIGURATION_FILE)
|
||||
rescue Exception => e
|
||||
warn "Error parsing config file #{CONFIGURATION_FILE}: #{e.message}"
|
||||
exit 1
|
||||
end
|
||||
|
||||
config[:debug_level] ||= 3
|
||||
|
||||
CloudServer.print_configuration(config)
|
||||
|
||||
db_type = config[:databasetype]
|
||||
|
||||
@ -72,6 +86,19 @@ case db_type
|
||||
exit -1
|
||||
end
|
||||
|
||||
##############################################################################
|
||||
# Sinatra Configuration
|
||||
##############################################################################
|
||||
set :config, config
|
||||
set :bind, config[:host]
|
||||
set :port, config[:port]
|
||||
|
||||
use Rack::Session::Pool, :key => 'ozones'
|
||||
|
||||
#Enable logger
|
||||
include CloudLogger
|
||||
enable_logging OZONES_LOG, settings.config[:debug_level].to_i
|
||||
|
||||
##############################################################################
|
||||
# DB bootstrapping
|
||||
##############################################################################
|
||||
@ -92,7 +119,7 @@ if Auth.all.size == 0
|
||||
credentials = IO.read(ENV['OZONES_AUTH']).strip.split(':')
|
||||
|
||||
if credentials.length < 2
|
||||
warn "Authorization data malformed"
|
||||
settings.logger.error {"Authorization data malformed"}
|
||||
exit -1
|
||||
end
|
||||
credentials[1] = Digest::SHA1.hexdigest(credentials[1])
|
||||
@ -100,7 +127,8 @@ if Auth.all.size == 0
|
||||
:password => credentials[1]})
|
||||
@auth.save
|
||||
else
|
||||
warn "oZones admin credentials not set, missing OZONES_AUTH file."
|
||||
error_m = "oZones admin credentials not set, missing OZONES_AUTH file."
|
||||
settings.logger.error { error_m }
|
||||
exit -1
|
||||
end
|
||||
else
|
||||
@ -113,19 +141,10 @@ ADMIN_PASS = @auth.password
|
||||
begin
|
||||
OZones::ProxyRules.new("apache",config[:htaccess])
|
||||
rescue Exception => e
|
||||
warn e.message
|
||||
settings.logger {e.message}
|
||||
exit -1
|
||||
end
|
||||
|
||||
|
||||
##############################################################################
|
||||
# Sinatra Configuration
|
||||
##############################################################################
|
||||
use Rack::Session::Pool, :key => 'ozones'
|
||||
set :bind, config[:host]
|
||||
set :port, config[:port]
|
||||
set :show_exceptions, false
|
||||
|
||||
##############################################################################
|
||||
# Helpers
|
||||
##############################################################################
|
||||
@ -157,10 +176,11 @@ helpers do
|
||||
|
||||
return [204, ""]
|
||||
else
|
||||
logger.info {"User not authorized login attempt"}
|
||||
return [401, ""]
|
||||
end
|
||||
end
|
||||
|
||||
logger.error {"Authentication settings wrong or not provided"}
|
||||
return [401, ""]
|
||||
end
|
||||
|
||||
@ -181,7 +201,9 @@ before do
|
||||
end
|
||||
end
|
||||
|
||||
@OzonesServer = OzonesServer.new(session[:key])
|
||||
@OzonesServer = OzonesServer.new(session[:key],
|
||||
settings.config,
|
||||
settings.logger)
|
||||
@pr = OZones::ProxyRules.new("apache",config[:htaccess])
|
||||
end
|
||||
end
|
||||
|
@ -21,7 +21,7 @@ require 'OpenNebula'
|
||||
# This class provides support for launching and stopping a websockify proxy
|
||||
#
|
||||
class OpenNebulaVNC
|
||||
def initialize(config, opt={:json_errors => true})
|
||||
def initialize(config, logger, opt={:json_errors => true})
|
||||
@proxy_path = config[:vnc_proxy_path]
|
||||
@proxy_base_port = config[:vnc_proxy_base_port].to_i
|
||||
|
||||
@ -36,6 +36,7 @@ class OpenNebulaVNC
|
||||
end
|
||||
|
||||
@options = opt
|
||||
@logger = logger
|
||||
end
|
||||
|
||||
# Start a VNC proxy
|
||||
@ -71,7 +72,7 @@ class OpenNebulaVNC
|
||||
cmd ="#{@proxy_path} #{proxy_options} #{proxy_port} #{host}:#{vnc_port}"
|
||||
|
||||
begin
|
||||
$stderr.puts("Starting vnc proxy: #{cmd}")
|
||||
@logger.info { "Starting vnc proxy: #{cmd}" }
|
||||
pipe = IO.popen(cmd)
|
||||
rescue Exception => e
|
||||
return [500, OpenNebula::Error.new(e.message).to_json]
|
||||
|
@ -1,23 +0,0 @@
|
||||
#!/usr/bin/ruby
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
$: << File.dirname(__FILE__)
|
||||
|
||||
require 'sunstone-server.rb'
|
||||
|
||||
run Sinatra::Application
|
@ -1,6 +1,9 @@
|
||||
# OpenNebula sever contact information
|
||||
:one_xmlrpc: http://localhost:2633/RPC2
|
||||
|
||||
# 0 = ERROR, 1 = WARNING, 2 = INFO, 3 = DEBUG
|
||||
:debug_level: 3
|
||||
|
||||
# Server Configuration
|
||||
:host: 127.0.0.1
|
||||
:port: 9869
|
||||
|
@ -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,7 +32,9 @@ else
|
||||
end
|
||||
|
||||
SUNSTONE_AUTH = VAR_LOCATION + "/.one/sunstone_auth"
|
||||
SUNSTONE_LOG = LOG_LOCATION + "/sunstone.log"
|
||||
CONFIGURATION_FILE = ETC_LOCATION + "/sunstone-server.conf"
|
||||
|
||||
PLUGIN_CONFIGURATION_FILE = ETC_LOCATION + "/sunstone-plugins.yaml"
|
||||
|
||||
SUNSTONE_ROOT_DIR = File.dirname(__FILE__)
|
||||
@ -54,27 +56,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 +110,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 +124,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 +176,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 +265,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