mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-25 02:50:08 +03:00
feature #564: Add Configuration file
This commit is contained in:
parent
95d156f592
commit
77e21af42e
@ -353,6 +353,7 @@ INSTALL_ETC_FILES=(
|
||||
ECO_ETC_TEMPLATE_FILES:$ETC_LOCATION/ec2query_templates
|
||||
OCCI_ETC_FILES:$ETC_LOCATION
|
||||
OCCI_ETC_TEMPLATE_FILES:$ETC_LOCATION/occi_templates
|
||||
SUNSTONE_ETC_FILES:$ETC_LOCATION
|
||||
)
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
@ -748,6 +749,8 @@ SUNSTONE_FILES="src/sunstone/config.ru \
|
||||
|
||||
SUNSTONE_BIN_FILES="src/sunstone/bin/sunstone-server"
|
||||
|
||||
SUNSTONE_ETC_FILES="src/sunstone/etc/sunstone-server.conf"
|
||||
|
||||
SUNSTONE_MODELS_FILES="src/sunstone/models/OpenNebulaJSON.rb \
|
||||
src/sunstone/models/SunstoneServer.rb"
|
||||
|
||||
|
@ -22,24 +22,15 @@ if [ -z "$ONE_LOCATION" ]; then
|
||||
SUNSTONE_SERVER=/usr/lib/one/sunstone/config.ru
|
||||
SUNSTONE_LOCK_FILE=/var/lock/one/.sunstone.lock
|
||||
SUNSTONE_LOG=/var/log/one/sunstone.log
|
||||
SUNSTONE_CONF=/etc/one/sunstone-server.conf
|
||||
else
|
||||
SUNSTONE_PID=$ONE_LOCATION/var/sunstone.pid
|
||||
SUNSTONE_SERVER=$ONE_LOCATION/lib/sunstone/config.ru
|
||||
SUNSTONE_LOCK_FILE=$ONE_LOCATION/var/.sunstone.lock
|
||||
SUNSTONE_LOG=$ONE_LOCATION/var/sunstone.log
|
||||
SUNSTONE_CONF=$ONE_LOCATION/etc/sunstone-server.conf
|
||||
fi
|
||||
|
||||
PORT="4567"
|
||||
HOST="127.0.0.1"
|
||||
|
||||
usage() {
|
||||
echo
|
||||
echo "Usage: sunstone-server [-H host] [-p port]"
|
||||
echo
|
||||
echo "-H: Host for the Sunstone server, default value: localhost"
|
||||
echo "-p: Port for incoming connections, default value: 4567"
|
||||
}
|
||||
|
||||
setup()
|
||||
{
|
||||
|
||||
@ -48,7 +39,8 @@ setup()
|
||||
SUNSTONEPID=`cat $SUNSTONE_PID`
|
||||
ps $SUNSTONEPID &> /dev/null
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "Sunstone Server is still running (PID:$SUNSTONEPID). Please try 'sunstone-server stop' first."
|
||||
echo -n "Sunstone Server is still running (PID:$SUNSTONEPID). Please "
|
||||
echo "try 'sunstone-server stop' first."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
@ -65,14 +57,21 @@ start()
|
||||
exit 1
|
||||
fi
|
||||
|
||||
source $SUNSTONE_CONF
|
||||
|
||||
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 sunstone daemon
|
||||
touch $SUNSTONE_LOCK_FILE
|
||||
rackup $SUNSTONE_SERVER -s thin -p $PORT -o $HOST -P $SUNSTONE_PID &> $SUNSTONE_LOG &
|
||||
rackup $SUNSTONE_SERVER -s thin -p $PORT -o $HOST \
|
||||
-P $SUNSTONE_PID &> $SUNSTONE_LOG &
|
||||
|
||||
LASTRC=$?
|
||||
|
||||
if [ $LASTRC -ne 0 ]; then
|
||||
echo "Error executing $SUNSTONE_SERVER"
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error executing $SUNSTONE_SERVER, please check the log $SUNSTONE_LOG"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@ -80,11 +79,11 @@ start()
|
||||
ps $LASTPID &> /dev/null
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error executing $SUNSTONE_SERVER."
|
||||
echo "Error executing $SUNSTONE_SERVER, please check the log $SUNSTONE_LOG"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "sunstone-server started"
|
||||
echo "sunstone-server listening on $HOST:$PORT"
|
||||
}
|
||||
|
||||
#
|
||||
@ -106,19 +105,8 @@ stop()
|
||||
echo "sunstone-server stopped"
|
||||
}
|
||||
|
||||
while getopts "p:H:" OPTION
|
||||
do
|
||||
case $OPTION in
|
||||
p) PORT=$OPTARG;;
|
||||
H) HOST=$OPTARG;;
|
||||
*) usage; exit 3;;
|
||||
esac
|
||||
done
|
||||
|
||||
shift $((OPTIND-1))
|
||||
|
||||
case "$1" in
|
||||
start) setup; start;;
|
||||
stop) stop;;
|
||||
*) usage; exit 3;;
|
||||
*) echo "Usage: sunstone-server {start|stop}" >&2; exit 3;;
|
||||
esac
|
||||
|
7
src/sunstone/etc/sunstone-server.conf
Normal file
7
src/sunstone/etc/sunstone-server.conf
Normal file
@ -0,0 +1,7 @@
|
||||
# Server Configuration
|
||||
HOST=127.0.0.1
|
||||
PORT=9869
|
||||
|
||||
# VNC Configuration
|
||||
VNC_PROXY_BASE_PORT=29876
|
||||
NOVNC_PATH=
|
@ -14,27 +14,10 @@
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
ONE_LOCATION = ENV["ONE_LOCATION"]
|
||||
|
||||
if !ONE_LOCATION
|
||||
LOG_LOCATION = "/var/log/one"
|
||||
VAR_LOCATION = "/var/lib/one"
|
||||
RUBY_LIB_LOCATION = "/usr/lib/one/ruby"
|
||||
else
|
||||
VAR_LOCATION = ONE_LOCATION+"/var"
|
||||
LOG_LOCATION = ONE_LOCATION+"/var"
|
||||
RUBY_LIB_LOCATION = ONE_LOCATION+"/lib/ruby"
|
||||
end
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << File.dirname(__FILE__)
|
||||
|
||||
require 'models/OpenNebulaJSON'
|
||||
require 'OpenNebulaJSON'
|
||||
include OpenNebulaJSON
|
||||
|
||||
class SunstoneServer
|
||||
VNC_PROXY_BASE_PORT = 29876
|
||||
|
||||
def initialize(username, password)
|
||||
# TBD one_client_user(name) from CloudServer
|
||||
@client = Client.new("dummy:dummy")
|
||||
@ -221,7 +204,7 @@ class SunstoneServer
|
||||
########################################################################
|
||||
# VNC
|
||||
########################################################################
|
||||
def startvnc(id)
|
||||
def startvnc(id, config)
|
||||
resource = retrieve_resource("vm", id)
|
||||
if OpenNebula.is_error?(resource)
|
||||
return [404, resource.to_json]
|
||||
@ -237,17 +220,17 @@ class SunstoneServer
|
||||
return [403, error.to_json]
|
||||
end
|
||||
|
||||
vnc_port = resource['TEMPLATE/GRAPHICS/PORT']
|
||||
# The VM host and its VNC port
|
||||
host = resource['HISTORY/HOSTNAME']
|
||||
vnc_port = resource['TEMPLATE/GRAPHICS/PORT']
|
||||
|
||||
proxy_port = VNC_PROXY_BASE_PORT + vnc_port.to_i
|
||||
# The noVNC proxy_port
|
||||
proxy_port = config[:vnc_proxy_base_port] + vnc_port.to_i
|
||||
|
||||
# puts "Launch noVNC on #{final_port} listenting to #{host}:#{vnc_port}"
|
||||
# So here we launch the noVNC server listening on the final_port
|
||||
# and serving as proxy for the VM host on the configured VNC port.
|
||||
# TODO - This path is in public...
|
||||
begin
|
||||
pipe = IO.popen("#{File.dirname(__FILE__)}/../lib/vendor/noVNC/utils/launch.sh --listen #{proxy_port} --vnc #{host}:#{vnc_port}")
|
||||
novnc_cmd = "#{config[:novnc_path]}/utils/launch.sh"
|
||||
pipe = IO.popen("#{novnc_cmd} --listen #{proxy_port} \
|
||||
--vnc #{host}:#{vnc_port}")
|
||||
rescue Exception => e
|
||||
error = Error.new(e.message)
|
||||
return [500, error.to_json]
|
||||
@ -268,7 +251,6 @@ class SunstoneServer
|
||||
return [404, resource.to_json]
|
||||
end
|
||||
|
||||
# puts "Killing noVNC with pid #{pid}"
|
||||
begin
|
||||
Process.kill('KILL',pipe.pid)
|
||||
pipe.close
|
||||
|
@ -16,20 +16,40 @@
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
ONE_LOCATION = ENV["ONE_LOCATION"]
|
||||
|
||||
if !ONE_LOCATION
|
||||
LOG_LOCATION = "/var/log/one"
|
||||
VAR_LOCATION = "/var/lib/one"
|
||||
RUBY_LIB_LOCATION = "/usr/lib/one/ruby"
|
||||
CONFIGURATION_FILE = "/etc/one/sunstone-server.conf"
|
||||
else
|
||||
VAR_LOCATION = ONE_LOCATION+"/var"
|
||||
LOG_LOCATION = ONE_LOCATION+"/var"
|
||||
RUBY_LIB_LOCATION = ONE_LOCATION+"/lib/ruby"
|
||||
CONFIGURATION_FILE = ONE_LOCATION+"/etc/sunstone-server.conf"
|
||||
end
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << File.dirname(__FILE__)+'/models'
|
||||
|
||||
##############################################################################
|
||||
# Required libraries
|
||||
##############################################################################
|
||||
require 'rubygems'
|
||||
require 'sinatra'
|
||||
|
||||
require 'models/SunstoneServer'
|
||||
require 'cloud/Configuration'
|
||||
require 'SunstoneServer'
|
||||
|
||||
@config = Configuration.new(CONFIGURATION_FILE)
|
||||
|
||||
##############################################################################
|
||||
# Sinatra Configuration
|
||||
##############################################################################
|
||||
use Rack::Session::Pool
|
||||
|
||||
set :host, @config[:host]
|
||||
set :port, @config[:port]
|
||||
|
||||
##############################################################################
|
||||
# Helpers
|
||||
@ -201,7 +221,7 @@ post '/vm/:id/startvnc' do
|
||||
return [200, info.to_json]
|
||||
end
|
||||
|
||||
rc = @SunstoneServer.startvnc(vm_id)
|
||||
rc = @SunstoneServer.startvnc(vm_id, @config)
|
||||
if rc[0] == 200
|
||||
info = rc[1]
|
||||
session['vnc'][vm_id] = info.clone
|
||||
|
Loading…
x
Reference in New Issue
Block a user