mirror of
https://github.com/OpenNebula/one.git
synced 2026-11-19 03:12:55 +09:00
Merge branch 'one-3.0' of git.opennebula.org:one into one-3.0
This commit is contained in:
commit
95ef877a66
50 files changed
+1281
-821
No files matched your search
+11
-7
@@ -228,12 +228,12 @@ public:
|
||||
|
||||
static string version()
|
||||
{
|
||||
return "OpenNebula 2.9.85";
|
||||
return "OpenNebula 2.9.90";
|
||||
};
|
||||
|
||||
static string db_version()
|
||||
{
|
||||
return "2.9.85";
|
||||
return "2.9.90";
|
||||
}
|
||||
|
||||
void start();
|
||||
@@ -449,8 +449,9 @@ private:
|
||||
void bootstrap();
|
||||
|
||||
/**
|
||||
* Callback function to TODO
|
||||
* @param _loaded_db_version TODO
|
||||
* Callback function for the check_db_version method. Stores the read
|
||||
* version in loaded_db_version
|
||||
* @param _loaded_db_version returned columns
|
||||
* @param num the number of columns read from the DB
|
||||
* @param names the column names
|
||||
* @param vaues the column values
|
||||
@@ -459,9 +460,12 @@ private:
|
||||
int select_cb(void *_loaded_db_version, int num, char **values,
|
||||
char **names);
|
||||
|
||||
/*
|
||||
* TODO
|
||||
* @return 0 ok, -1 version mismatch, -2 needs bootstrap
|
||||
/**
|
||||
* Reads the current DB version.
|
||||
*
|
||||
* @return 0 on success,
|
||||
* -1 if there is a version mismatch,
|
||||
* -2 if the DB needs a bootstrap
|
||||
*/
|
||||
int check_db_version();
|
||||
};
|
||||
|
||||
@@ -35,12 +35,21 @@ protected:
|
||||
:Request(method_name,params,help)
|
||||
{
|
||||
auth_op = AuthRequest::CHOWN;
|
||||
|
||||
Nebula& nd = Nebula::instance();
|
||||
gpool = nd.get_gpool();
|
||||
upool = nd.get_upool();
|
||||
};
|
||||
|
||||
~RequestManagerChown(){};
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
GroupPool * gpool;
|
||||
UserPool * upool;
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
virtual void request_execute(xmlrpc_c::paramList const& _paramList,
|
||||
RequestAttributes& att);
|
||||
};
|
||||
|
||||
+11
-2
@@ -202,6 +202,7 @@ LIB_DIRS="$LIB_LOCATION/ruby \
|
||||
$LIB_LOCATION/ruby/cloud/econe \
|
||||
$LIB_LOCATION/ruby/cloud/econe/views \
|
||||
$LIB_LOCATION/ruby/cloud/occi \
|
||||
$LIB_LOCATION/ruby/cloud/CloudAuth \
|
||||
$LIB_LOCATION/ruby/onedb \
|
||||
$LIB_LOCATION/tm_commands \
|
||||
$LIB_LOCATION/tm_commands/shared \
|
||||
@@ -345,6 +346,7 @@ INSTALL_FILES=(
|
||||
HOOK_FT_FILES:$VAR_LOCATION/remotes/hooks/ft
|
||||
HOOK_NETWORK_FILES:$VAR_LOCATION/remotes/hooks/vnm
|
||||
COMMON_CLOUD_LIB_FILES:$LIB_LOCATION/ruby/cloud
|
||||
CLOUD_AUTH_LIB_FILES:$LIB_LOCATION/ruby/cloud/CloudAuth
|
||||
ECO_LIB_FILES:$LIB_LOCATION/ruby/cloud/econe
|
||||
ECO_LIB_VIEW_FILES:$LIB_LOCATION/ruby/cloud/econe/views
|
||||
ECO_BIN_FILES:$BIN_LOCATION
|
||||
@@ -650,6 +652,7 @@ IMAGE_DRIVER_FS_SCRIPTS="src/image_mad/remotes/fs/cp \
|
||||
#-------------------------------------------------------------------------------
|
||||
ONEDB_MIGRATOR_FILES="src/onedb/2.0_to_2.9.80.rb \
|
||||
src/onedb/2.9.80_to_2.9.85.rb \
|
||||
src/onedb/2.9.85_to_2.9.90.rb \
|
||||
src/onedb/onedb.rb \
|
||||
src/onedb/onedb_backend.rb"
|
||||
|
||||
@@ -789,10 +792,14 @@ RUBY_OPENNEBULA_LIB_FILES="src/oca/ruby/OpenNebula/Host.rb \
|
||||
|
||||
COMMON_CLOUD_LIB_FILES="src/cloud/common/CloudServer.rb \
|
||||
src/cloud/common/CloudClient.rb \
|
||||
src/cloud/common/Configuration.rb"
|
||||
src/cloud/common/CloudAuth.rb"
|
||||
|
||||
COMMON_CLOUD_CLIENT_LIB_FILES="src/cloud/common/CloudClient.rb"
|
||||
|
||||
CLOUD_AUTH_LIB_FILES="src/cloud/common/CloudAuth/BasicCloudAuth.rb \
|
||||
src/cloud/common/CloudAuth/EC2CloudAuth.rb \
|
||||
src/cloud/common/CloudAuth/X509CloudAuth.rb"
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# EC2 Query for OpenNebula
|
||||
#-------------------------------------------------------------------------------
|
||||
@@ -926,7 +933,8 @@ SUNSTONE_MODELS_JSON_FILES="src/sunstone/models/OpenNebulaJSON/HostJSON.rb \
|
||||
src/sunstone/models/OpenNebulaJSON/AclJSON.rb \
|
||||
src/sunstone/models/OpenNebulaJSON/VirtualNetworkJSON.rb"
|
||||
|
||||
SUNSTONE_TEMPLATE_FILES="src/sunstone/templates/login.html"
|
||||
SUNSTONE_TEMPLATE_FILES="src/sunstone/templates/login.html \
|
||||
src/sunstone/templates/login_x509.html"
|
||||
|
||||
SUNSTONE_VIEWS_FILES="src/sunstone/views/index.erb"
|
||||
|
||||
@@ -1007,6 +1015,7 @@ SUNSTONE_PUBLIC_IMAGES_FILES="src/sunstone/public/images/ajax-loader.gif \
|
||||
src/sunstone/public/images/opennebula-sunstone-big.png \
|
||||
src/sunstone/public/images/opennebula-sunstone-small.png \
|
||||
src/sunstone/public/images/panel.png \
|
||||
src/sunstone/public/images/panel_short.png \
|
||||
src/sunstone/public/images/pbar.gif \
|
||||
src/sunstone/public/images/Refresh-icon.png \
|
||||
src/sunstone/public/images/vnc_off.png \
|
||||
|
||||
@@ -21,7 +21,7 @@ include OpenNebula
|
||||
|
||||
module OpenNebulaHelper
|
||||
ONE_VERSION=<<-EOT
|
||||
OpenNebula 2.9.85
|
||||
OpenNebula 2.9.90
|
||||
Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org)
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2011, 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. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
class CloudAuth
|
||||
AUTH_MODULES = {
|
||||
"basic" => 'BasicCloudAuth',
|
||||
"ec2" => 'EC2CloudAuth',
|
||||
"x509" => 'X509CloudAuth'
|
||||
}
|
||||
|
||||
attr_reader :client, :token
|
||||
|
||||
def initialize(conf)
|
||||
@conf = conf
|
||||
|
||||
if AUTH_MODULES.include?(@conf[:auth])
|
||||
require 'CloudAuth/' + AUTH_MODULES[@conf[:auth]]
|
||||
extend Kernel.const_get(AUTH_MODULES[@conf[:auth]])
|
||||
else
|
||||
raise "Auth module not specified"
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def get_password(username)
|
||||
@oneadmin_client ||= OpenNebula::Client.new(nil, @conf[:one_xmlrpc])
|
||||
|
||||
if @user_pool.nil?
|
||||
@user_pool ||= OpenNebula::UserPool.new(@oneadmin_client)
|
||||
|
||||
rc = @user_pool.info
|
||||
if OpenNebula.is_error?(rc)
|
||||
raise rc.message
|
||||
end
|
||||
end
|
||||
|
||||
return @user_pool["USER[NAME=\"#{username}\"]/PASSWORD"]
|
||||
end
|
||||
end
|
||||
@@ -14,22 +14,27 @@
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
# OpenNebula administrator user
|
||||
USER = oneadmin
|
||||
PASSWORD = oneadmin
|
||||
module BasicCloudAuth
|
||||
def auth(env, params={})
|
||||
auth = Rack::Auth::Basic::Request.new(env)
|
||||
|
||||
# OpenNebula sever contact information
|
||||
ONE_XMLRPC=http://localhost:2633/RPC2
|
||||
if auth.provided? && auth.basic?
|
||||
username, password = auth.credentials
|
||||
|
||||
# Host and port where econe server will run
|
||||
SERVER = localhost
|
||||
PORT = 4567
|
||||
if @conf[:hash_passwords]
|
||||
password = Digest::SHA1.hexdigest(password)
|
||||
end
|
||||
|
||||
# Configuration for the image repository
|
||||
DATABASE = /images/var/econe.db
|
||||
IMAGE_DIR = /images/tmp
|
||||
|
||||
#
|
||||
# VM types allowed and its template file (inside templates directory)
|
||||
#
|
||||
VM_TYPE=[NAME=m1.small, TEMPLATE=m1.small.erb]
|
||||
one_pass = get_password(username)
|
||||
if one_pass && one_pass == password
|
||||
@token = "#{username}:#{password}"
|
||||
@client = Client.new(@token, @conf[:one_xmlrpc], false)
|
||||
return nil
|
||||
else
|
||||
return "Authentication failure"
|
||||
end
|
||||
else
|
||||
return "Basic auth not provided"
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,92 @@
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2011, 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. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
module EC2CloudAuth
|
||||
def auth(env, params={})
|
||||
username = params['AWSAccessKeyId']
|
||||
one_pass = get_password(username)
|
||||
return "Invalid credentials" unless one_pass
|
||||
|
||||
signature = case params['SignatureVersion']
|
||||
when "1" then signature_v1(params.clone,one_pass)
|
||||
when "2" then signature_v2(params.clone,one_pass,env,true,false)
|
||||
end
|
||||
|
||||
if params['Signature'] != signature
|
||||
if params['SignatureVersion']=="2"
|
||||
signature = signature_v2(params.clone,one_pass,env,false,false)
|
||||
if params['Signature'] != signature
|
||||
return "Invalid Credentials"
|
||||
end
|
||||
else
|
||||
return "Invalid Credentials"
|
||||
end
|
||||
end
|
||||
|
||||
@token = "#{username}:#{one_pass}"
|
||||
@client = Client.new(@token, @conf[:one_xmlrpc], false)
|
||||
return nil
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Calculates signature version 1
|
||||
def signature_v1(params, secret_key, digest='sha1')
|
||||
params.delete('Signature')
|
||||
req_desc = params.sort {|x,y| x[0].downcase <=> y[0].downcase}.to_s
|
||||
|
||||
digest_generator = OpenSSL::Digest::Digest.new(digest)
|
||||
digest = OpenSSL::HMAC.digest(digest_generator, secret_key, req_desc)
|
||||
b64sig = Base64.b64encode(digest)
|
||||
return b64sig.strip
|
||||
end
|
||||
|
||||
# Calculates signature version 2
|
||||
def signature_v2(params, secret_key, env, include_port=true, urlencode=true)
|
||||
params.delete('Signature')
|
||||
params.delete('file')
|
||||
|
||||
server_host = params.delete(:econe_host)
|
||||
server_port = params.delete(:econe_port)
|
||||
if include_port
|
||||
server_str = "#{server_host}:#{server_port}"
|
||||
else
|
||||
server_str = server_host
|
||||
end
|
||||
|
||||
canonical_str = AWS.canonical_string(
|
||||
params,
|
||||
server_str,
|
||||
env['REQUEST_METHOD'])
|
||||
|
||||
# Use the correct signature strength
|
||||
sha_strength = case params['SignatureMethod']
|
||||
when "HmacSHA1" then 'sha1'
|
||||
when "HmacSHA256" then 'sha256'
|
||||
else 'sha1'
|
||||
end
|
||||
|
||||
digest = OpenSSL::Digest::Digest.new(sha_strength)
|
||||
hmac = OpenSSL::HMAC.digest(digest, secret_key, canonical_str)
|
||||
b64hmac = Base64.encode64(hmac).gsub("\n","")
|
||||
|
||||
if urlencode
|
||||
return CGI::escape(b64hmac)
|
||||
else
|
||||
return b64hmac
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,108 @@
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2011, 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. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
module X509CloudAuth
|
||||
# Gets the username associated with a password
|
||||
# password:: _String_ the password
|
||||
# [return] _Hash_ with the username
|
||||
def get_username(password)
|
||||
@oneadmin_client ||= OpenNebula::Client.new(nil, @conf[:one_xmlrpc])
|
||||
|
||||
if @user_pool.nil?
|
||||
@user_pool ||= OpenNebula::UserPool.new(@oneadmin_client)
|
||||
|
||||
rc = @user_pool.info
|
||||
if OpenNebula.is_error?(rc)
|
||||
raise rc.message
|
||||
end
|
||||
end
|
||||
|
||||
username = @user_pool["USER[PASSWORD=\"#{password}\"]/NAME"]
|
||||
return username if (username != nil)
|
||||
|
||||
# Check if the DN is part of a |-separted multi-DN password
|
||||
user_elts = Array.new
|
||||
@user_pool.each {|e| user_elts << e['PASSWORD']}
|
||||
multiple_users = user_elts.select {|e| e=~ /\|/ }
|
||||
matched = nil
|
||||
multiple_users.each do |e|
|
||||
e.to_s.split('|').each do |w|
|
||||
if (w == password)
|
||||
matched=e
|
||||
break
|
||||
end
|
||||
end
|
||||
break if matched
|
||||
end
|
||||
if matched
|
||||
password = matched.to_s
|
||||
end
|
||||
|
||||
return @user_pool["USER[PASSWORD=\"#{password}\"]/NAME"]
|
||||
end
|
||||
|
||||
def auth(env, params={})
|
||||
failed = 'Authentication failed. '
|
||||
# For https, the web service should be set to include the user cert in the environment.
|
||||
cert_line = env['HTTP_SSL_CLIENT_CERT']
|
||||
cert_line = nil if cert_line == '(null)' # For Apache mod_ssl
|
||||
|
||||
# Use the https credentials for authentication
|
||||
require 'server_auth'
|
||||
while cert_line
|
||||
begin
|
||||
cert_array=cert_line.scan(/([^\s]*)\s/)
|
||||
cert_array = cert_array[2..-2]
|
||||
cert_array.unshift('-----BEGIN CERTIFICATE-----')
|
||||
cert_array.push('-----END CERTIFICATE-----')
|
||||
cert_pem = cert_array.join("\n")
|
||||
cert = OpenSSL::X509::Certificate.new(cert_pem)
|
||||
rescue
|
||||
raise failed + "Could not create X509 certificate from " + cert_line
|
||||
end
|
||||
|
||||
# Password should be DN with whitespace removed.
|
||||
subjectname = cert.subject.to_s.delete("\s")
|
||||
begin
|
||||
username = get_username(subjectname)
|
||||
rescue
|
||||
username = nil
|
||||
end
|
||||
|
||||
break if username
|
||||
|
||||
chain_dn = (!chain_dn ? "" : chain_dn) + "\n" + subjectname
|
||||
chain_index = !chain_index ? 0 : chain_index + 1
|
||||
cert_line = env["HTTP_SSL_CLIENT_CERT_CHAIN_#{chain_index}"]
|
||||
cert_line = nil if cert_line == '(null)' # For Apache mod_ssl
|
||||
end
|
||||
|
||||
if !cert_line
|
||||
msg = ""
|
||||
msg << failed
|
||||
msg << "Username not found in certificate chain "
|
||||
msg << chain_dn if chain_dn
|
||||
raise msg
|
||||
end
|
||||
|
||||
auth = ServerAuth.new
|
||||
|
||||
@token = auth.login_token(username, subjectname, 300)
|
||||
@client = Client.new(@token, @conf[:one_xmlrpc], false)
|
||||
|
||||
return nil
|
||||
end
|
||||
end
|
||||
@@ -173,7 +173,7 @@ module CloudCLI
|
||||
|
||||
def version_text
|
||||
version=<<EOT
|
||||
OpenNebula 2.9.85
|
||||
OpenNebula 2.9.90
|
||||
Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org)
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
|
||||
@@ -14,9 +14,8 @@
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
require 'Configuration'
|
||||
require 'OpenNebula'
|
||||
require 'pp'
|
||||
require 'CloudAuth'
|
||||
|
||||
##############################################################################
|
||||
# This class represents a generic Cloud Server using the OpenNebula Cloud
|
||||
@@ -28,80 +27,39 @@ class CloudServer
|
||||
# Public attributes
|
||||
##########################################################################
|
||||
attr_reader :config
|
||||
attr_reader :one_client
|
||||
|
||||
# Initializes the Cloud server based on a config file
|
||||
# config_file:: _String_ for the server. MUST include the following
|
||||
# variables:
|
||||
# USER
|
||||
# PASSWORD
|
||||
# AUTH
|
||||
# VM_TYPE
|
||||
# IMAGE_DIR
|
||||
# DATABASE
|
||||
def initialize(config_file)
|
||||
|
||||
# XMLRPC
|
||||
def initialize(config)
|
||||
# --- Load the Cloud Server configuration file ---
|
||||
@config = config
|
||||
@cloud_auth = CloudAuth.new(@config)
|
||||
end
|
||||
|
||||
@config = Configuration.new(config_file)
|
||||
def authenticate(env, params={})
|
||||
@cloud_auth.auth(env, params)
|
||||
end
|
||||
|
||||
if @config[:vm_type] == nil
|
||||
raise "No VM_TYPE defined."
|
||||
end
|
||||
|
||||
@instance_types = Hash.new
|
||||
|
||||
if @config[:vm_type].kind_of?(Array)
|
||||
@config[:vm_type].each {|type|
|
||||
@instance_types[type['NAME']]=type
|
||||
}
|
||||
else
|
||||
@instance_types[@config[:vm_type]['NAME']]=@config[:vm_type]
|
||||
end
|
||||
|
||||
# --- Start an OpenNebula Session ---
|
||||
|
||||
@one_client = Client.new(nil,@config[:one_xmlrpc])
|
||||
@user_pool = UserPool.new(@one_client)
|
||||
def client
|
||||
@cloud_auth.client
|
||||
end
|
||||
|
||||
#
|
||||
# Prints the configuration of the server
|
||||
#
|
||||
def print_configuration
|
||||
def self.print_configuration(config)
|
||||
puts "--------------------------------------"
|
||||
puts " Server configuration "
|
||||
puts "--------------------------------------"
|
||||
pp @config
|
||||
pp config
|
||||
|
||||
puts "--------------------------------------"
|
||||
puts " Registered Instance Types "
|
||||
puts "--------------------------------------"
|
||||
pp @instance_types
|
||||
STDOUT.flush
|
||||
end
|
||||
|
||||
###########################################################################
|
||||
# USER and OpenNebula Session Methods
|
||||
###########################################################################
|
||||
|
||||
# Generates an OpenNebula Session for the given user
|
||||
# user:: _Hash_ the user information
|
||||
# [return] an OpenNebula client session
|
||||
def one_client_user(name, password)
|
||||
client = Client.new("dummy:dummy")
|
||||
client.one_auth = "#{name}:#{password}"
|
||||
|
||||
return client
|
||||
end
|
||||
|
||||
# Gets the data associated with a user
|
||||
# name:: _String_ the name of the user
|
||||
# [return] _Hash_ with the user data
|
||||
def get_user_password(name)
|
||||
@user_pool.info
|
||||
return @user_pool["USER[NAME=\"#{name}\"]/PASSWORD"]
|
||||
end
|
||||
|
||||
|
||||
# Finds out if a port is available on ip
|
||||
# ip:: _String_ IP address where the port to check is
|
||||
# port:: _String_ port to find out whether is open
|
||||
@@ -123,4 +81,3 @@ class CloudServer
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,115 +0,0 @@
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2011, 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. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
###############################################################################
|
||||
# The Configuration Class represents a simple configuration file for the
|
||||
# Cloud servers. It does not check syntax.
|
||||
###############################################################################
|
||||
class Configuration
|
||||
|
||||
###########################################################################
|
||||
# Patterns to parse the Configuration File
|
||||
###########################################################################
|
||||
|
||||
NAME_REG =/[\w\d_-]+/
|
||||
VARIABLE_REG =/\s*(#{NAME_REG})\s*=\s*/
|
||||
|
||||
SIMPLE_VARIABLE_REG =/#{VARIABLE_REG}([^\[]+?)(#.*)?/
|
||||
SINGLE_VARIABLE_REG =/^#{SIMPLE_VARIABLE_REG}$/
|
||||
ARRAY_VARIABLE_REG =/^#{VARIABLE_REG}\[(.*?)\]/m
|
||||
|
||||
###########################################################################
|
||||
###########################################################################
|
||||
|
||||
def initialize(file)
|
||||
@conf=parse_conf(file)
|
||||
end
|
||||
|
||||
def add_configuration_value(key,value)
|
||||
add_value(@conf,key,value)
|
||||
end
|
||||
|
||||
def [](key)
|
||||
@conf[key.to_s.upcase]
|
||||
end
|
||||
|
||||
###########################################################################
|
||||
###########################################################################
|
||||
|
||||
private
|
||||
|
||||
#
|
||||
#
|
||||
#
|
||||
def add_value(conf, key, value)
|
||||
if conf[key]
|
||||
if !conf[key].kind_of?(Array)
|
||||
conf[key]=[conf[key]]
|
||||
end
|
||||
conf[key]<<value
|
||||
else
|
||||
conf[key]=value
|
||||
end
|
||||
end
|
||||
|
||||
#
|
||||
#
|
||||
#
|
||||
def parse_conf(file)
|
||||
conf_file=File.read(file)
|
||||
|
||||
conf=Hash.new
|
||||
|
||||
conf_file.scan(SINGLE_VARIABLE_REG) {|m|
|
||||
key=m[0].strip.upcase
|
||||
value=m[1].strip
|
||||
|
||||
# hack to skip multiline VM_TYPE values
|
||||
next if %w{NAME TEMPLATE}.include? key.upcase
|
||||
|
||||
add_value(conf, key, value)
|
||||
}
|
||||
|
||||
conf_file.scan(ARRAY_VARIABLE_REG) {|m|
|
||||
master_key=m[0].strip.upcase
|
||||
|
||||
pieces=m[1].split(',')
|
||||
|
||||
vars=Hash.new
|
||||
pieces.each {|p|
|
||||
key, value=p.split('=')
|
||||
vars[key.strip.upcase]=value.strip
|
||||
}
|
||||
|
||||
add_value(conf, master_key, vars)
|
||||
}
|
||||
|
||||
conf
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
#
|
||||
# Test program for the Configuration Parser
|
||||
#
|
||||
if $0 == __FILE__
|
||||
|
||||
require 'pp'
|
||||
|
||||
conf=Configuration.new('cloud.conf')
|
||||
pp conf
|
||||
|
||||
end
|
||||
@@ -15,14 +15,21 @@
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
# OpenNebula sever contact information
|
||||
ONE_XMLRPC=http://localhost:2633/RPC2
|
||||
:one_xmlrpc: http://localhost:2633/RPC2
|
||||
|
||||
# Host and port where econe server will run
|
||||
SERVER=<PUT HERE FQDN OF SERVER>
|
||||
PORT=4567
|
||||
:server: localhost
|
||||
:port: 4567
|
||||
|
||||
# SSL proxy that serves the API (set if is being used)
|
||||
#SSL_SERVER=fqdm.of.the.server
|
||||
#:ssl_server: fqdm.of.the.server
|
||||
|
||||
# Authentication protocol for the econe server:
|
||||
# ec2, default Acess key and Secret key scheme
|
||||
# x509, for x509 certificates based authentication
|
||||
:auth: ec2
|
||||
|
||||
# VM types allowed and its template file (inside templates directory)
|
||||
VM_TYPE=[NAME=m1.small, TEMPLATE=m1.small.erb]
|
||||
:instance_types:
|
||||
:m1.small:
|
||||
:template: m1.small.erb
|
||||
@@ -15,7 +15,6 @@
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
require 'rubygems'
|
||||
require 'sinatra'
|
||||
require 'erb'
|
||||
require 'time'
|
||||
require 'AWS'
|
||||
@@ -62,67 +61,26 @@ class EC2QueryServer < CloudServer
|
||||
|
||||
###########################################################################
|
||||
|
||||
def initialize(config_file,template,views)
|
||||
super(config_file)
|
||||
@config.add_configuration_value("TEMPLATE_LOCATION",template)
|
||||
@config.add_configuration_value("VIEWS",views)
|
||||
|
||||
if @config[:ssl_server]
|
||||
@server_host=@config[:ssl_server]
|
||||
else
|
||||
@server_host=@config[:server]
|
||||
end
|
||||
|
||||
@server_port=@config[:port]
|
||||
|
||||
print_configuration
|
||||
def initialize(config)
|
||||
super(config)
|
||||
end
|
||||
|
||||
def authenticate(env, params)
|
||||
econe_host = @config[:ssl_server]
|
||||
econe_host ||= @config[:server]
|
||||
|
||||
###########################################################################
|
||||
# Authentication functions
|
||||
###########################################################################
|
||||
econe_port = @config[:port]
|
||||
|
||||
# EC2 protocol authentication function
|
||||
# params:: of the request
|
||||
# [return] true if authenticated
|
||||
def authenticate(params,env)
|
||||
password = get_user_password(params['AWSAccessKeyId'])
|
||||
return nil if !password
|
||||
|
||||
signature = case params['SignatureVersion']
|
||||
when "1" then signature_version_1(params.clone, password)
|
||||
when "2" then signature_version_2(params,
|
||||
password,
|
||||
env,
|
||||
true,
|
||||
false)
|
||||
end
|
||||
|
||||
if params['Signature']==signature
|
||||
return one_client_user(params['AWSAccessKeyId'], password)
|
||||
else
|
||||
if params['SignatureVersion']=="2"
|
||||
signature = signature_version_2(params,
|
||||
password,
|
||||
env,
|
||||
false,
|
||||
false)
|
||||
if params['Signature']==signature
|
||||
return one_client_user(params['AWSAccessKeyId'], password)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return nil
|
||||
params.merge!({:econe_host => econe_host, :econe_port => econe_port})
|
||||
super(env, params)
|
||||
end
|
||||
|
||||
|
||||
###########################################################################
|
||||
# Repository Interface
|
||||
###########################################################################
|
||||
|
||||
def upload_image(params, one_client)
|
||||
image = ImageEC2.new(Image.build_xml, one_client, params['file'])
|
||||
def upload_image(params)
|
||||
image = ImageEC2.new(Image.build_xml, self.client, params['file'])
|
||||
|
||||
template = image.to_one_template
|
||||
if OpenNebula.is_error?(template)
|
||||
@@ -140,11 +98,11 @@ class EC2QueryServer < CloudServer
|
||||
return response.result(binding), 200
|
||||
end
|
||||
|
||||
def register_image(params, one_client)
|
||||
def register_image(params)
|
||||
# Get the Image ID
|
||||
tmp, img=params['ImageLocation'].split('-')
|
||||
|
||||
image = Image.new(Image.build_xml(img.to_i), one_client)
|
||||
image = Image.new(Image.build_xml(img.to_i), self.client)
|
||||
|
||||
# Enable the new Image
|
||||
rc = image.info
|
||||
@@ -160,9 +118,9 @@ class EC2QueryServer < CloudServer
|
||||
return response.result(binding), 200
|
||||
end
|
||||
|
||||
def describe_images(params, one_client)
|
||||
def describe_images(params)
|
||||
user_flag = OpenNebula::Pool::INFO_GROUP
|
||||
impool = ImagePool.new(one_client, user_flag)
|
||||
impool = ImagePool.new(self.client, user_flag)
|
||||
impool.info
|
||||
|
||||
erb_version = params['Version']
|
||||
@@ -175,14 +133,14 @@ class EC2QueryServer < CloudServer
|
||||
# Instance Interface
|
||||
###########################################################################
|
||||
|
||||
def run_instances(params, one_client)
|
||||
def run_instances(params)
|
||||
# Get the instance type and path
|
||||
if params['InstanceType'] != nil
|
||||
instance_type_name = params['InstanceType']
|
||||
instance_type = @instance_types[instance_type_name]
|
||||
instance_type = @config[:instance_types][instance_type_name.to_sym]
|
||||
|
||||
if instance_type != nil
|
||||
path = @config[:template_location] + "/#{instance_type['TEMPLATE']}"
|
||||
path = @config[:template_location] + "/#{instance_type[:template]}"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -201,7 +159,7 @@ class EC2QueryServer < CloudServer
|
||||
template_text = template.result(binding)
|
||||
|
||||
# Start the VM.
|
||||
vm = VirtualMachine.new(VirtualMachine.build_xml, one_client)
|
||||
vm = VirtualMachine.new(VirtualMachine.build_xml, self.client)
|
||||
|
||||
rc = vm.allocate(template_text)
|
||||
if OpenNebula::is_error?(rc)
|
||||
@@ -219,26 +177,26 @@ class EC2QueryServer < CloudServer
|
||||
return response.result(binding), 200
|
||||
end
|
||||
|
||||
def describe_instances(params, one_client)
|
||||
def describe_instances(params)
|
||||
user_flag = OpenNebula::Pool::INFO_MINE
|
||||
vmpool = VirtualMachinePool.new(one_client, user_flag)
|
||||
vmpool = VirtualMachinePool.new(self.client, user_flag)
|
||||
vmpool.info
|
||||
|
||||
erb_version = params['Version']
|
||||
erb_user_name = params['AWSAccessKeyId']
|
||||
|
||||
|
||||
response = ERB.new(File.read(@config[:views]+"/describe_instances.erb"))
|
||||
return response.result(binding), 200
|
||||
end
|
||||
|
||||
def terminate_instances(params, one_client)
|
||||
def terminate_instances(params)
|
||||
# Get the VM ID
|
||||
vmid=params['InstanceId.1']
|
||||
vmid=params['InstanceId.01'] if !vmid
|
||||
|
||||
tmp, vmid=vmid.split('-') if vmid[0]==?i
|
||||
|
||||
vm = VirtualMachine.new(VirtualMachine.build_xml(vmid),one_client)
|
||||
vm = VirtualMachine.new(VirtualMachine.build_xml(vmid),self.client)
|
||||
rc = vm.info
|
||||
|
||||
return OpenNebula::Error.new('Unsupported'),400 if OpenNebula::is_error?(rc)
|
||||
@@ -257,55 +215,6 @@ class EC2QueryServer < CloudServer
|
||||
return response.result(binding), 200
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Calculates signature version 1
|
||||
def signature_version_1(params, secret_key, digest='sha1')
|
||||
params.delete('Signature')
|
||||
req_desc = params.sort {|x,y| x[0].downcase <=> y[0].downcase}.to_s
|
||||
|
||||
digest_generator = OpenSSL::Digest::Digest.new(digest)
|
||||
digest = OpenSSL::HMAC.digest(digest_generator,
|
||||
secret_key,
|
||||
req_desc)
|
||||
b64sig = Base64.b64encode(digest)
|
||||
return b64sig.strip
|
||||
end
|
||||
|
||||
# Calculates signature version 2
|
||||
def signature_version_2(params, secret_key, env, includeport=true, urlencode=true)
|
||||
signature_params = params.reject { |key,value|
|
||||
key=='Signature' or key=='file' }
|
||||
|
||||
if includeport
|
||||
server_str = @server_host + ':' + @server_port
|
||||
else
|
||||
server_str = @server_host
|
||||
end
|
||||
|
||||
canonical_str = AWS.canonical_string(signature_params,
|
||||
server_str,
|
||||
env['REQUEST_METHOD'])
|
||||
|
||||
# Use the correct signature strength
|
||||
sha_strength = case params['SignatureMethod']
|
||||
when "HmacSHA1" then 'sha1'
|
||||
when "HmacSHA256" then 'sha256'
|
||||
else 'sha1'
|
||||
end
|
||||
|
||||
digest = OpenSSL::Digest::Digest.new(sha_strength)
|
||||
b64hmac =
|
||||
Base64.encode64(
|
||||
OpenSSL::HMAC.digest(digest, secret_key, canonical_str)).gsub("\n","")
|
||||
|
||||
if urlencode
|
||||
return CGI::escape(b64hmac)
|
||||
else
|
||||
return b64hmac
|
||||
end
|
||||
end
|
||||
|
||||
###########################################################################
|
||||
# Helper functions
|
||||
###########################################################################
|
||||
|
||||
@@ -40,39 +40,56 @@ $: << RUBY_LIB_LOCATION+"/cloud/econe"
|
||||
###############################################################################
|
||||
require 'rubygems'
|
||||
require 'sinatra'
|
||||
require 'yaml'
|
||||
|
||||
require 'EC2QueryServer'
|
||||
|
||||
include OpenNebula
|
||||
|
||||
##############################################################################
|
||||
# Parse Configuration file
|
||||
##############################################################################
|
||||
begin
|
||||
$econe_server = EC2QueryServer.new(CONFIGURATION_FILE,
|
||||
TEMPLATE_LOCATION, VIEWS_LOCATION)
|
||||
conf = YAML.load_file(CONFIGURATION_FILE)
|
||||
rescue Exception => e
|
||||
puts "Error starting server: #{e}"
|
||||
exit(-1)
|
||||
puts "Error parsing config file #{CONFIGURATION_FILE}: #{e.message}"
|
||||
exit 1
|
||||
end
|
||||
|
||||
if CloudServer.is_port_open?($econe_server.config[:server],
|
||||
$econe_server.config[:port])
|
||||
puts "Port busy, please shutdown the service or move econe server port."
|
||||
exit
|
||||
end
|
||||
conf[:template_location] = TEMPLATE_LOCATION
|
||||
conf[:views] = VIEWS_LOCATION
|
||||
|
||||
CloudServer.print_configuration(conf)
|
||||
|
||||
##############################################################################
|
||||
# Sinatra Configuration
|
||||
##############################################################################
|
||||
set :host, $econe_server.config[:server]
|
||||
set :port, $econe_server.config[:port]
|
||||
set :config, conf
|
||||
set :host, settings.config[:server]
|
||||
set :port, settings.config[:port]
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
##############################################################################
|
||||
# Actions
|
||||
##############################################################################
|
||||
|
||||
before do
|
||||
@client = $econe_server.authenticate(params,env)
|
||||
|
||||
if @client.nil?
|
||||
@econe_server = EC2QueryServer.new(settings.config)
|
||||
|
||||
begin
|
||||
result = @econe_server.authenticate(request.env, params)
|
||||
rescue Exception => e
|
||||
# Add a log message
|
||||
error 500, error_xml("AuthFailure", 0)
|
||||
end
|
||||
|
||||
if result
|
||||
# Add a log message
|
||||
error 400, error_xml("AuthFailure", 0)
|
||||
end
|
||||
end
|
||||
@@ -80,7 +97,7 @@ end
|
||||
helpers do
|
||||
def error_xml(code,id)
|
||||
message = ''
|
||||
|
||||
|
||||
case code
|
||||
when 'AuthFailure'
|
||||
message = 'User not authorized'
|
||||
@@ -88,45 +105,44 @@ helpers do
|
||||
message = 'Specified AMI ID does not exist'
|
||||
when 'Unsupported'
|
||||
message = 'The instance type or feature is not supported in your requested Availability Zone.'
|
||||
else
|
||||
else
|
||||
message = code
|
||||
end
|
||||
|
||||
|
||||
xml = "<Response><Errors><Error><Code>"+
|
||||
code +
|
||||
"</Code><Message>" +
|
||||
message +
|
||||
"</Message></Error></Errors><RequestID>" +
|
||||
id.to_s +
|
||||
code +
|
||||
"</Code><Message>" +
|
||||
message +
|
||||
"</Message></Error></Errors><RequestID>" +
|
||||
id.to_s +
|
||||
"</RequestID></Response>"
|
||||
|
||||
return xml
|
||||
end
|
||||
|
||||
return xml
|
||||
end
|
||||
end
|
||||
|
||||
post '/' do
|
||||
do_http_request(params, @client)
|
||||
do_http_request(params)
|
||||
end
|
||||
|
||||
get '/' do
|
||||
do_http_request(params, @client)
|
||||
do_http_request(params)
|
||||
end
|
||||
|
||||
def do_http_request(params, client)
|
||||
|
||||
def do_http_request(params)
|
||||
case params['Action']
|
||||
when 'UploadImage'
|
||||
result,rc = $econe_server.upload_image(params, client)
|
||||
result,rc = @econe_server.upload_image(params)
|
||||
when 'RegisterImage'
|
||||
result,rc = $econe_server.register_image(params, client)
|
||||
result,rc = @econe_server.register_image(params)
|
||||
when 'DescribeImages'
|
||||
result,rc = $econe_server.describe_images(params, client)
|
||||
result,rc = @econe_server.describe_images(params)
|
||||
when 'RunInstances'
|
||||
result,rc = $econe_server.run_instances(params, client)
|
||||
result,rc = @econe_server.run_instances(params)
|
||||
when 'DescribeInstances'
|
||||
result,rc = $econe_server.describe_instances(params, client)
|
||||
result,rc = @econe_server.describe_instances(params)
|
||||
when 'TerminateInstances'
|
||||
result,rc = $econe_server.terminate_instances(params, client)
|
||||
result,rc = @econe_server.terminate_instances(params)
|
||||
end
|
||||
|
||||
if OpenNebula::is_error?(result)
|
||||
@@ -135,5 +151,5 @@ def do_http_request(params, client)
|
||||
|
||||
headers['Content-Type'] = 'application/xml'
|
||||
|
||||
result
|
||||
result
|
||||
end
|
||||
@@ -14,21 +14,31 @@
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
# OpenNebula server contact information
|
||||
ONE_XMLRPC=http://localhost:2633/RPC2
|
||||
# OpenNebula sever contact information
|
||||
:one_xmlrpc: http://localhost:2633/RPC2
|
||||
|
||||
# Host and port where the occi server will run
|
||||
SERVER=<FQDN OF OCCI SERVER>
|
||||
PORT=4567
|
||||
# Host and port where OCCI server will run
|
||||
:server: localhost
|
||||
:port: 4567
|
||||
|
||||
# SSL proxy that serves the API (set if is being used)
|
||||
#SSL_SERVER=https://localhost:443
|
||||
#:ssl_server: fqdm.of.the.server
|
||||
|
||||
# Configuration for OpenNebula's Virtual Networks
|
||||
BRIDGE=<NAME OF DEFAULT BRIDGE>
|
||||
#:bridge: NAME_OF_DEFAULT_BRIDGE
|
||||
|
||||
# Authentication protocol for the OCCI server:
|
||||
# basic, for OpenNebula's user-password scheme
|
||||
# x509, for x509 certificates based authentication
|
||||
:auth: basic
|
||||
|
||||
# VM types allowed and its template file (inside templates directory)
|
||||
VM_TYPE=[NAME=custom, TEMPLATE=custom.erb]
|
||||
VM_TYPE=[NAME=small, TEMPLATE=small.erb]
|
||||
VM_TYPE=[NAME=medium, TEMPLATE=medium.erb]
|
||||
VM_TYPE=[NAME=large, TEMPLATE=large.erb]
|
||||
:instance_types:
|
||||
:custom:
|
||||
:template: custom.erb
|
||||
:small:
|
||||
:template: small.erb
|
||||
:medium:
|
||||
:template: medium.erb
|
||||
:large:
|
||||
:template: large.erb
|
||||
@@ -15,12 +15,9 @@
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
# Common cloud libs
|
||||
require 'rubygems'
|
||||
require 'sinatra'
|
||||
require 'CloudServer'
|
||||
|
||||
# OCA
|
||||
require 'OpenNebula'
|
||||
include OpenNebula
|
||||
|
||||
# OCCI libs
|
||||
@@ -43,29 +40,13 @@ class OCCIServer < CloudServer
|
||||
# Server initializer
|
||||
# config_file:: _String_ path of the config file
|
||||
# template:: _String_ path to the location of the templates
|
||||
def initialize(config_file,template)
|
||||
super(config_file)
|
||||
def initialize(config)
|
||||
super(config)
|
||||
|
||||
@config.add_configuration_value("TEMPLATE_LOCATION",template)
|
||||
|
||||
if @config[:ssl_server]
|
||||
@base_url=@config[:ssl_server]
|
||||
if config[:ssl_server]
|
||||
@base_url=config[:ssl_server]
|
||||
else
|
||||
@base_url="http://#{@config[:server]}:#{@config[:port]}"
|
||||
end
|
||||
|
||||
print_configuration
|
||||
end
|
||||
|
||||
# Retrieve a client with the user credentials
|
||||
# requestenv:: _Hash_ Hash containing the environment of the request
|
||||
# [return] _Client_ client with the user credentials
|
||||
def get_client(requestenv)
|
||||
auth = Rack::Auth::Basic::Request.new(requestenv)
|
||||
if auth
|
||||
return one_client_user(auth.credentials[0], auth.credentials[1])
|
||||
else
|
||||
return nil
|
||||
@base_url="http://#{config[:server]}:#{config[:port]}"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -92,13 +73,8 @@ class OCCIServer < CloudServer
|
||||
# --- Get User's VMs ---
|
||||
user_flag = -1
|
||||
|
||||
one_client = get_client(request.env)
|
||||
if !one_client
|
||||
return "No authorization data present", 401
|
||||
end
|
||||
|
||||
vmpool = VirtualMachinePoolOCCI.new(
|
||||
one_client,
|
||||
self.client,
|
||||
user_flag)
|
||||
|
||||
# --- Prepare XML Response ---
|
||||
@@ -124,13 +100,8 @@ class OCCIServer < CloudServer
|
||||
# --- Get User's VNETs ---
|
||||
user_flag = -1
|
||||
|
||||
one_client = get_client(request.env)
|
||||
if !one_client
|
||||
return "No authorization data present", 401
|
||||
end
|
||||
|
||||
network_pool = VirtualNetworkPoolOCCI.new(
|
||||
one_client,
|
||||
self.client,
|
||||
user_flag)
|
||||
|
||||
# --- Prepare XML Response ---
|
||||
@@ -155,13 +126,8 @@ class OCCIServer < CloudServer
|
||||
# --- Get User's Images ---
|
||||
user_flag = -1
|
||||
|
||||
one_client = get_client(request.env)
|
||||
if !one_client
|
||||
return "No authorization data present", 401
|
||||
end
|
||||
|
||||
image_pool = ImagePoolOCCI.new(
|
||||
one_client,
|
||||
self.client,
|
||||
user_flag)
|
||||
|
||||
# --- Prepare XML Response ---
|
||||
@@ -193,16 +159,11 @@ class OCCIServer < CloudServer
|
||||
# [return] _String_,_Integer_ COMPUTE Representation or error, status code
|
||||
def post_compute(request)
|
||||
# --- Create the new Instance ---
|
||||
one_client = get_client(request.env)
|
||||
if !one_client
|
||||
return "No authorization data present", 401
|
||||
end
|
||||
|
||||
vm = VirtualMachineOCCI.new(
|
||||
VirtualMachine.build_xml,
|
||||
one_client,
|
||||
self.client,
|
||||
request.body.read,
|
||||
@instance_types,
|
||||
@config[:instance_types],
|
||||
@config[:template_location])
|
||||
|
||||
# --- Generate the template and Allocate the new Instance ---
|
||||
@@ -223,14 +184,9 @@ class OCCIServer < CloudServer
|
||||
# status code
|
||||
def get_compute(request, params)
|
||||
# --- Get the VM ---
|
||||
one_client = get_client(request.env)
|
||||
if !one_client
|
||||
return "No authorization data present", 401
|
||||
end
|
||||
|
||||
vm = VirtualMachineOCCI.new(
|
||||
VirtualMachine.build_xml(params[:id]),
|
||||
one_client)
|
||||
self.client)
|
||||
|
||||
# --- Prepare XML Response ---
|
||||
rc = vm.info
|
||||
@@ -253,14 +209,9 @@ class OCCIServer < CloudServer
|
||||
# status code
|
||||
def delete_compute(request, params)
|
||||
# --- Get the VM ---
|
||||
one_client = get_client(request.env)
|
||||
if !one_client
|
||||
return "No authorization data present", 401
|
||||
end
|
||||
|
||||
vm = VirtualMachineOCCI.new(
|
||||
VirtualMachine.build_xml(params[:id]),
|
||||
one_client)
|
||||
self.client)
|
||||
|
||||
rc = vm.info
|
||||
return rc, 404 if OpenNebula::is_error?(rc)
|
||||
@@ -278,14 +229,9 @@ class OCCIServer < CloudServer
|
||||
# status code
|
||||
def put_compute(request, params)
|
||||
# --- Get the VM ---
|
||||
one_client = get_client(request.env)
|
||||
if !one_client
|
||||
return "No authorization data present", 401
|
||||
end
|
||||
|
||||
vm = VirtualMachineOCCI.new(
|
||||
VirtualMachine.build_xml(params[:id]),
|
||||
one_client)
|
||||
self.client)
|
||||
|
||||
rc = vm.info
|
||||
return rc, 400 if OpenNebula.is_error?(rc)
|
||||
@@ -325,20 +271,7 @@ class OCCIServer < CloudServer
|
||||
return OpenNebula::Error.new(error_msg), 400
|
||||
end
|
||||
|
||||
# Create a new Image to save the disk
|
||||
template = "NAME=\"#{image_name}\"\n"
|
||||
if image_type
|
||||
template << "TYPE=\"#{image_type}\"\n"
|
||||
else
|
||||
template << "TYPE=\"OS\"\n"
|
||||
end
|
||||
|
||||
image = Image.new(Image.build_xml, one_client)
|
||||
|
||||
rc = image.allocate(template)
|
||||
return rc, 400 if OpenNebula.is_error?(rc)
|
||||
|
||||
rc = vm.save_as(disk_id, image.id)
|
||||
rc = vm.save_as(disk_id, image_name)
|
||||
if OpenNebula.is_error?(rc)
|
||||
image.delete
|
||||
return rc, 400
|
||||
@@ -362,14 +295,9 @@ class OCCIServer < CloudServer
|
||||
# [return] _String_,_Integer_ Network Representation or error, status code
|
||||
def post_network(request)
|
||||
# --- Create the new Instance ---
|
||||
one_client = get_client(request.env)
|
||||
if !one_client
|
||||
return "No authorization data present", 401
|
||||
end
|
||||
|
||||
network = VirtualNetworkOCCI.new(
|
||||
VirtualNetwork.build_xml,
|
||||
one_client,
|
||||
self.client,
|
||||
request.body,
|
||||
@config[:bridge])
|
||||
|
||||
@@ -390,15 +318,9 @@ class OCCIServer < CloudServer
|
||||
# [return] _String_,_Integer_ NETWORK occi representation or error,
|
||||
# status code
|
||||
def get_network(request, params)
|
||||
# --- Get the VNET ---
|
||||
one_client = get_client(request.env)
|
||||
if !one_client
|
||||
return "No authorization data present", 401
|
||||
end
|
||||
|
||||
network = VirtualNetworkOCCI.new(
|
||||
VirtualNetwork.build_xml(params[:id]),
|
||||
one_client)
|
||||
self.client)
|
||||
|
||||
# --- Prepare XML Response ---
|
||||
rc = network.info
|
||||
@@ -419,15 +341,9 @@ class OCCIServer < CloudServer
|
||||
# [return] _String_,_Integer_ Delete confirmation msg or error,
|
||||
# status code
|
||||
def delete_network(request, params)
|
||||
# --- Get the VNET ---
|
||||
one_client = get_client(request.env)
|
||||
if !one_client
|
||||
return "No authorization data present", 401
|
||||
end
|
||||
|
||||
network = VirtualNetworkOCCI.new(
|
||||
VirtualNetwork.build_xml(params[:id]),
|
||||
one_client)
|
||||
self.client)
|
||||
|
||||
rc = network.info
|
||||
return rc, 404 if OpenNebula::is_error?(rc)
|
||||
@@ -446,15 +362,10 @@ class OCCIServer < CloudServer
|
||||
def put_network(request, params)
|
||||
xmldoc = XMLElement.build_xml(request.body, 'NETWORK')
|
||||
vnet_info = XMLElement.new(xmldoc) if xmldoc != nil
|
||||
|
||||
one_client = get_client(request.env)
|
||||
if !one_client
|
||||
return "No authorization data present", 401
|
||||
end
|
||||
|
||||
vnet = VirtualNetworkOCCI.new(
|
||||
VirtualNetwork.build_xml(params[:id]),
|
||||
one_client)
|
||||
self.client)
|
||||
|
||||
rc = vnet.info
|
||||
return rc, 400 if OpenNebula.is_error?(rc)
|
||||
@@ -487,11 +398,6 @@ class OCCIServer < CloudServer
|
||||
error = OpenNebula::Error.new(error_msg)
|
||||
return error, 400
|
||||
end
|
||||
|
||||
one_client = get_client(request.env)
|
||||
if !one_client
|
||||
return "No authorization data present", 401
|
||||
end
|
||||
|
||||
# --- Create and Add the new Image ---
|
||||
occixml = request.params['occixml']
|
||||
@@ -499,7 +405,7 @@ class OCCIServer < CloudServer
|
||||
|
||||
image = ImageOCCI.new(
|
||||
Image.build_xml,
|
||||
one_client,
|
||||
self.client,
|
||||
occixml,
|
||||
request.params['file'])
|
||||
|
||||
@@ -521,14 +427,9 @@ class OCCIServer < CloudServer
|
||||
# status code
|
||||
def get_storage(request, params)
|
||||
# --- Get the Image ---
|
||||
one_client = get_client(request.env)
|
||||
if !one_client
|
||||
return "No authorization data present", 401
|
||||
end
|
||||
|
||||
image = ImageOCCI.new(
|
||||
Image.build_xml(params[:id]),
|
||||
one_client)
|
||||
self.client)
|
||||
|
||||
rc = image.info
|
||||
|
||||
@@ -550,14 +451,9 @@ class OCCIServer < CloudServer
|
||||
# status code
|
||||
def delete_storage(request, params)
|
||||
# --- Get the Image ---
|
||||
one_client = get_client(request.env)
|
||||
if !one_client
|
||||
return "No authorization data present", 401
|
||||
end
|
||||
|
||||
image = ImageOCCI.new(
|
||||
Image.build_xml(params[:id]),
|
||||
one_client)
|
||||
self.client)
|
||||
|
||||
rc = image.info
|
||||
return rc, 404 if OpenNebula::is_error?(rc)
|
||||
@@ -576,15 +472,10 @@ class OCCIServer < CloudServer
|
||||
def put_storage(request, params)
|
||||
xmldoc = XMLElement.build_xml(request.body, 'STORAGE')
|
||||
image_info = XMLElement.new(xmldoc) if xmldoc != nil
|
||||
|
||||
one_client = get_client(request.env)
|
||||
if !one_client
|
||||
return "No authorization data present", 401
|
||||
end
|
||||
|
||||
image = ImageOCCI.new(
|
||||
Image.build_xml(params[:id]),
|
||||
one_client)
|
||||
self.client)
|
||||
|
||||
rc = image.info
|
||||
return rc, 400 if OpenNebula.is_error?(rc)
|
||||
|
||||
@@ -77,8 +77,8 @@ class VirtualMachineOCCI < VirtualMachine
|
||||
if @vm_info != nil
|
||||
itype = @vm_info['INSTANCE_TYPE']
|
||||
|
||||
if itype != nil and types[itype] != nil
|
||||
@template = base + "/#{types[itype]['TEMPLATE']}"
|
||||
if itype != nil and types[itype.to_sym] != nil
|
||||
@template = base + "/#{types[itype.to_sym][:template]}"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -43,35 +43,57 @@ $: << RUBY_LIB_LOCATION+"/cloud" # For the Repository Manager
|
||||
################################################
|
||||
require 'rubygems'
|
||||
require 'sinatra'
|
||||
require 'OCCIServer'
|
||||
require 'yaml'
|
||||
|
||||
require 'OpenNebula'
|
||||
require 'OCCIServer'
|
||||
|
||||
include OpenNebula
|
||||
|
||||
##############################################################################
|
||||
# Parse Configuration file
|
||||
##############################################################################
|
||||
begin
|
||||
$occi_server = OCCIServer.new(CONFIGURATION_FILE, TEMPLATE_LOCATION)
|
||||
conf = YAML.load_file(CONFIGURATION_FILE)
|
||||
rescue Exception => e
|
||||
puts "Error starting server: #{e}"
|
||||
exit(-1)
|
||||
puts "Error parsing config file #{CONFIGURATION_FILE}: #{e.message}"
|
||||
exit 1
|
||||
end
|
||||
|
||||
if CloudServer.is_port_open?($occi_server.config[:server],
|
||||
$occi_server.config[:port])
|
||||
puts "Port busy, please shutdown the service or move occi server port."
|
||||
exit
|
||||
end
|
||||
conf[:template_location] = TEMPLATE_LOCATION
|
||||
|
||||
CloudServer.print_configuration(conf)
|
||||
|
||||
##############################################################################
|
||||
# Sinatra Configuration
|
||||
##############################################################################
|
||||
set :host, $occi_server.config[:server]
|
||||
set :port, $occi_server.config[:port]
|
||||
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
|
||||
end
|
||||
|
||||
set :host, settings.config[:server]
|
||||
set :port, settings.config[:port]
|
||||
|
||||
##############################################################################
|
||||
# Helpers
|
||||
##############################################################################
|
||||
|
||||
before do
|
||||
@occi_server = OCCIServer.new(settings.config)
|
||||
begin
|
||||
result = @occi_server.authenticate(request.env)
|
||||
rescue Exception => e
|
||||
error 500, e.message
|
||||
end
|
||||
|
||||
if result
|
||||
error 401, result
|
||||
end
|
||||
end
|
||||
|
||||
# Response treatment
|
||||
helpers do
|
||||
def treat_response(result,rc)
|
||||
@@ -93,32 +115,32 @@ end
|
||||
###################################################
|
||||
|
||||
post '/compute' do
|
||||
result,rc = $occi_server.post_compute(request)
|
||||
result,rc = @occi_server.post_compute(request)
|
||||
treat_response(result,rc)
|
||||
end
|
||||
|
||||
get '/compute' do
|
||||
result,rc = $occi_server.get_computes(request)
|
||||
result,rc = @occi_server.get_computes(request)
|
||||
treat_response(result,rc)
|
||||
end
|
||||
|
||||
post '/network' do
|
||||
result,rc = $occi_server.post_network(request)
|
||||
result,rc = @occi_server.post_network(request)
|
||||
treat_response(result,rc)
|
||||
end
|
||||
|
||||
get '/network' do
|
||||
result,rc = $occi_server.get_networks(request)
|
||||
result,rc = @occi_server.get_networks(request)
|
||||
treat_response(result,rc)
|
||||
end
|
||||
|
||||
post '/storage' do
|
||||
result,rc = $occi_server.post_storage(request)
|
||||
result,rc = @occi_server.post_storage(request)
|
||||
treat_response(result,rc)
|
||||
end
|
||||
|
||||
get '/storage' do
|
||||
result,rc = $occi_server.get_storages(request)
|
||||
result,rc = @occi_server.get_storages(request)
|
||||
treat_response(result,rc)
|
||||
end
|
||||
|
||||
@@ -127,46 +149,46 @@ end
|
||||
###################################################
|
||||
|
||||
get '/compute/:id' do
|
||||
result,rc = $occi_server.get_compute(request, params)
|
||||
result,rc = @occi_server.get_compute(request, params)
|
||||
treat_response(result,rc)
|
||||
end
|
||||
|
||||
delete '/compute/:id' do
|
||||
result,rc = $occi_server.delete_compute(request, params)
|
||||
result,rc = @occi_server.delete_compute(request, params)
|
||||
treat_response(result,rc)
|
||||
end
|
||||
|
||||
put '/compute/:id' do
|
||||
result,rc = $occi_server.put_compute(request, params)
|
||||
result,rc = @occi_server.put_compute(request, params)
|
||||
treat_response(result,rc)
|
||||
end
|
||||
|
||||
get '/network/:id' do
|
||||
result,rc = $occi_server.get_network(request, params)
|
||||
result,rc = @occi_server.get_network(request, params)
|
||||
treat_response(result,rc)
|
||||
end
|
||||
|
||||
delete '/network/:id' do
|
||||
result,rc = $occi_server.delete_network(request, params)
|
||||
result,rc = @occi_server.delete_network(request, params)
|
||||
treat_response(result,rc)
|
||||
end
|
||||
|
||||
put '/network/:id' do
|
||||
result,rc = $occi_server.put_network(request, params)
|
||||
result,rc = @occi_server.put_network(request, params)
|
||||
treat_response(result,rc)
|
||||
end
|
||||
|
||||
get '/storage/:id' do
|
||||
result,rc = $occi_server.get_storage(request, params)
|
||||
result,rc = @occi_server.get_storage(request, params)
|
||||
treat_response(result,rc)
|
||||
end
|
||||
|
||||
delete '/storage/:id' do
|
||||
result,rc = $occi_server.delete_storage(request, params)
|
||||
result,rc = @occi_server.delete_storage(request, params)
|
||||
treat_response(result,rc)
|
||||
end
|
||||
|
||||
put '/storage/:id' do
|
||||
result,rc = $occi_server.put_storage(request, params)
|
||||
result,rc = @occi_server.put_storage(request, params)
|
||||
treat_response(result,rc)
|
||||
end
|
||||
@@ -15,25 +15,26 @@
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
# Paths for utilities
|
||||
export PATH=/bin:/sbin:/usr/bin:$PATH
|
||||
AWK=awk
|
||||
BASH=/bin/bash
|
||||
BASH=bash
|
||||
CUT=cut
|
||||
DATE=/bin/date
|
||||
DD=/bin/dd
|
||||
DU=/usr/bin/du
|
||||
LVCREATE=/sbin/lvcreate
|
||||
LVREMOVE=/sbin/lvremove
|
||||
LVS=/sbin/lvs
|
||||
MD5SUM=/usr/bin/md5sum
|
||||
MKFS=/sbin/mkfs
|
||||
MKISOFS=/usr/bin/mkisofs
|
||||
MKSWAP=/sbin/mkswap
|
||||
SCP=/usr/bin/scp
|
||||
SED=/bin/sed
|
||||
SSH=/usr/bin/ssh
|
||||
SUDO=/usr/bin/sudo
|
||||
WGET=/usr/bin/wget
|
||||
READLINK=/bin/readlink
|
||||
DATE=date
|
||||
DD=dd
|
||||
DU=du
|
||||
LVCREATE=lvcreate
|
||||
LVREMOVE=lvremove
|
||||
LVS=lvs
|
||||
MD5SUM=md5sum
|
||||
MKFS=mkfs
|
||||
MKISOFS=mkisofs
|
||||
MKSWAP=mkswap
|
||||
SCP=scp
|
||||
SED=sed
|
||||
SSH=ssh
|
||||
SUDO=sudo
|
||||
WGET=wget
|
||||
READLINK=readlink
|
||||
|
||||
# Used for log messages
|
||||
SCRIPT_NAME=`basename $0`
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
# -------------------------------------------------------------------------- *
|
||||
# Copyright 2002-2011, 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. *
|
||||
# -------------------------------------------------------------------------- *
|
||||
|
||||
require "rexml/document"
|
||||
include REXML
|
||||
|
||||
module Migrator
|
||||
def db_version
|
||||
"2.9.90"
|
||||
end
|
||||
|
||||
def one_version
|
||||
"OpenNebula 2.9.90"
|
||||
end
|
||||
|
||||
def up
|
||||
return true
|
||||
end
|
||||
end
|
||||
@@ -182,17 +182,27 @@ sleep 3s
|
||||
|
||||
mkdir -p results/xml_files
|
||||
|
||||
for obj in host vnet image vm user; do
|
||||
for obj in vnet image vm; do
|
||||
one$obj list a -x > results/xml_files/$obj-pool.xml
|
||||
done
|
||||
|
||||
for obj in host user; do
|
||||
one$obj list -x > results/xml_files/$obj-pool.xml
|
||||
done
|
||||
|
||||
for obj in host vnet image vm user; do
|
||||
for i in 0 1 2 3 4; do
|
||||
one$obj show -x $i > results/xml_files/$obj-$i.xml
|
||||
done
|
||||
done
|
||||
|
||||
if [ $TWO_SERIES == "no" ]; then
|
||||
oneacl list a -x > results/xml_files/acl-pool.xml
|
||||
onegroup list a -x > results/xml_files/group-pool.xml
|
||||
oneacl list -x > results/xml_files/acl-pool.xml
|
||||
onegroup list -x > results/xml_files/group-pool.xml
|
||||
|
||||
for i in 0 1; do
|
||||
onegroup show -x $i > results/xml_files/group-$i.xml
|
||||
done
|
||||
fi
|
||||
|
||||
# Clean one auth files
|
||||
|
||||
@@ -57,13 +57,28 @@ pkill -9 -P $PID oned
|
||||
echo "All resources created, now 2.2 DB will be upgraded."
|
||||
|
||||
# dump current DB and schema
|
||||
onedb backup results/mysqldb.3.0
|
||||
onedb backup results/mysqldb.3.0 -v
|
||||
if [ $? -ne 0 ]; then
|
||||
exit -1
|
||||
fi
|
||||
|
||||
mysqldump -u oneadmin -poneadmin -h localhost -P 0 --no-data onedb_test > results/mysqldb.3.0.tmpschema
|
||||
if [ $? -ne 0 ]; then
|
||||
exit -1
|
||||
fi
|
||||
|
||||
# restore 2.2
|
||||
onedb restore -f 2.2/mysqldb.sql
|
||||
onedb restore -v -f 2.2/mysqldb.sql
|
||||
if [ $? -ne 0 ]; then
|
||||
exit -1
|
||||
fi
|
||||
|
||||
# upgrade
|
||||
onedb upgrade -v --backup results/mysqldb.backup
|
||||
if [ $? -ne 0 ]; then
|
||||
exit -1
|
||||
fi
|
||||
|
||||
# dump upgraded DB schema
|
||||
mysqldump -u oneadmin -poneadmin -h localhost -P 0 --no-data onedb_test > results/mysqldb.upgraded.tmpschema
|
||||
|
||||
@@ -104,10 +119,18 @@ for obj in host vnet image vm user; do
|
||||
done
|
||||
done
|
||||
|
||||
for obj in host vnet image vm acl group user; do
|
||||
for i in 0 1; do
|
||||
onegroup show -x $i > results/xml_files/group-$i-upgraded.xml
|
||||
done
|
||||
|
||||
|
||||
for obj in vnet image vm; do
|
||||
one$obj list a -x > results/xml_files/$obj-pool-upgraded.xml
|
||||
done
|
||||
|
||||
for obj in host acl group user; do
|
||||
one$obj list -x > results/xml_files/$obj-pool-upgraded.xml
|
||||
done
|
||||
|
||||
pkill -P $PID oned
|
||||
sleep 2s;
|
||||
@@ -117,11 +140,8 @@ echo "XML output collected. A diff will be performed."
|
||||
|
||||
mkdir results/diff_files
|
||||
|
||||
diff <(grep -v -e "<LAST_MON_TIME>" -e "<CLUSTER>" -e "NAME>" results/xml_files/host-pool.xml) <(grep -v -e "<LAST_MON_TIME>" -e "<CLUSTER>" -e "NAME>" results/xml_files/host-pool-upgraded.xml) > results/diff_files/host-pool.diff
|
||||
|
||||
# TODO: fix
|
||||
# The image-pool.xml files are the same, but for some reason the Images are
|
||||
# returned in different order.
|
||||
# TODO: fix. The pool elements are returned in different order.
|
||||
#diff <(grep -v -e "<LAST_MON_TIME>" -e "<CLUSTER>" -e "NAME>" results/xml_files/host-pool.xml) <(grep -v -e "<LAST_MON_TIME>" -e "<CLUSTER>" -e "NAME>" results/xml_files/host-pool-upgraded.xml) > results/diff_files/host-pool.diff
|
||||
#diff <(grep -v -e "<REGTIME>" -e "<SOURCE>" -e "<SIZE>" results/xml_files/image-pool.xml) <(grep -v -e "<REGTIME>" -e "<SOURCE>" -e "<SIZE>" results/xml_files/image-pool-upgraded.xml) > results/diff_files/image-pool.diff
|
||||
|
||||
diff <(grep -v -e "<LAST_POLL>" -e "TIME>" -e "<SOURCE>" -e "<TEMPLATE_ID>" -e "<VM_DIR>" results/xml_files/vm-pool.xml) <(grep -v -e "<LAST_POLL>" -e "TIME>" -e "<SOURCE>" -e "<TEMPLATE_ID>" -e "<VM_DIR>" results/xml_files/vm-pool-upgraded.xml) > results/diff_files/vm-pool.diff
|
||||
@@ -142,6 +162,9 @@ for i in 0 1 2 3 4; do
|
||||
diff <(cat results/xml_files/user-$i.xml) <(cat results/xml_files/user-$i-upgraded.xml) > results/diff_files/user-$i.diff
|
||||
done
|
||||
|
||||
for i in 0 1; do
|
||||
diff <(cat results/xml_files/group-$i.xml) <(cat results/xml_files/group-$i-upgraded.xml) > results/diff_files/group-$i.diff
|
||||
done
|
||||
|
||||
CODE=0
|
||||
|
||||
@@ -155,6 +178,14 @@ for obj in host vnet image vm user; do
|
||||
done
|
||||
done
|
||||
|
||||
for i in 0 1; do
|
||||
FILE=results/diff_files/group-$i.diff
|
||||
if [[ -s $FILE ]] ; then
|
||||
echo "Error: diff file $FILE is not empty."
|
||||
CODE=-1
|
||||
fi
|
||||
done
|
||||
|
||||
for obj in host vnet image vm acl group user; do
|
||||
FILE=results/diff_files/$obj-pool.diff
|
||||
if [[ -s $FILE ]] ; then
|
||||
|
||||
@@ -63,6 +63,10 @@ cp 2.2/one.db results/one.db.upgraded
|
||||
|
||||
onedb upgrade -v --sqlite results/one.db.upgraded --backup results/one.db.backup
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
exit -1
|
||||
fi
|
||||
|
||||
echo "Done. Upgraded DB and the one just created will be compared."
|
||||
|
||||
# Dump both DB schemas
|
||||
@@ -106,10 +110,18 @@ for obj in host vnet image vm user; do
|
||||
done
|
||||
done
|
||||
|
||||
for obj in host vnet image vm acl group user; do
|
||||
for i in 0 1; do
|
||||
onegroup show -x $i > results/xml_files/group-$i-upgraded.xml
|
||||
done
|
||||
|
||||
|
||||
for obj in vnet image vm; do
|
||||
one$obj list a -x > results/xml_files/$obj-pool-upgraded.xml
|
||||
done
|
||||
|
||||
for obj in host acl group user; do
|
||||
one$obj list -x > results/xml_files/$obj-pool-upgraded.xml
|
||||
done
|
||||
|
||||
pkill -P $PID oned
|
||||
sleep 2s;
|
||||
@@ -139,6 +151,9 @@ for i in 0 1 2 3 4; do
|
||||
diff <(cat results/xml_files/user-$i.xml) <(cat results/xml_files/user-$i-upgraded.xml) > results/diff_files/user-$i.diff
|
||||
done
|
||||
|
||||
for i in 0 1; do
|
||||
diff <(cat results/xml_files/group-$i.xml) <(cat results/xml_files/group-$i-upgraded.xml) > results/diff_files/group-$i.diff
|
||||
done
|
||||
|
||||
CODE=0
|
||||
|
||||
@@ -152,6 +167,14 @@ for obj in host vnet image vm user; do
|
||||
done
|
||||
done
|
||||
|
||||
for i in 0 1; do
|
||||
FILE=results/diff_files/group-$i.diff
|
||||
if [[ -s $FILE ]] ; then
|
||||
echo "Error: diff file $FILE is not empty."
|
||||
CODE=-1
|
||||
fi
|
||||
done
|
||||
|
||||
for obj in host vnet image vm acl group user; do
|
||||
FILE=results/diff_files/$obj-pool.diff
|
||||
if [[ -s $FILE ]] ; then
|
||||
|
||||
@@ -26,7 +26,14 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
# Global Options
|
||||
########################################################################
|
||||
set :option, CommandParser::OPTIONS
|
||||
|
||||
|
||||
FORCE={
|
||||
:name => "force",
|
||||
:short => "-f",
|
||||
:large => "--force",
|
||||
:description => "Force the usage of Hosts in more than one VDC"
|
||||
}
|
||||
|
||||
begin
|
||||
helper = VDCHelper.new "vdc"
|
||||
rescue Exception => e
|
||||
@@ -34,8 +41,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
exit -1
|
||||
end
|
||||
|
||||
command :create, 'Create a new VDC', :file do
|
||||
helper.create_resource(args[0])
|
||||
command :create, 'Create a new VDC', :file, :options=>[FORCE] do
|
||||
helper.create_resource(args[0], options)
|
||||
end
|
||||
|
||||
command :show, 'Show information of a particular VDC', :vdcid do
|
||||
@@ -50,4 +57,14 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
command :delete, 'Deletes a VDC', :vdcid do
|
||||
helper.delete_resource(args[0],options)
|
||||
end
|
||||
|
||||
command :addhost, 'Adds the set of hosts to the VDC',
|
||||
:vdcid, :range, :options=>[FORCE] do
|
||||
helper.addhost(args[0], args[1], options)
|
||||
end
|
||||
|
||||
command :delhost, 'Deletes the set of hosts from the VDC',
|
||||
:vdcid, :range, :options=>[FORCE] do
|
||||
helper.delhost(args[0], args[1], options)
|
||||
end
|
||||
end
|
||||
@@ -1,5 +1,21 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2011, 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. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
ONE_LOCATION=ENV["ONE_LOCATION"]
|
||||
|
||||
if !ONE_LOCATION
|
||||
|
||||
@@ -90,19 +90,14 @@ EOT
|
||||
# :zonetemplate
|
||||
######################################################################
|
||||
def post_resource(kind, template)
|
||||
template=File.read(template)
|
||||
|
||||
body_str = ""
|
||||
|
||||
template.strip.each_line{|line|
|
||||
line.strip!
|
||||
key,value = line.split("=")
|
||||
body_str = body_str + key + "=" + URI.escape(value) + "&"
|
||||
}
|
||||
tmpl_str = File.read(template)
|
||||
post_resource_str(kind, tmpl_str)
|
||||
end
|
||||
|
||||
body_str = body_str[0..-1]
|
||||
|
||||
url = URI.parse(@endpoint+"/"+kind)
|
||||
def post_resource_str(kind, tmpl_str)
|
||||
body_str = OZonesClient::to_body(tmpl_str)
|
||||
|
||||
url = URI.parse("#{@endpoint}/#{kind}")
|
||||
|
||||
req = Net::HTTP::Post.new(url.path)
|
||||
req.body=body_str
|
||||
@@ -116,9 +111,25 @@ EOT
|
||||
return OZonesClient::parse_error(res, kind)
|
||||
end
|
||||
|
||||
def put_resource(kind, id, tmpl_str)
|
||||
body_str = OZonesClient::to_body(tmpl_str)
|
||||
|
||||
url = URI.parse("#{@endpoint}/#{kind}/#{id}")
|
||||
|
||||
req = Net::HTTP::Put.new(url.path)
|
||||
req.body=body_str
|
||||
|
||||
req.basic_auth @ozonesauth[0], @ozonesauth[1]
|
||||
|
||||
res = OZonesClient::http_start(url, @timeout) do |http|
|
||||
http.request(req)
|
||||
end
|
||||
|
||||
return OZonesClient::parse_error(res, kind)
|
||||
end
|
||||
|
||||
def get_resource(kind, id)
|
||||
url = URI.parse(@endpoint+"/#{kind}/" + id.to_s)
|
||||
url = URI.parse("#{@endpoint}/#{kind}/#{id}")
|
||||
req = Net::HTTP::Get.new(url.path)
|
||||
|
||||
req.basic_auth @ozonesauth[0], @ozonesauth[1]
|
||||
@@ -131,7 +142,7 @@ EOT
|
||||
end
|
||||
|
||||
def delete_resource(kind, id)
|
||||
url = URI.parse(@endpoint+"/#{kind}/" + id.to_s)
|
||||
url = URI.parse("#{@endpoint}/#{kind}/#{id}")
|
||||
req = Net::HTTP::Delete.new(url.path)
|
||||
|
||||
req.basic_auth @ozonesauth[0], @ozonesauth[1]
|
||||
@@ -169,10 +180,7 @@ EOT
|
||||
end
|
||||
|
||||
def self.is_http_error?(value)
|
||||
value.class == Net::HTTPInternalServerError ||
|
||||
value.class == Net::HTTPBadRequest ||
|
||||
value.class == Net::HTTPNotFound ||
|
||||
value.class == Net::HTTPUnauthorized
|
||||
value.class != Net::HTTPOK
|
||||
end
|
||||
|
||||
def self.parse_error(value, kind)
|
||||
@@ -237,8 +245,20 @@ EOT
|
||||
end
|
||||
|
||||
##########################################################################
|
||||
# JSON utils
|
||||
# JSON & Template utils
|
||||
##########################################################################
|
||||
|
||||
def self.to_body(tmpl_str)
|
||||
body_str = ""
|
||||
|
||||
tmpl_str.strip.each_line{|line|
|
||||
line.strip!
|
||||
key,value = line.split("=")
|
||||
body_str = body_str + key + "=" + URI.escape(value) + "&"
|
||||
}
|
||||
|
||||
body_str = body_str[0..-1]
|
||||
end
|
||||
|
||||
def self.parse_json(json_str, root_element)
|
||||
begin
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2011, 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. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
require 'OZonesClient'
|
||||
|
||||
module OZonesHelper
|
||||
@@ -18,11 +34,8 @@ module OZonesHelper
|
||||
if OZonesClient::is_error?(rc)
|
||||
[-1, rc.message]
|
||||
else
|
||||
id=rc.body.match('\"id\":(.*)$')[1].strip
|
||||
if id[-1..-1] == ","
|
||||
id = id[0..id.size-2]
|
||||
end
|
||||
[0, "ID: #{id}"]
|
||||
id = get_id(rc)
|
||||
[0, "ID: #{id}"]
|
||||
end
|
||||
end
|
||||
|
||||
@@ -58,6 +71,19 @@ module OZonesHelper
|
||||
[0, "#{message}"]
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
########################################################################
|
||||
# Helpers
|
||||
########################################################################
|
||||
|
||||
|
||||
def get_id(rc)
|
||||
id = rc.body.match('\"id\":(.*)$')[1].strip
|
||||
if id[-1..-1] == ","
|
||||
id = id[0..id.size-2]
|
||||
end
|
||||
|
||||
return id
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,3 +1,19 @@
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2011, 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. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
require 'cli/ozones_helper'
|
||||
require 'cli/one_helper'
|
||||
|
||||
@@ -8,8 +24,21 @@ class VDCHelper < OZonesHelper::OZHelper
|
||||
super(user, pass, endpoint_str, timeout, debug_flag)
|
||||
end
|
||||
|
||||
def create_resource(template)
|
||||
super(@vdc_str,template)
|
||||
def create_resource(template, options)
|
||||
tmpl_str = File.read(template)
|
||||
|
||||
if options[:force]
|
||||
tmpl_str << "FORCE=YES\n"
|
||||
end
|
||||
|
||||
rc = @client.post_resource_str(@vdc_str, tmpl_str)
|
||||
|
||||
if OZonesClient::is_error?(rc)
|
||||
[-1, rc.message]
|
||||
else
|
||||
id = get_id(rc)
|
||||
[0, "ID: #{id}"]
|
||||
end
|
||||
end
|
||||
|
||||
def list_pool(options)
|
||||
@@ -23,7 +52,62 @@ class VDCHelper < OZonesHelper::OZHelper
|
||||
def delete_resource(id, options)
|
||||
super(@vdc_str,id, options)
|
||||
end
|
||||
|
||||
def addhost(id, host_array, options)
|
||||
rc = @client.get_resource(@vdc_str, id)
|
||||
|
||||
if OZonesClient::is_error?(rc)
|
||||
return [-1, rc.message]
|
||||
else
|
||||
vdc = OZonesClient::parse_json(rc.body, @vdc_str.upcase)
|
||||
end
|
||||
|
||||
hosts = vdc['hosts'].split(',').collect!{|x| x.to_i}
|
||||
host_array.concat(hosts).uniq!
|
||||
|
||||
new_host = host_array.join(',')
|
||||
template = "ID=#{id}\nHOSTS=#{new_host}\n"
|
||||
|
||||
if options[:force]
|
||||
template << "FORCE=YES\n"
|
||||
end
|
||||
|
||||
rc = @client.put_resource(@vdc_str, id, template)
|
||||
|
||||
if OZonesClient::is_error?(rc)
|
||||
return [-1, rc.message]
|
||||
end
|
||||
|
||||
[0, ""]
|
||||
end
|
||||
|
||||
def delhost(id, host_array, options)
|
||||
rc = @client.get_resource(@vdc_str, id)
|
||||
|
||||
if OZonesClient::is_error?(rc)
|
||||
return [-1, rc.message]
|
||||
else
|
||||
vdc = OZonesClient::parse_json(rc.body, @vdc_str.upcase)
|
||||
end
|
||||
|
||||
hosts = vdc['hosts'].split(',').collect!{|x| x.to_i}
|
||||
|
||||
new_host = (hosts - host_array).join(',')
|
||||
template = "ID=#{id}\nHOSTS=#{new_host}\n"
|
||||
|
||||
if options[:force]
|
||||
template << "FORCE=YES\n"
|
||||
end
|
||||
|
||||
rc = @client.put_resource(@vdc_str, id, template)
|
||||
|
||||
if OZonesClient::is_error?(rc)
|
||||
return [-1, rc.message]
|
||||
end
|
||||
|
||||
[0, ""]
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def format_resource(vdc, options)
|
||||
@@ -34,6 +118,7 @@ class VDCHelper < OZonesHelper::OZHelper
|
||||
|
||||
puts str % ["ID ", vdc['id'].to_s]
|
||||
puts str % ["NAME ", vdc['name'].to_s]
|
||||
puts str % ["GROUP_ID ", vdc['group_id'].to_s]
|
||||
puts str % ["ZONEID ", vdc['zones_id'].to_s]
|
||||
puts str % ["VDCADMIN ", vdc['vdcadminname'].to_s]
|
||||
puts str % ["HOST IDs ", vdc['hosts'].to_s]
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
:databasetype: sqlite
|
||||
#:htaccess: /var/www/.htaccess
|
||||
:dbdebug: yes
|
||||
:dbdebug: no
|
||||
|
||||
#####################
|
||||
# Server Configuration
|
||||
|
||||
@@ -26,10 +26,10 @@ module OZones
|
||||
|
||||
OZones::Zones.all.each{|zone|
|
||||
zone.vdcs.all.each{|vdc|
|
||||
htaccess << "RewriteRule ^(.*)/#{vdc.name} " +
|
||||
htaccess << "RewriteRule ^#{vdc.name} " +
|
||||
"#{zone.endpoint} [P]\n"
|
||||
if zone.sunsendpoint != nil
|
||||
htaccess << "RewriteRule ^(.*)/sunstone_#{vdc.name} " +
|
||||
htaccess << "RewriteRule ^sunstone_#{vdc.name} " +
|
||||
"#{zone.sunsendpoint} [P]\n"
|
||||
end
|
||||
}
|
||||
|
||||
@@ -23,11 +23,17 @@ module OZones
|
||||
@file_path = file_path
|
||||
else
|
||||
if !ENV["ONE_LOCATION"]
|
||||
@file_path="/usr/lib/one/ozones/htaccess"
|
||||
@file_path="/var/lib/one/.htaccess"
|
||||
else
|
||||
@file_path=ENV["ONE_LOCATION"]+"/lib/ozones/htaccess"
|
||||
@file_path=ENV["ONE_LOCATION"]+"/var/.htaccess"
|
||||
end
|
||||
end
|
||||
|
||||
# Let's check for file permissions
|
||||
if !File.writable?(@file_path) and
|
||||
!File.writable?(File.dirname(@file_path))
|
||||
raise "#{@file_path} is not writable"
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
|
||||
@@ -21,11 +21,12 @@ module OZones
|
||||
include OpenNebulaJSON::JSONUtils
|
||||
extend OpenNebulaJSON::JSONUtils
|
||||
|
||||
property :id, Serial
|
||||
property :name, String, :required => true, :unique => true
|
||||
property :vdcadminname, String, :required => true
|
||||
property :acls, String
|
||||
property :hosts, String
|
||||
property :id, Serial
|
||||
property :name, String, :required => true, :unique => true
|
||||
property :group_id, Integer
|
||||
property :vdcadminname, String, :required => true
|
||||
property :acls, String
|
||||
property :hosts, String
|
||||
|
||||
belongs_to :zones
|
||||
|
||||
@@ -44,6 +45,70 @@ module OZones
|
||||
vdc_attributes["VDC"] = attributes
|
||||
return vdc_attributes
|
||||
end
|
||||
|
||||
#######################################################################
|
||||
# Methods to handle the ACL list
|
||||
#######################################################################
|
||||
# The ID of the first host ACL
|
||||
HOST_ACL_FIRST_ID = 3
|
||||
|
||||
# This method returns an Array of ACL strings to create them
|
||||
# in the target zone
|
||||
def get_vdc_acls_str(user_id, group_id)
|
||||
rule_str = Array.new
|
||||
|
||||
# Grant permissions to the group
|
||||
rule_str << "@#{group_id} VM+NET+IMAGE+TEMPLATE/* " \
|
||||
"CREATE+INFO_POOL_MINE"
|
||||
|
||||
# Grant permissions to the vdc admin
|
||||
rule_str << "##{user_id} USER/* CREATE"
|
||||
rule_str << "##{user_id} USER/@#{group_id} MANAGE+DELETE+INFO"
|
||||
|
||||
###############################################################
|
||||
#When more rules are added the class constant HOST_ACL_FIRST_ID
|
||||
#must be modified
|
||||
###############################################################
|
||||
|
||||
rule_str.concat(self.get_host_acls_str(group_id))
|
||||
end
|
||||
|
||||
def get_host_acls_str(group_id, host_list = nil)
|
||||
rule_str = Array.new
|
||||
|
||||
if host_list == nil
|
||||
host_list = self.hosts
|
||||
end
|
||||
|
||||
# Grant permissions to use the vdc hosts
|
||||
host_list.split(',').each{|hostid|
|
||||
rule_str << "@#{group_id} HOST/##{hostid} USE"
|
||||
}
|
||||
|
||||
return rule_str
|
||||
end
|
||||
|
||||
def get_host_acls
|
||||
self.acls.split(',')[HOST_ACL_FIRST_ID..-1].collect!{|x| x.to_i}
|
||||
end
|
||||
|
||||
# Returns the host acls as an array of strings.
|
||||
# The acls of the VDC are updated and the host acl ids removed
|
||||
def get_host_acls!(new_host_acls = nil)
|
||||
acl_ids = self.acls.split(',')
|
||||
vdc_acl = acl_ids.slice!(0,HOST_ACL_FIRST_ID)
|
||||
|
||||
newacl = ""
|
||||
vdc_acl.each{|id|
|
||||
newacl << id << ','
|
||||
}
|
||||
|
||||
newacl.chomp
|
||||
newacl << new_host_acls if new_host_acls
|
||||
|
||||
self.acls = newacl
|
||||
|
||||
return acl_ids
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@@ -17,72 +17,50 @@
|
||||
require 'OpenNebula'
|
||||
|
||||
class OCAInteraction
|
||||
|
||||
|
||||
# Creates a VDC (user, group, hosts)
|
||||
def create_vdc_in_zone(zone,vdc,adminname, adminpass)
|
||||
def create_vdc_in_zone(zone, vdc, adminname, adminpass)
|
||||
# Create a new client to interact with the zone
|
||||
client = OpenNebula::Client.new(zone.onename + ":" + zone.onepass,
|
||||
zone.endpoint,
|
||||
false)
|
||||
|
||||
|
||||
# Create a group in the zone with the VDC name
|
||||
group = OpenNebula::Group.new(OpenNebula::Group.build_xml, client)
|
||||
result = group.allocate(vdc.name)
|
||||
return result if OpenNebula.is_error?(result)
|
||||
|
||||
|
||||
# Create the VDC admin user in the Zone
|
||||
user=OpenNebula::User.new(OpenNebula::User.build_xml, client)
|
||||
result=user.allocate(adminname, adminpass)
|
||||
return rollback(client, group,
|
||||
user = OpenNebula::User.new(OpenNebula::User.build_xml, client)
|
||||
result = user.allocate(adminname, adminpass)
|
||||
return rollback(client, group,
|
||||
result, user) if OpenNebula.is_error?(result)
|
||||
|
||||
# Change primary group of the admin user to the VDC group
|
||||
result = user.chgrp(group.id)
|
||||
return rollback(client, group,
|
||||
return rollback(client, group,
|
||||
result, user) if OpenNebula.is_error?(result)
|
||||
|
||||
# Add ACLs
|
||||
aclp = OpenNebula::AclPool.new client
|
||||
|
||||
# Grant permissions to the group
|
||||
rule_str = "@#{group.id} VM+NET+IMAGE+TEMPLATE/* " +
|
||||
"CREATE+INFO_POOL_MINE"
|
||||
acl = OpenNebula::Acl.new(OpenNebula::Acl.build_xml,client)
|
||||
result = acl.allocate(*OpenNebula::Acl.parse_rule(rule_str))
|
||||
return rollback(client, group,
|
||||
result, user) if OpenNebula.is_error?(result)
|
||||
acls_str = acl.id.to_s + ","
|
||||
|
||||
# Grant permissions to the vdc admin
|
||||
rule_str = "##{user.id} USER/* CREATE"
|
||||
acl = OpenNebula::Acl.new(OpenNebula::Acl.build_xml,client)
|
||||
result = acl.allocate(*OpenNebula::Acl.parse_rule(rule_str))
|
||||
return rollback(client, group,
|
||||
result,user,acls_str) if OpenNebula.is_error?(result)
|
||||
acls_str += acl.id.to_s + ","
|
||||
|
||||
rule_str = "##{user.id} USER/@#{group.id} MANAGE+DELETE+INFO"
|
||||
acl = OpenNebula::Acl.new(OpenNebula::Acl.build_xml,client)
|
||||
result = acl.allocate(*OpenNebula::Acl.parse_rule(rule_str))
|
||||
return rollback(client, group,
|
||||
result,user,acls_str) if OpenNebula.is_error?(result)
|
||||
acls_str += acl.id.to_s + ","
|
||||
|
||||
# Grant permissions to use the vdc hosts
|
||||
aclp = OpenNebula::AclPool.new client
|
||||
rules = vdc.get_vdc_acls_str(user.id, group.id)
|
||||
|
||||
vdc.hosts.split(",").each{|hostid|
|
||||
rule_str = "@#{group.id} HOST/##{hostid} USE"
|
||||
acl = OpenNebula::Acl.new(OpenNebula::Acl.build_xml,client)
|
||||
result = acl.allocate(*OpenNebula::Acl.parse_rule(rule_str))
|
||||
if OpenNebula.is_error?(result)
|
||||
return rollback(client, group, result, user, acls_str)
|
||||
end
|
||||
acls_str += acl.id.to_s + ","
|
||||
}
|
||||
acls_str = ""
|
||||
|
||||
return acls_str.chop
|
||||
rules.each{ |rule_str|
|
||||
acl = OpenNebula::Acl.new(OpenNebula::Acl.build_xml,client)
|
||||
rc = acl.allocate(*OpenNebula::Acl.parse_rule(rule_str))
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
return rollback(client, group, rc, user, acls_str)
|
||||
end
|
||||
|
||||
acls_str << acl.id.to_s << ","
|
||||
}
|
||||
|
||||
return acls_str.chop, group.id
|
||||
end
|
||||
|
||||
|
||||
def delete_vdc_in_zone(id)
|
||||
vdc = OZones::Vdc.get(id)
|
||||
zone= OZones::Zones.get(vdc.zones_id)
|
||||
@@ -91,38 +69,62 @@ class OCAInteraction
|
||||
client = OpenNebula::Client.new(zone.onename + ":" + zone.onepass,
|
||||
zone.endpoint,
|
||||
false)
|
||||
|
||||
# Get the id of vdcadmin
|
||||
vdcgroupid = OpenNebulaHelper::OneHelper.id_to_name(vdc.name,
|
||||
OpenNebula::GroupPool.new(client),
|
||||
"GROUP")[1].to_i
|
||||
|
||||
# Delete the resources from the VDC
|
||||
delete_images(vdcgroupid, client)
|
||||
delete_templates(vdcgroupid, client)
|
||||
delete_vms(vdcgroupid, client)
|
||||
delete_vns(vdcgroupid, client)
|
||||
|
||||
delete_images(vdc.group_id, client)
|
||||
delete_templates(vdc.group_id, client)
|
||||
delete_vms(vdc.group_id, client)
|
||||
delete_vns(vdc.group_id, client)
|
||||
|
||||
# Delete ACLs
|
||||
delete_acls(vdc.acls, client)
|
||||
|
||||
delete_acls(vdc.acls, client)
|
||||
|
||||
# Delete users from a group
|
||||
up = OpenNebula::UserPool.new(client)
|
||||
up.info
|
||||
up.each{|user|
|
||||
if user['GID'].to_i == vdcgroupid
|
||||
OpenNebula::User.new_with_id(user['ID'], client).delete
|
||||
up.each{|user|
|
||||
if user['GID'].to_i == vdc.group_id
|
||||
OpenNebula::User.new_with_id(user['ID'], client).delete
|
||||
end
|
||||
}
|
||||
|
||||
|
||||
# Delete the group
|
||||
rc = OpenNebula::Group.new_with_id(vdcgroupid, client).delete
|
||||
rc = OpenNebula::Group.new_with_id(vdc.group_id, client).delete
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
return rc
|
||||
else
|
||||
return rc
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def update_vdc_hosts(zone, vdc, host_list)
|
||||
# Create a new client to interact with the zone
|
||||
client = OpenNebula::Client.new(zone.onename + ":" + zone.onepass,
|
||||
zone.endpoint,
|
||||
false)
|
||||
# Delete existing host ACLs
|
||||
vdc.get_host_acls.each{|acl_id|
|
||||
OpenNebula::Acl.new_with_id(acl_id, client).delete
|
||||
}
|
||||
|
||||
# Create new ACLs
|
||||
acls_str = ""
|
||||
host_acls = vdc.get_host_acls_str(vdc.group_id, host_list)
|
||||
|
||||
host_acls.each{|rule|
|
||||
acl = OpenNebula::Acl.new(OpenNebula::Acl.build_xml,client)
|
||||
rc = acl.allocate(*OpenNebula::Acl.parse_rule(rule))
|
||||
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
return rc
|
||||
end
|
||||
|
||||
acls_str += acl.id.to_s + ","
|
||||
}
|
||||
|
||||
return acls_str.chop
|
||||
end
|
||||
|
||||
# Creates a VDC (user, group, hosts)
|
||||
@@ -140,15 +142,11 @@ class OCAInteraction
|
||||
|
||||
# Deletes resources from failed created VDC
|
||||
def rollback(client, group, result, user=nil, acls_str=nil)
|
||||
user.delete if user
|
||||
user.delete if user
|
||||
group.delete
|
||||
|
||||
return result if !acls_str
|
||||
|
||||
acls_str.chop.split(",").each{|acl_id|
|
||||
OpenNebula::Acl.new_with_id(acl_id, client).delete
|
||||
}
|
||||
|
||||
delete_acls(acls_str, client)
|
||||
|
||||
return result
|
||||
end
|
||||
|
||||
@@ -156,51 +154,53 @@ class OCAInteraction
|
||||
def delete_images(groupid, client)
|
||||
ip = OpenNebula::ImagePool.new(client)
|
||||
ip.info
|
||||
ip.each{|image|
|
||||
ip.each{|image|
|
||||
if image['GID'].to_i == groupid
|
||||
OpenNebula::Image.new_with_id(image['ID'], client).delete
|
||||
OpenNebula::Image.new_with_id(image['ID'], client).delete
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
# Deletes templates from a group
|
||||
def delete_templates(groupid, client)
|
||||
tp = OpenNebula::TemplatePool.new(client)
|
||||
tp.info
|
||||
tp.each{|template|
|
||||
tp.each{|template|
|
||||
if template['GID'].to_i == groupid
|
||||
OpenNebula::Image.new_with_id(template['ID'], client).delete
|
||||
OpenNebula::Image.new_with_id(template['ID'], client).delete
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
# Deletes VMs from a group
|
||||
def delete_vms(groupid, client)
|
||||
vmp = OpenNebula::VirtualMachinePool.new(client)
|
||||
vmp.info
|
||||
vmp.each{|vm|
|
||||
vmp.each{|vm|
|
||||
if vm['GID'].to_i == groupid
|
||||
OpenNebula::VirtualMachine.new_with_id(vm['ID'], client).delete
|
||||
OpenNebula::VirtualMachine.new_with_id(vm['ID'], client).delete
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
# Deletes VNs from a group
|
||||
def delete_vns(groupid, client)
|
||||
vnp = OpenNebula::VirtualNetworkPool.new(client)
|
||||
vnp.info
|
||||
vnp.each{|vn|
|
||||
vnp.each{|vn|
|
||||
if vn['GID'].to_i == groupid
|
||||
OpenNebula::VirtualNetwork.new_with_id(vn['ID'], client).delete
|
||||
OpenNebula::VirtualNetwork.new_with_id(vn['ID'], client).delete
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
# Delete ACLs from a group
|
||||
def delete_acls(acls_str, client)
|
||||
acls_str.split(",").each{|acl_id|
|
||||
OpenNebula::Acl.new_with_id(acl_id, client).delete
|
||||
}
|
||||
def delete_acls(acls_str, client)
|
||||
if acls_str != nil && !acls_str.empty?
|
||||
acls_str.split(",").each{|acl_id|
|
||||
OpenNebula::Acl.new_with_id(acl_id.to_i, client).delete
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -136,23 +136,26 @@ class OzonesServer
|
||||
|
||||
if body.size > 0
|
||||
result = parse_json(body,kind)
|
||||
data = result if !OpenNebula.is_error?(result)
|
||||
data = result if !OpenNebula.is_error?(result)
|
||||
end
|
||||
|
||||
resource = case kind
|
||||
when "vdc" then
|
||||
vdc_data=Hash.new
|
||||
vdc_data = Hash.new
|
||||
data.each{|key,value|
|
||||
vdc_data[key.downcase.to_sym]=value if key!="pool"
|
||||
}
|
||||
|
||||
# Check parameters
|
||||
if !vdc_data[:vdcadminname] || !vdc_data[:vdcadminpass] ||
|
||||
!vdc_data[:zoneid] || !vdc_data[:name] || !vdc_data[:hosts]
|
||||
return [400, OZones::Error.new(
|
||||
"Error: Couldn't create resource #{kind}. " +
|
||||
"Not enough information on the template").to_json]
|
||||
end
|
||||
mandatory_params = [:vdcadminname, :vdcadminpass,
|
||||
:zoneid, :name, :hosts]
|
||||
|
||||
mandatory_params.each { |param|
|
||||
if !vdc_data[param]
|
||||
return [400, OZones::Error.new(
|
||||
"Error: Couldn't create resource #{kind}. " +
|
||||
"Mandatory attribute '#{param}' is missing.").to_json]
|
||||
end
|
||||
}
|
||||
|
||||
# Check if the referenced zone exists
|
||||
zone=OZones::Zones.get(vdc_data[:zoneid])
|
||||
@@ -162,12 +165,29 @@ class OzonesServer
|
||||
return [404, error.to_json]
|
||||
end
|
||||
|
||||
if (!vdc_data[:force] or vdc_data[:force].upcase!="YES") and
|
||||
!host_uniqueness?(zone, vdc_data[:hosts])
|
||||
return [403, OZones::Error.new(
|
||||
"Error: Couldn't create resource #{kind}. " +
|
||||
"Hosts are not unique, and no force option" +
|
||||
" was given.").to_json]
|
||||
end
|
||||
|
||||
vdcadminname = vdc_data[:vdcadminname]
|
||||
vdcadminpass = vdc_data[:vdcadminpass]
|
||||
vdc_data.delete(:zoneid)
|
||||
vdc_data.delete(:vdcadminpass)
|
||||
vdc_data.delete(:force)
|
||||
|
||||
vdc = OZones::Vdc.create(vdc_data)
|
||||
begin
|
||||
vdc = OZones::Vdc.create(vdc_data)
|
||||
rescue Exception => e
|
||||
msg = e.message
|
||||
msg["accessible in OZones::Vdc"] = "supported."
|
||||
return [400, OZones::Error.new(
|
||||
"Error: Couldn't create resource #{kind}." +
|
||||
" #{msg}").to_json]
|
||||
end
|
||||
|
||||
zone.vdcs << vdc
|
||||
zone.save
|
||||
@@ -184,8 +204,10 @@ class OzonesServer
|
||||
"Error: Couldn't create #{kind}. Reason: " +
|
||||
rc.message).to_json]
|
||||
else
|
||||
vdc.acls = rc
|
||||
vdc.acls = rc[0]
|
||||
vdc.group_id = rc[1]
|
||||
vdc.save
|
||||
|
||||
pr.update # Rewrite proxy conf file
|
||||
return [200, vdc.to_json]
|
||||
end
|
||||
@@ -201,13 +223,15 @@ class OzonesServer
|
||||
zone_data[key.downcase.to_sym]=value if key!="pool"
|
||||
}
|
||||
|
||||
# Check parameters
|
||||
if !zone_data[:onename] || !zone_data[:onepass] ||
|
||||
!zone_data[:endpoint] || !zone_data[:name]
|
||||
return [400, OZones::Error.new(
|
||||
"Error: Couldn't create resource #{kind}. " +
|
||||
"Not enough information on the template").to_json]
|
||||
end
|
||||
mandatory_params = [:onename, :onepass, :endpoint, :name]
|
||||
|
||||
mandatory_params.each { |param|
|
||||
if !zone_data[param]
|
||||
return [400, OZones::Error.new(
|
||||
"Error: Couldn't create resource #{kind}. " +
|
||||
"Mandatory attribute '#{param}' is missing.").to_json]
|
||||
end
|
||||
}
|
||||
|
||||
# Digest and check credentials
|
||||
zone_data[:onepass] =
|
||||
@@ -241,6 +265,86 @@ class OzonesServer
|
||||
return [404, error.to_json]
|
||||
end
|
||||
end
|
||||
|
||||
############################################################################
|
||||
# Update resources
|
||||
############################################################################
|
||||
# Updates a resource of a kind, and updates the Proxy Rules if needed
|
||||
def update_resource(kind, data, body, pr)
|
||||
|
||||
if body.size > 0
|
||||
result = parse_json(body,kind)
|
||||
data = result if !OpenNebula.is_error?(result)
|
||||
end
|
||||
|
||||
puts data
|
||||
|
||||
resource = case kind
|
||||
when "vdc" then
|
||||
vdc_data=Hash.new
|
||||
vdc_id = nil
|
||||
data.each{|key,value|
|
||||
vdc_data[key.downcase.to_sym]=value if key!="id"
|
||||
vdc_id = value if key=="id"
|
||||
}
|
||||
|
||||
# Check parameters
|
||||
if !vdc_data[:hosts] || !vdc_id
|
||||
return [400, OZones::Error.new(
|
||||
"Error: Couldn't update resource #{kind}. " +
|
||||
"Need ID and HOSTS to update.").to_json]
|
||||
end
|
||||
|
||||
# Check if the referenced Vdc exists
|
||||
vdc=OZones::Vdc.get(vdc_id)
|
||||
if !vdc
|
||||
error = OZones::Error.new("Error: Vdc " +
|
||||
"#{vdc_id} not found, cannot update Vdc.")
|
||||
return [404, error.to_json]
|
||||
end
|
||||
|
||||
# Get the zone where the Vdc belongs
|
||||
zone=OZones::Zones.get(vdc.zones.id)
|
||||
if !zone
|
||||
error = OZones::Error.new("Error: Zone " +
|
||||
"#{vdc.zones.id} not found, cannot update Vdc.")
|
||||
return [404, error.to_json]
|
||||
end
|
||||
|
||||
if (!vdc_data[:force] or vdc_data[:force].upcase!="YES") and
|
||||
!host_uniqueness?(zone, vdc_data[:hosts], vdc_id.to_i)
|
||||
return [403, OZones::Error.new(
|
||||
"Error: Couldn't update resource #{kind}. " +
|
||||
"Hosts are not unique, and no force option" +
|
||||
" was given.").to_json]
|
||||
end
|
||||
|
||||
rc = @ocaInt.update_vdc_hosts(zone, vdc, vdc_data[:hosts])
|
||||
|
||||
if !OpenNebula.is_error?(rc)
|
||||
vdc.hosts = vdc_data[:hosts]
|
||||
vdc.get_host_acls!(rc)
|
||||
|
||||
vdc.save
|
||||
|
||||
if vdc.saved?
|
||||
return [200, vdc.to_json]
|
||||
else
|
||||
return [500, OZones::Error.new(
|
||||
"Error: Couldn't update resource #{kind}.").to_json]
|
||||
end
|
||||
|
||||
else
|
||||
return [500, OZones::Error.new(
|
||||
"Error: Couldn't update resource #{kind.upcase}." +
|
||||
" Failed to update ACLs").to_json]
|
||||
end
|
||||
else
|
||||
error = OZones::Error.new(
|
||||
"Error: #{kind.upcase} resource update not supported")
|
||||
return [404, error.to_json]
|
||||
end
|
||||
end
|
||||
|
||||
############################################################################
|
||||
# Delete resources
|
||||
@@ -272,20 +376,26 @@ class OzonesServer
|
||||
end
|
||||
|
||||
############################################################################
|
||||
# TODO
|
||||
# Helper functions
|
||||
############################################################################
|
||||
def perform_action(kind, id, action_json)
|
||||
resource = retrieve_resource(kind, id)
|
||||
if OpenNebula.is_error?(resource)
|
||||
return [404, resource.to_json]
|
||||
end
|
||||
|
||||
# Check if hosts are already include in any Vdc of the zone
|
||||
def host_uniqueness?(zone, host_list, vdc_id = -1)
|
||||
all_hosts = ""
|
||||
zone.vdcs.all.each{|vdc|
|
||||
if vdc.hosts != nil and !vdc.hosts.empty? and vdc.id != vdc_id
|
||||
all_hosts << ',' << vdc.hosts
|
||||
end
|
||||
}
|
||||
|
||||
rc = resource.perform_action(action_json)
|
||||
if OpenNebula.is_error?(rc)
|
||||
return [500, rc.to_json]
|
||||
else
|
||||
return [204, resource.to_json]
|
||||
end
|
||||
all_hosts = all_hosts.split(',')
|
||||
|
||||
host_list.split(",").each{|host|
|
||||
return false if all_hosts.include?(host)
|
||||
}
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
@@ -48,7 +48,6 @@ require 'rubygems'
|
||||
require 'data_mapper'
|
||||
require 'digest/sha1'
|
||||
require 'OzonesServer'
|
||||
require 'one_helper'
|
||||
|
||||
##############################################################################
|
||||
# Read configuration
|
||||
@@ -98,6 +97,13 @@ end
|
||||
ADMIN_NAME = @auth.name
|
||||
ADMIN_PASS = @auth.password
|
||||
|
||||
begin
|
||||
OZones::ProxyRules.new("apache",config[:htaccess])
|
||||
rescue Exception => e
|
||||
warn e.message
|
||||
exit -1
|
||||
end
|
||||
|
||||
|
||||
##############################################################################
|
||||
# Sinatra Configuration
|
||||
@@ -241,7 +247,20 @@ get '/:pool/:aggpool' do
|
||||
@OzonesServer.get_aggregated_pool(params[:pool], params[:aggpool])
|
||||
end
|
||||
|
||||
##############################################################################
|
||||
# Create a new Resource
|
||||
##############################################################################
|
||||
post '/:pool' do
|
||||
@OzonesServer.create_resource(params[:pool], params, request.body.read, @pr)
|
||||
end
|
||||
|
||||
##############################################################################
|
||||
# Update Resource
|
||||
##############################################################################
|
||||
put '/:resource/:id' do
|
||||
@OzonesServer.update_resource(params[:resource], params,
|
||||
request.body.read, @pr)
|
||||
end
|
||||
|
||||
##############################################################################
|
||||
# Delete Resource
|
||||
@@ -250,12 +269,5 @@ delete '/:resource/:id' do
|
||||
@OzonesServer.delete_resource(params[:resource], params[:id], @pr)
|
||||
end
|
||||
|
||||
##############################################################################
|
||||
# Create a new Resource
|
||||
##############################################################################
|
||||
post '/:pool' do
|
||||
@OzonesServer.create_resource(params[:pool], params, request.body.read, @pr)
|
||||
end
|
||||
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div id="footer" class="ui-layout-south">
|
||||
Copyright 2002-2011 © OpenNebula Project Leads (<a href="http://opennebula.org" target="_blank">OpenNebula.org</a>). All Rights Reserved. OpenNebula 2.9.85
|
||||
Copyright 2002-2011 © OpenNebula Project Leads (<a href="http://opennebula.org" target="_blank">OpenNebula.org</a>). All Rights Reserved. OpenNebula 2.9.90
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"vdc": {
|
||||
"hosts": "testhostvdc0n0,testhostvdc0n1,testhostvdc0n2",
|
||||
"hosts": "5,7,9",
|
||||
"zones_id": 1,
|
||||
"name": "testvdc0",
|
||||
"id": 1
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
NAME=testvdc0
|
||||
ZONEID=1
|
||||
HOSTS=5,7,9
|
||||
VDCADMINNAME=adminname
|
||||
VDCADMINPASS=adminpass
|
||||
@@ -1,5 +1,5 @@
|
||||
NAME=testvdc1
|
||||
HOSTS=testhostvdc1n0
|
||||
HOSTS=8
|
||||
ZONEID=1
|
||||
VDCADMINNAME=othername
|
||||
VDCADMINPASS=otherpass
|
||||
@@ -1,3 +1,3 @@
|
||||
NAME=testvdcnozone
|
||||
HOSTS=testhostvdcnozone,bogushost
|
||||
HOSTS=3,7
|
||||
ZONEID=5
|
||||
+1
-2
@@ -122,10 +122,9 @@ int PoolSQL::allocate(
|
||||
else
|
||||
{
|
||||
rc = lastOID;
|
||||
do_hooks(objsql, Hook::ALLOCATE);
|
||||
}
|
||||
|
||||
do_hooks(objsql, Hook::ALLOCATE);
|
||||
|
||||
objsql->unlock();
|
||||
|
||||
delete objsql;
|
||||
|
||||
@@ -32,11 +32,6 @@ void RequestManagerChown::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
string nuname;
|
||||
string ngname;
|
||||
|
||||
// TODO: Move these to constructor?
|
||||
Nebula& nd = Nebula::instance();
|
||||
GroupPool * gpool = nd.get_gpool();
|
||||
UserPool * upool = nd.get_upool();
|
||||
|
||||
PoolObjectSQL * object;
|
||||
|
||||
if ( basic_authorization(oid, att) == false )
|
||||
@@ -123,10 +118,6 @@ void UserChown::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
|
||||
string ngname;
|
||||
|
||||
Nebula& nd = Nebula::instance();
|
||||
GroupPool * gpool = nd.get_gpool();
|
||||
UserPool * upool = static_cast<UserPool *>(pool);
|
||||
|
||||
User * user;
|
||||
Group * group;
|
||||
|
||||
|
||||
@@ -408,7 +408,7 @@ void VirtualMachineSaveDisk::request_execute(xmlrpc_c::paramList const& paramLis
|
||||
|
||||
// ------------------ Template for the new image ------------------
|
||||
|
||||
oss << "NAME= " << img_name << endl;
|
||||
oss << "NAME= \"" << img_name << "\"" << endl;
|
||||
oss << "PUBLIC = NO " << endl;
|
||||
oss << "SOURCE = - " << endl;
|
||||
|
||||
|
||||
@@ -19,13 +19,13 @@
|
||||
|
||||
if [ -z "$ONE_LOCATION" ]; then
|
||||
SUNSTONE_PID=/var/run/one/sunstone.pid
|
||||
SUNSTONE_SERVER=/usr/lib/one/sunstone/config.ru
|
||||
SUNSTONE_SERVER=/usr/lib/one/sunstone/sunstone-server.rb
|
||||
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_SERVER=$ONE_LOCATION/lib/sunstone/sunstone-server.rb
|
||||
SUNSTONE_LOCK_FILE=$ONE_LOCATION/var/.sunstone.lock
|
||||
SUNSTONE_LOG=$ONE_LOCATION/var/sunstone.log
|
||||
SUNSTONE_CONF=$ONE_LOCATION/etc/sunstone-server.conf
|
||||
@@ -56,23 +56,16 @@ start()
|
||||
echo "Can not find $SUNSTONE_SERVER."
|
||||
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 &
|
||||
ruby $SUNSTONE_SERVER > $SUNSTONE_LOG 2>&1 &
|
||||
LASTPID=$!
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error executing $SUNSTONE_SERVER, please check the log $SUNSTONE_LOG"
|
||||
exit 1
|
||||
else
|
||||
echo $LASTPID > $SUNSTONE_PID
|
||||
fi
|
||||
|
||||
sleep 1
|
||||
@@ -83,7 +76,7 @@ start()
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "sunstone-server listening on $HOST:$PORT"
|
||||
echo "sunstone-server started"
|
||||
}
|
||||
|
||||
#
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
# OpenNebula sever contact information
|
||||
:one_xmlrpc: http://localhost:2633/RPC2
|
||||
|
||||
# Server Configuration
|
||||
HOST=127.0.0.1
|
||||
PORT=9869
|
||||
:host: 127.0.0.1
|
||||
:port: 9869
|
||||
|
||||
:auth: basic
|
||||
|
||||
# VNC Configuration
|
||||
VNC_PROXY_BASE_PORT=29876
|
||||
NOVNC_PATH=
|
||||
:vnc_proxy_base_port: 29876
|
||||
:novnc_path:
|
||||
@@ -23,37 +23,8 @@ class SunstoneServer
|
||||
# FLAG that will filter the elements retrieved from the Pools
|
||||
POOL_FILTER = Pool::INFO_GROUP
|
||||
|
||||
def initialize(username, password)
|
||||
# TBD one_client_user(name) from CloudServer
|
||||
@client = Client.new("dummy:dummy")
|
||||
@client.one_auth = "#{username}:#{password}"
|
||||
end
|
||||
|
||||
############################################################################
|
||||
#
|
||||
############################################################################
|
||||
def self.authorize(user="", sha1_pass="")
|
||||
if user.empty? || sha1_pass.empty?
|
||||
return [401, false]
|
||||
end
|
||||
|
||||
# TBD get_user_password(name) from CloudServer
|
||||
user_pool = UserPool.new(Client.new)
|
||||
rc = user_pool.info
|
||||
if OpenNebula.is_error?(rc)
|
||||
return [500, false]
|
||||
end
|
||||
|
||||
user_pass = user_pool["USER[NAME=\"#{user}\"]/PASSWORD"]
|
||||
user_id = user_pool["USER[NAME=\"#{user}\"]/ID"]
|
||||
user_gid = user_pool["USER[NAME=\"#{user}\"]/GID"]
|
||||
user_gname = user_pool["USER[NAME=\"#{user}\"]/GNAME"]
|
||||
|
||||
if user_pass == sha1_pass
|
||||
return [204, [user_id, user_gid, user_gname]]
|
||||
else
|
||||
return [401, nil]
|
||||
end
|
||||
def initialize(token, xmlrpc)
|
||||
@client = Client.new(token, xmlrpc, false)
|
||||
end
|
||||
|
||||
############################################################################
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 1.8 KiB |
@@ -36,6 +36,7 @@ end
|
||||
SUNSTONE_ROOT_DIR = File.dirname(__FILE__)
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << RUBY_LIB_LOCATION+'/cloud'
|
||||
$: << SUNSTONE_ROOT_DIR+'/models'
|
||||
|
||||
##############################################################################
|
||||
@@ -44,17 +45,25 @@ $: << SUNSTONE_ROOT_DIR+'/models'
|
||||
require 'rubygems'
|
||||
require 'sinatra'
|
||||
require 'erb'
|
||||
require 'yaml'
|
||||
|
||||
require 'cloud/Configuration'
|
||||
require 'CloudAuth'
|
||||
require 'SunstoneServer'
|
||||
require 'SunstonePlugins'
|
||||
|
||||
set :config, Configuration.new(CONFIGURATION_FILE)
|
||||
begin
|
||||
conf = YAML.load_file(CONFIGURATION_FILE)
|
||||
conf[:hash_passwords] = true
|
||||
rescue Exception => e
|
||||
puts "Error parsing config file #{CONFIGURATION_FILE}: #{e.message}"
|
||||
exit 1
|
||||
end
|
||||
|
||||
##############################################################################
|
||||
# Sinatra Configuration
|
||||
##############################################################################
|
||||
use Rack::Session::Pool, :key => 'sunstone'
|
||||
set :config, conf
|
||||
set :host, settings.config[:host]
|
||||
set :port, settings.config[:port]
|
||||
|
||||
@@ -67,32 +76,40 @@ helpers do
|
||||
end
|
||||
|
||||
def build_session
|
||||
auth = Rack::Auth::Basic::Request.new(request.env)
|
||||
if auth.provided? && auth.basic? && auth.credentials
|
||||
user = auth.credentials[0]
|
||||
sha1_pass = Digest::SHA1.hexdigest(auth.credentials[1])
|
||||
cloud_auth = CloudAuth.new(settings.config)
|
||||
|
||||
rc = SunstoneServer.authorize(user, sha1_pass)
|
||||
if rc[1]
|
||||
session[:user] = user
|
||||
session[:user_id] = rc[1][0]
|
||||
session[:user_gid] = rc[1][1]
|
||||
session[:user_gname] = rc[1][2]
|
||||
session[:password] = sha1_pass
|
||||
session[:ip] = request.ip
|
||||
session[:remember] = params[:remember]
|
||||
|
||||
if params[:remember]
|
||||
env['rack.session.options'][:expire_after] = 30*60*60*24
|
||||
end
|
||||
|
||||
return [204, ""]
|
||||
else
|
||||
return [rc.first, ""]
|
||||
end
|
||||
begin
|
||||
result = cloud_auth.auth(request.env, params)
|
||||
rescue Exception => e
|
||||
error 500, e.message
|
||||
end
|
||||
|
||||
return [401, ""]
|
||||
if result
|
||||
return [401, ""]
|
||||
else
|
||||
user_id = OpenNebula::User::SELF
|
||||
user = OpenNebula::User.new_with_id(user_id, cloud_auth.client)
|
||||
|
||||
rc = user.info
|
||||
if OpenNebula.is_error?(rc)
|
||||
# Add a log message
|
||||
return [500, ""]
|
||||
end
|
||||
|
||||
session[:user] = user['NAME']
|
||||
session[:user_id] = user['ID']
|
||||
session[:user_gid] = user['GID']
|
||||
session[:user_gname] = user['GNAME']
|
||||
session[:token] = cloud_auth.token
|
||||
session[:ip] = request.ip
|
||||
session[:remember] = params[:remember]
|
||||
|
||||
if params[:remember]
|
||||
env['rack.session.options'][:expire_after] = 30*60*60*24
|
||||
end
|
||||
|
||||
return [204, ""]
|
||||
end
|
||||
end
|
||||
|
||||
def destroy_session
|
||||
@@ -105,7 +122,9 @@ before do
|
||||
unless request.path=='/login' || request.path=='/'
|
||||
halt 401 unless authorized?
|
||||
|
||||
@SunstoneServer = SunstoneServer.new(session[:user], session[:password])
|
||||
@SunstoneServer = SunstoneServer.new(
|
||||
session[:token],
|
||||
settings.config[:one_xmlrpc])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -125,9 +144,10 @@ end
|
||||
# HTML Requests
|
||||
##############################################################################
|
||||
get '/' do
|
||||
return File.read(File.dirname(__FILE__)+
|
||||
'/templates/login.html') unless authorized?
|
||||
|
||||
if !authorized?
|
||||
templ = settings.config[:auth]=="basic"? "login.html" : "login_x509.html"
|
||||
return File.read(File.dirname(__FILE__)+'/templates/'+templ)
|
||||
end
|
||||
time = Time.now + 60
|
||||
response.set_cookie("one-user",
|
||||
:value=>"#{session[:user]}",
|
||||
@@ -146,7 +166,10 @@ get '/' do
|
||||
end
|
||||
|
||||
get '/login' do
|
||||
File.read(SUNSTONE_ROOT_DIR+'/templates/login.html')
|
||||
if !authorized?
|
||||
templ = settings.config[:auth]=="basic"? "login.html" : "login_x509.html"
|
||||
return File.read(File.dirname(__FILE__)+'/templates/'+templ)
|
||||
end
|
||||
end
|
||||
|
||||
##############################################################################
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
<!DOCTYPE html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<title>OpenNebula Sunstone Login</title>
|
||||
<link rel="stylesheet" type="text/css" href="css/login.css" />
|
||||
|
||||
<!-- Vendor Libraries -->
|
||||
<script type="text/javascript" src="vendor/jQuery/jquery-1.4.4.min.js"></script>
|
||||
<!-- End Vendor Libraries -->
|
||||
|
||||
<script type="text/javascript" src="js/opennebula.js"></script>
|
||||
<script type="text/javascript" src="js/login.js"></script>
|
||||
|
||||
</head>
|
||||
|
||||
|
||||
<body>
|
||||
<div id="header">
|
||||
<div id="logo">
|
||||
The OpenNebula Cloud Operations Center
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="wrapper">
|
||||
<div id="logo_sunstone">
|
||||
</div>
|
||||
|
||||
<div id="auth_error" class="error_message">
|
||||
Invalid username or password
|
||||
</div>
|
||||
<div id="one_error" class="error_message">
|
||||
OpenNebula is not running
|
||||
</div>
|
||||
|
||||
<form id="login_form">
|
||||
<div class="border" id="login" style='height:169px;background:url("../images/panel_short.png") no-repeat scroll center transparent'>
|
||||
<div class="content">
|
||||
<input style="float:left;" type="submit" id="login_btn" value="" />
|
||||
<input type="checkbox" id="check_remember" />
|
||||
<label id="label_remember" for="check_remember">Remember me</label>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -67,7 +67,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div id="footer" class="ui-layout-south">
|
||||
Copyright 2002-2011 © OpenNebula Project Leads (<a href="http://opennebula.org" target="_blank">OpenNebula.org</a>). All Rights Reserved. OpenNebula 2.9.85
|
||||
Copyright 2002-2011 © OpenNebula Project Leads (<a href="http://opennebula.org" target="_blank">OpenNebula.org</a>). All Rights Reserved. OpenNebula 2.9.90
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user