Revision 96e19909 src/sunstone/sunstone-server.rb
src/sunstone/sunstone-server.rb | ||
---|---|---|
64 | 64 |
############################################################################## |
65 | 65 |
|
66 | 66 |
begin |
67 |
conf = YAML.load_file(CONFIGURATION_FILE) |
|
67 |
$conf = YAML.load_file(CONFIGURATION_FILE)
|
|
68 | 68 |
rescue Exception => e |
69 | 69 |
STDERR.puts "Error parsing config file #{CONFIGURATION_FILE}: #{e.message}" |
70 | 70 |
exit 1 |
71 | 71 |
end |
72 | 72 |
|
73 |
conf[:debug_level] ||= 3 |
|
73 |
$conf[:debug_level] ||= 3
|
|
74 | 74 |
|
75 |
CloudServer.print_configuration(conf) |
|
75 |
CloudServer.print_configuration($conf)
|
|
76 | 76 |
|
77 | 77 |
#Sinatra configuration |
78 | 78 |
|
79 |
set :config, conf |
|
80 |
set :bind, settings.config[:host]
|
|
81 |
set :port, settings.config[:port]
|
|
79 |
set :config, $conf
|
|
80 |
set :bind, $conf[:host]
|
|
81 |
set :port, $conf[:port]
|
|
82 | 82 |
|
83 |
case settings.config[:sessions]
|
|
83 |
case $conf[:sessions]
|
|
84 | 84 |
when 'memory', nil |
85 | 85 |
use Rack::Session::Pool, :key => 'sunstone' |
86 | 86 |
when 'memcache' |
87 |
memcache_server=settings.config[:memcache_host]+':'<<
|
|
88 |
settings.config[:memcache_port].to_s
|
|
87 |
memcache_server=$conf[:memcache_host]+':'<<
|
|
88 |
$conf[:memcache_port].to_s
|
|
89 | 89 |
|
90 | 90 |
STDERR.puts memcache_server |
91 | 91 |
|
92 | 92 |
use Rack::Session::Memcache, |
93 | 93 |
:memcache_server => memcache_server, |
94 |
:namespace => settings.config[:memcache_namespace]
|
|
94 |
:namespace => $conf[:memcache_namespace]
|
|
95 | 95 |
else |
96 | 96 |
STDERR.puts "Wrong value for :sessions in configuration file" |
97 | 97 |
exit(-1) |
... | ... | |
100 | 100 |
# Enable logger |
101 | 101 |
|
102 | 102 |
include CloudLogger |
103 |
enable_logging SUNSTONE_LOG, settings.config[:debug_level].to_i
|
|
103 |
logger=enable_logging(SUNSTONE_LOG, $conf[:debug_level].to_i)
|
|
104 | 104 |
|
105 | 105 |
begin |
106 | 106 |
ENV["ONE_CIPHER_AUTH"] = SUNSTONE_AUTH |
107 |
cloud_auth = CloudAuth.new(settings.config, settings.logger)
|
|
107 |
$cloud_auth = CloudAuth.new($conf, logger)
|
|
108 | 108 |
rescue => e |
109 |
settings.logger.error {
|
|
109 |
logger.error { |
|
110 | 110 |
"Error initializing authentication system" } |
111 |
settings.logger.error { e.message }
|
|
111 |
logger.error { e.message } |
|
112 | 112 |
exit -1 |
113 | 113 |
end |
114 | 114 |
|
115 |
set :cloud_auth, cloud_auth |
|
115 |
set :cloud_auth, $cloud_auth
|
|
116 | 116 |
|
117 | 117 |
#start VNC proxy |
118 | 118 |
|
119 |
$vnc = OpenNebulaVNC.new($conf, logger) |
|
120 |
|
|
119 | 121 |
configure do |
120 | 122 |
set :run, false |
121 |
set :vnc, OpenNebulaVNC.new(conf, settings.logger)
|
|
123 |
set :vnc, $vnc
|
|
122 | 124 |
end |
123 | 125 |
|
124 | 126 |
############################################################################## |
... | ... | |
131 | 133 |
|
132 | 134 |
def build_session |
133 | 135 |
begin |
134 |
result = settings.cloud_auth.auth(request.env, params)
|
|
136 |
result = $cloud_auth.auth(request.env, params)
|
|
135 | 137 |
rescue Exception => e |
136 | 138 |
logger.error { e.message } |
137 | 139 |
return [500, ""] |
... | ... | |
141 | 143 |
logger.info { "Unauthorized login attempt" } |
142 | 144 |
return [401, ""] |
143 | 145 |
else |
144 |
client = settings.cloud_auth.client(result)
|
|
146 |
client = $cloud_auth.client(result)
|
|
145 | 147 |
user_id = OpenNebula::User::SELF |
146 | 148 |
|
147 | 149 |
user = OpenNebula::User.new_with_id(user_id, client) |
... | ... | |
166 | 168 |
if user['TEMPLATE/LANG'] |
167 | 169 |
session[:lang] = user['TEMPLATE/LANG'] |
168 | 170 |
else |
169 |
session[:lang] = settings.config[:lang]
|
|
171 |
session[:lang] = $conf[:lang]
|
|
170 | 172 |
end |
171 | 173 |
|
172 | 174 |
if user['TEMPLATE/VNC_WSS'] |
173 | 175 |
session[:wss] = user['TEMPLATE/VNC_WSS'] |
174 | 176 |
else |
175 |
wss = settings.config[:vnc_proxy_support_wss]
|
|
177 |
wss = $conf[:vnc_proxy_support_wss]
|
|
176 | 178 |
#limit to yes,no options |
177 | 179 |
session[:wss] = (wss == true || wss == "yes" || wss == "only" ? |
178 | 180 |
"yes" : "no") |
... | ... | |
201 | 203 |
halt 401 unless authorized? |
202 | 204 |
|
203 | 205 |
@SunstoneServer = SunstoneServer.new( |
204 |
settings.cloud_auth.client(session[:user]),
|
|
205 |
settings.config,
|
|
206 |
settings.logger)
|
|
206 |
$cloud_auth.client(session[:user]),
|
|
207 |
$conf,
|
|
208 |
logger) |
|
207 | 209 |
end |
208 | 210 |
end |
209 | 211 |
|
... | ... | |
222 | 224 |
############################################################################## |
223 | 225 |
# Custom routes |
224 | 226 |
############################################################################## |
225 |
if settings.config[:routes]
|
|
226 |
settings.config[:routes].each { |route|
|
|
227 |
if $conf[:routes]
|
|
228 |
$conf[:routes].each { |route|
|
|
227 | 229 |
require "routes/#{route}" |
228 | 230 |
} |
229 | 231 |
end |
... | ... | |
282 | 284 |
:wss => session[:wss], |
283 | 285 |
}, |
284 | 286 |
:system_config => { |
285 |
:marketplace_url => settings.config[:marketplace_url],
|
|
286 |
:vnc_proxy_port => settings.vnc.proxy_port
|
|
287 |
:marketplace_url => $conf[:marketplace_url],
|
|
288 |
:vnc_proxy_port => $vnc.proxy_port
|
|
287 | 289 |
} |
288 | 290 |
} |
289 | 291 |
|
... | ... | |
395 | 397 |
############################################################################## |
396 | 398 |
post '/vm/:id/startvnc' do |
397 | 399 |
vm_id = params[:id] |
398 |
@SunstoneServer.startvnc(vm_id, settings.vnc)
|
|
400 |
@SunstoneServer.startvnc(vm_id, $vnc)
|
|
399 | 401 |
end |
400 | 402 |
|
401 | 403 |
############################################################################## |
Also available in: Unified diff