diff --git a/include/ImageManager.h b/include/ImageManager.h index 509a25f7d2..59e3f744ef 100644 --- a/include/ImageManager.h +++ b/include/ImageManager.h @@ -85,6 +85,14 @@ public: * @return pointer to the image or 0 if could not be acquired */ Image * acquire_image(int image_id); + + /** + * Try to acquire an image from the repository for a VM. + * @param name of the image + * @param id of owner + * @return pointer to the image or 0 if could not be acquired + */ + Image * acquire_image(const string& name, int uid); /** * Releases an image and triggers any needed operations in the repo diff --git a/include/ImagePool.h b/include/ImagePool.h index 7eab479ddf..a19337a7a9 100644 --- a/include/ImagePool.h +++ b/include/ImagePool.h @@ -135,7 +135,6 @@ public: * @return 0 on success, * -1 error, * -2 not using the pool, - * -3 deprecated NAME found */ int disk_attribute(VectorAttribute * disk, int disk_id, diff --git a/include/RequestManagerAllocate.h b/include/RequestManagerAllocate.h index d4d30cb2a6..e2561eb4d9 100644 --- a/include/RequestManagerAllocate.h +++ b/include/RequestManagerAllocate.h @@ -236,7 +236,7 @@ public: UserAllocate(): RequestManagerAllocate("UserAllocate", "Returns user information", - "A:sss", + "A:ssss", false) { Nebula& nd = Nebula::instance(); diff --git a/include/RequestManagerVirtualMachine.h b/include/RequestManagerVirtualMachine.h index 2b535b2e15..ea70ad35f5 100644 --- a/include/RequestManagerVirtualMachine.h +++ b/include/RequestManagerVirtualMachine.h @@ -129,7 +129,7 @@ public: VirtualMachineSaveDisk(): RequestManagerVirtualMachine("VirtualMachineSaveDisk", "Saves a disk from virtual machine as a new image", - "A:siis"){}; + "A:siiss"){}; ~VirtualMachineSaveDisk(){}; diff --git a/include/VirtualNetworkPool.h b/include/VirtualNetworkPool.h index 6dc2ef2c1e..8dc90e290d 100644 --- a/include/VirtualNetworkPool.h +++ b/include/VirtualNetworkPool.h @@ -94,8 +94,7 @@ public: * @param vid of the VM requesting the lease * @return 0 on success, * -1 error, - * -2 not using the pool, - * -3 unsupported NETWORK attribute + * -2 not using the pool */ int nic_attribute(VectorAttribute * nic, int uid, int vid); @@ -165,6 +164,19 @@ private: { return new VirtualNetwork(-1,-1,"","",0); }; + + /** + * Function to get a VirtualNetwork by its name, as provided by a VM + * template + */ + VirtualNetwork * get_nic_by_name(VectorAttribute * nic, + const string& name, + int _uid); + + /** + * Function to get a VirtualNetwork by its id, as provided by a VM template + */ + VirtualNetwork * get_nic_by_id(const string& id_s); }; #endif /*VIRTUAL_NETWORK_POOL_H_*/ diff --git a/install.sh b/install.sh index e68a8ca288..fcbc67b326 100755 --- a/install.sh +++ b/install.sh @@ -795,8 +795,7 @@ RUBY_OPENNEBULA_LIB_FILES="src/oca/ruby/OpenNebula/Host.rb \ src/oca/ruby/OpenNebula/GroupPool.rb \ src/oca/ruby/OpenNebula/Acl.rb \ src/oca/ruby/OpenNebula/AclPool.rb \ - src/oca/ruby/OpenNebula/XMLUtils.rb \ - src/oca/ruby/OpenNebula/Configuration.rb" + src/oca/ruby/OpenNebula/XMLUtils.rb" #------------------------------------------------------------------------------- # Common Cloud Files diff --git a/share/etc/oned.conf b/share/etc/oned.conf index 03168786e1..630303e906 100644 --- a/share/etc/oned.conf +++ b/share/etc/oned.conf @@ -556,10 +556,11 @@ HM_MAD = [ # caching #******************************************************************************* -#AUTH_MAD = [ -# executable = "one_auth_mad", -# arguments = "--authn ssh,x509,server_cipher,server_x509" +AUTH_MAD = [ + executable = "one_auth_mad", + arguments = "--authn ssh,x509,server_cipher,server_x509" # arguments = "--authz quota --authn ssh,x509,server_cipher,server_x509" -#] +] + +SESSION_EXPIRATION_TIME = 900 -SESSION_EXPIRATION_TIME = 900 \ No newline at end of file diff --git a/src/acct/watch_helper.rb b/src/acct/watch_helper.rb index e0a8fb2dbf..5a167d93c8 100644 --- a/src/acct/watch_helper.rb +++ b/src/acct/watch_helper.rb @@ -327,9 +327,9 @@ module WatchHelper v.name = vm['NAME'] v.uid = vm['UID'].to_i v.gid = vm['GID'].to_i - v.mem = vm['TEMPLATE/MEMORY'].to_i - v.cpu = vm['TEMPLATE/CPU'].to_f - v.vcpu = vm['TEMPLATE/VCPU'].to_i + v.mem = vm['TEMPLATE']['MEMORY'].to_i + v.cpu = vm['TEMPLATE']['CPU'].to_f + v.vcpu = vm['TEMPLATE']['VCPU'].to_i v.stime = vm['STIME'].to_i v.etime = vm['ETIME'].to_i } diff --git a/src/cloud/occi/lib/OCCIServer.rb b/src/cloud/occi/lib/OCCIServer.rb index 841f45fa49..954248d3db 100755 --- a/src/cloud/occi/lib/OCCIServer.rb +++ b/src/cloud/occi/lib/OCCIServer.rb @@ -504,4 +504,38 @@ class OCCIServer < CloudServer return to_occi_xml(user, 200) end + + def get_computes_types + etc_location=ONE_LOCATION ? ONE_LOCATION+"/etc" : "/etc/one" + begin + xml_response = "\n" + + Dir[etc_location + "/occi_templates/**"].each{| filename | + next if File.basename(filename) == "common.erb" + xml_response += "\t" + xml_response += "\t\t#{File.basename(filename)[0..-5]}" + file = File.open(filename, "r") + file.each_line{|line| + next if line.match(/^#/) + match=line.match(/^(.*)=(.*)/) + next if !match + case match[1].strip + when "NAME" + xml_response += "\t\t#{match[2].strip}" + when "CPU" + xml_response += "\t\t#{match[2].strip}" + when "MEMORY" + xml_response += "\t\t#{match[2].strip}" + end + } + xml_response += "\t" + } + + xml_response += "" + + return xml_response, 200 + rescue Exception => e + return "Error getting the instance types. Reason: #{e.message}", 500 + end + end end diff --git a/src/cloud/occi/lib/occi-server.rb b/src/cloud/occi/lib/occi-server.rb index aac6c8a267..e650e861cd 100755 --- a/src/cloud/occi/lib/occi-server.rb +++ b/src/cloud/occi/lib/occi-server.rb @@ -172,7 +172,11 @@ end ################################################### get '/compute/:id' do - result,rc = @occi_server.get_compute(request, params) + if params[:id] == "types" + result,rc = @occi_server.get_computes_types + else + result,rc = @occi_server.get_compute(request, params) + end treat_response(result,rc) end @@ -219,4 +223,4 @@ end get '/user/:id' do result,rc = @occi_server.get_user(request, params) treat_response(result,rc) -end \ No newline at end of file +end diff --git a/src/image/ImageManagerActions.cc b/src/image/ImageManagerActions.cc index 0b625a2818..39e5ec681b 100644 --- a/src/image/ImageManagerActions.cc +++ b/src/image/ImageManagerActions.cc @@ -46,6 +46,31 @@ Image * ImageManager::acquire_image(int image_id) /* -------------------------------------------------------------------------- */ +Image * ImageManager::acquire_image(const string& name, int uid) +{ + Image * img; + int rc; + + img = ipool->get(name,uid,true); + + if ( img == 0 ) + { + return 0; + } + + rc = acquire_image(img); + + if ( rc != 0 ) + { + img->unlock(); + img = 0; + } + + return img; +} + +/* -------------------------------------------------------------------------- */ + int ImageManager::acquire_image(Image *img) { int rc = 0; diff --git a/src/image/ImagePool.cc b/src/image/ImagePool.cc index 87ff03086a..b282e72a04 100644 --- a/src/image/ImagePool.cc +++ b/src/image/ImagePool.cc @@ -136,6 +136,69 @@ error_common: /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ +static int get_disk_uid(VectorAttribute * disk, int _uid) +{ + istringstream is; + + string uid_s ; + string uname; + int uid; + + if (!(uid_s = disk->vector_value("IMAGE_UID")).empty()) + { + is.str(uid_s); + is >> uid; + + if( is.fail() ) + { + return -1; + } + } + else if (!(uname = disk->vector_value("IMAGE_UNAME")).empty()) + { + User * user; + Nebula& nd = Nebula::instance(); + UserPool * upool = nd.get_upool(); + + user = upool->get(uname,true); + + if ( user == 0 ) + { + return -1; + } + + uid = user->get_oid(); + + user->unlock(); + } + else + { + uid = _uid; + } + + return uid; +} + +/* -------------------------------------------------------------------------- */ + +static int get_disk_id(const string& id_s) +{ + istringstream is; + int id; + + is.str(id_s); + is >> id; + + if( is.fail() ) + { + return -1; + } + + return id; +} + +/* -------------------------------------------------------------------------- */ + int ImagePool::disk_attribute(VectorAttribute * disk, int disk_id, int * index, @@ -152,36 +215,44 @@ int ImagePool::disk_attribute(VectorAttribute * disk, Nebula& nd = Nebula::instance(); ImageManager * imagem = nd.get_imagem(); - istringstream is; - - source = disk->vector_value("IMAGE"); - - if (!source.empty()) + if (!(source = disk->vector_value("IMAGE")).empty()) { - return -3; - } - - source = disk->vector_value("IMAGE_ID"); - - if (!source.empty()) - { - is.str(source); - is >> image_id; - - if( !is.fail() ) + int uiid = get_disk_uid(disk,uid); + + if ( uiid == -1) { - img = imagem->acquire_image(image_id); + return -1; + } - if (img == 0) - { - return -1; - } + img = imagem->acquire_image(source, uiid); + + if ( img == 0 ) + { + return -1; } } - - if (img == 0) + else if (!(source = disk->vector_value("IMAGE_ID")).empty()) { - string type = disk->vector_value("TYPE"); + int iid = get_disk_id(source); + + if ( iid == -1) + { + return -1; + } + + img = imagem->acquire_image(iid); + + if ( img == 0 ) + { + return -1; + } + } + else //Not using the image repository + { + string type; + + rc = -2; + type = disk->vector_value("TYPE"); transform(type.begin(),type.end(),type.begin(),(int(*)(int))toupper); @@ -198,13 +269,14 @@ int ImagePool::disk_attribute(VectorAttribute * disk, disk->replace("TARGET", dev_prefix); } } - - rc = -2; } - else + + if ( img != 0 ) { img->disk_attribute(disk, index, img_type); + image_id = img->get_oid(); + update(img); img->unlock(); @@ -224,22 +296,27 @@ void ImagePool::authorize_disk(VectorAttribute * disk,int uid, AuthRequest * ar) string source; Image * img = 0; - istringstream is; - int image_id; - - source = disk->vector_value("IMAGE_ID"); - - if (source.empty()) + if (!(source = disk->vector_value("IMAGE")).empty()) { - return; + int uiid = get_disk_uid(disk,uid); + + if ( uiid == -1) + { + return; + } + + img = get(source , uiid, true); } - - is.str(source); - is >> image_id; - - if( !is.fail() ) + else if (!(source = disk->vector_value("IMAGE_ID")).empty()) { - img = get(image_id,true); + int iid = get_disk_id(source); + + if ( iid == -1) + { + return; + } + + img = get(iid, true); } if (img == 0) diff --git a/src/image/test/ImagePoolTest.cc b/src/image/test/ImagePoolTest.cc index 4564f30339..3218dd3806 100644 --- a/src/image/test/ImagePoolTest.cc +++ b/src/image/test/ImagePoolTest.cc @@ -149,7 +149,8 @@ class ImagePoolTest : public PoolTest CPPUNIT_TEST ( imagepool_disk_attribute ); CPPUNIT_TEST ( dump ); CPPUNIT_TEST ( dump_where ); - + CPPUNIT_TEST ( get_using_name ); + CPPUNIT_TEST ( wrong_get_name ); CPPUNIT_TEST_SUITE_END (); protected: @@ -904,6 +905,64 @@ public: /* ********************************************************************* */ + void get_using_name() + { + int oid_0, oid_1; + ImagePool * imp = static_cast(pool); + + // Allocate two objects + oid_0 = allocate(0); + oid_1 = allocate(1); + + // --------------------------------- + // Get first object and check its integrity + obj = pool->get(oid_0, false); + CPPUNIT_ASSERT( obj != 0 ); + check(0, obj); + + // Get using its name + obj = imp->get(names[1], uids[1], true); + CPPUNIT_ASSERT( obj != 0 ); + obj->unlock(); + + check(1, obj); + + + // --------------------------------- + // Clean the cache, forcing the pool to read the objects from the DB + pool->clean(); + + // Get first object and check its integrity + obj = imp->get(names[0], uids[0], false); + check(0, obj); + + // Get using its name + obj = imp->get(oid_1, false); + check(1, obj); + }; + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + + void wrong_get_name() + { + ImagePool * imp = static_cast(pool); + + // The pool is empty + // Non existing name + obj = imp->get("Wrong name", 0, true); + CPPUNIT_ASSERT( obj == 0 ); + + // Allocate an object + allocate(0); + + // Ask again for a non-existing name + obj = imp->get("Non existing name",uids[0], true); + CPPUNIT_ASSERT( obj == 0 ); + } + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ }; /* ************************************************************************* */ diff --git a/src/image_mad/remotes/fs/fsrc b/src/image_mad/remotes/fs/fsrc index dcf439837c..fb3980a2af 100644 --- a/src/image_mad/remotes/fs/fsrc +++ b/src/image_mad/remotes/fs/fsrc @@ -55,7 +55,7 @@ echo "$IMAGE_REPOSITORY_PATH/`echo $CANONICAL_MD5 | cut -d ' ' -f1`" } function fs_du { - SIZE=`$(stat -c %s $1)` + SIZE=`stat -c %s $1` if [ $? -ne 0 ]; then SIZE=0 @@ -67,15 +67,19 @@ function fs_du { } function check_restricted { - if [ -n "`find -L $SAFE_DIRS -path $1 2>/dev/null`" ] ; then - echo 0 - return - fi + for path in $SAFE_DIRS ; do + if [ -n "`readlink -f $1 | grep -E "^$path"`" ] ; then + echo 0 + return + fi + done - if [ -n "`find -L $RESTRICTED_DIRS -path $1 2>/dev/null`" ]; then - echo 1 - return - fi + for path in $RESTRICTED_DIRS ; do + if [ -n "`readlink -f $1 | grep -E "^$path"`" ] ; then + echo 1 + return + fi + done echo 0 } \ No newline at end of file diff --git a/src/oca/ruby/OpenNebula/Configuration.rb b/src/oca/ruby/OpenNebula/Configuration.rb deleted file mode 100644 index aaef7fe89f..0000000000 --- a/src/oca/ruby/OpenNebula/Configuration.rb +++ /dev/null @@ -1,108 +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. # -#--------------------------------------------------------------------------- # - -module OpenNebula - ############################################################################ - # The Configuration Class represents a simple configuration file using - # OpenNebula syntax. It does not check syntax. - ############################################################################ - class Configuration - attr_reader :conf - - ######################################################################## - # 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(str) - parse_conf(str) - end - - def self.new_from_file(file) - conf_file = File.read(file) - self.new(conf_file) - end - - def add_value(key, value) - if @conf[key] - if !@conf[key].kind_of?(Array) - @conf[key]=[@conf[key]] - end - @conf[key]< Users need to have an authentication driver defined.\n"<< + " If you have AUTH_MAD uncommented in oned.conf, enter the driver name,\n"<< + " or press enter to use the default value.\n\n" + print " Driver name (x509, ssh, ldap): " + auth_driver = gets.chomp + [ [:group_pool, "group"], [:host_pool, "host"], [:image_pool, "image"], @@ -100,7 +106,17 @@ module Migrator # TODO: Try to guess if the password contains a DN and set the # driver to 'x509', or assume ssh if the password is not hex auth_elem = doc.root.add_element("AUTH_DRIVER") - auth_elem.text = "core" + + pass = "" + doc.root.each_element("PASSWORD") { |e| + pass = e.text + } + + if ( auth_driver.empty? || pass =~ /^(\d|[a-fA-F]){40}$/ ) + auth_elem.text = "core" + else + auth_elem.text = auth_driver + end doc.root.add_element("TEMPLATE") diff --git a/src/onedb/onedb b/src/onedb/onedb index 1f94760aa5..6fd05d5237 100755 --- a/src/onedb/onedb +++ b/src/onedb/onedb @@ -103,7 +103,7 @@ USERNAME={ :description => "MySQL username", :proc => lambda { |o, options| options[:backend] = :mysql - options[:username] = o + options[:user] = o } } @@ -115,7 +115,7 @@ PASSWORD={ :description => "MySQL password. Leave unset to be prompted for it", :proc => lambda { |o, options| options[:backend] = :mysql - options[:password] = o + options[:passwd] = o } } @@ -127,20 +127,12 @@ DBNAME={ :description => "MySQL DB name for OpenNebula", :proc => lambda { |o, options| options[:backend] = :mysql - options[:dbname] = o + options[:db_name] = o } } cmd=CommandParser::CmdParser.new(ARGV) do description <<-EOT.unindent - DB Connection options: - - By default, onedb reads the connection data from oned.conf - If any of these options is set, oned.conf is ignored (i.e. if you set - MySQL's port onedb won't look for the rest of the options in oned.conf) - - Description: - This command enables the user to manage the OpenNebula database. It provides information about the DB version, means to upgrade it to the latest version, and backup tools. diff --git a/src/onedb/onedb.rb b/src/onedb/onedb.rb index 9f6f1650b2..a6a041ad38 100644 --- a/src/onedb/onedb.rb +++ b/src/onedb/onedb.rb @@ -14,35 +14,32 @@ # limitations under the License. # #--------------------------------------------------------------------------- # -require 'OpenNebula/Configuration' require 'onedb_backend' class OneDB def initialize(ops) - if ops[:backend]==nil - from_onedconf - else - if ops[:backend] == :sqlite - @backend = BackEndSQLite.new(ops[:sqlite]) - else - passwd = ops[:passwd] - if !passwd - # Hide input characters - `stty -echo` - print "MySQL Password: " - passwd = STDIN.gets.strip - `stty echo` - puts "" - end - - @backend = BackEndMySQL.new( - :server => ops[:server], - :port => ops[:port], - :user => ops[:user], - :passwd => passwd, - :db_name => ops[:db_name] - ) + if ops[:backend] == :sqlite + @backend = BackEndSQLite.new(ops[:sqlite]) + elsif ops[:backend] == :mysql + passwd = ops[:passwd] + if !passwd + # Hide input characters + `stty -echo` + print "MySQL Password: " + passwd = STDIN.gets.strip + `stty echo` + puts "" end + + @backend = BackEndMySQL.new( + :server => ops[:server], + :port => ops[:port], + :user => ops[:user], + :passwd => passwd, + :db_name => ops[:db_name] + ) + else + raise "You need to specify the SQLite or MySQL connection options." end end @@ -151,32 +148,6 @@ class OneDB private - def from_onedconf() - config = OpenNebula::Configuration.new_from_file("#{ETC_LOCATION}/oned.conf") - - if config[:db] == nil - raise "No DB defined." - end - - if config[:db]["BACKEND"].upcase.include? "SQLITE" - sqlite_file = "#{VAR_LOCATION}/one.db" - @backend = BackEndSQLite.new(sqlite_file) - elsif config[:db]["BACKEND"].upcase.include? "MYSQL" - @backend = BackEndMySQL.new( - :server => config[:db]["SERVER"], - :port => config[:db]["PORT"], - :user => config[:db]["USER"], - :passwd => config[:db]["PASSWD"], - :db_name => config[:db]["DB_NAME"] - ) - else - raise "Could not load DB configuration from " << - "#{ETC_LOCATION}/oned.conf" - end - - return 0 - end - def one_not_running() if File.exists?(LOCK_FILE) raise "First stop OpenNebula. Lock file found: #{LOCK_FILE}" diff --git a/src/onedb/onedb_backend.rb b/src/onedb/onedb_backend.rb index 71cbda3324..b57ba32a1b 100644 --- a/src/onedb/onedb_backend.rb +++ b/src/onedb/onedb_backend.rb @@ -34,9 +34,11 @@ class OneDBBacKEnd return [version, timestamp, comment] - rescue - # If the DB doesn't have db_version table, it means it is empty or a 2.x - if !db_exists? + rescue Exception => e + if e.class == Sequel::DatabaseConnectionError + raise e + elsif !db_exists? + # If the DB doesn't have db_version table, it means it is empty or a 2.x raise "Database schema does not look to be created by " << "OpenNebula: table user_pool is missing or empty." end @@ -103,12 +105,16 @@ class OneDBBacKEnd def db_exists? begin + found = false + # User with ID 0 (oneadmin) always exists - @db.fetch("SELECT * FROM user_pool WHERE oid=0") { |row| } - return true + @db.fetch("SELECT * FROM user_pool WHERE oid=0") { |row| + found = true + } rescue - return false end + + return found end end diff --git a/src/onedb/test/test_mysql.sh b/src/onedb/test/test_mysql.sh index 8b07053057..d6f413f9d2 100755 --- a/src/onedb/test/test_mysql.sh +++ b/src/onedb/test/test_mysql.sh @@ -57,7 +57,7 @@ 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 -v +onedb backup results/mysqldb.3.0 -v -S localhost -P 0 -u oneadmin -p oneadmin -d onedb_test if [ $? -ne 0 ]; then exit -1 fi @@ -68,13 +68,13 @@ if [ $? -ne 0 ]; then fi # restore 2.2 -onedb restore -v -f 2.2/mysqldb.sql +onedb restore -v -f 2.2/mysqldb.sql -S localhost -P 0 -u oneadmin -p oneadmin -d onedb_test if [ $? -ne 0 ]; then exit -1 fi # upgrade -onedb upgrade -v --backup results/mysqldb.backup +echo "ssh" | onedb upgrade -v --backup results/mysqldb.backup -S localhost -P 0 -u oneadmin -p oneadmin -d onedb_test if [ $? -ne 0 ]; then exit -1 fi diff --git a/src/onedb/test/test_sqlite.sh b/src/onedb/test/test_sqlite.sh index f435fbe1a4..3daae85bfd 100755 --- a/src/onedb/test/test_sqlite.sh +++ b/src/onedb/test/test_sqlite.sh @@ -61,7 +61,7 @@ echo "All resources created, now 2.2 DB will be upgraded." cp $VAR_LOCATION/one.db results/one.db.3.0 cp 2.2/one.db results/one.db.upgraded -onedb upgrade -v --sqlite results/one.db.upgraded --backup results/one.db.backup +echo "ssh" | onedb upgrade -v --sqlite results/one.db.upgraded --backup results/one.db.backup if [ $? -ne 0 ]; then exit -1 diff --git a/src/ozones/Client/lib/zona.rb b/src/ozones/Client/lib/zona.rb index abc562c84a..b94e889c7f 100644 --- a/src/ozones/Client/lib/zona.rb +++ b/src/ozones/Client/lib/zona.rb @@ -18,7 +18,6 @@ require 'rubygems' require 'uri' require 'net/https' -require 'OpenNebula/Configuration' require 'zona/OZonesJSON' @@ -122,7 +121,7 @@ EOT # @param [String] tmpl_str OpenNebula template string # @return [String, Zona::Error] Response string or Error def post_resource_str(kind, tmpl_str) - tmpl_json = Zona.to_body(kind, tmpl_str) + tmpl_json = Zona.parse_template(kind, tmpl_str) post_resource(kind, tmpl_json) end @@ -150,7 +149,7 @@ EOT # @param [String] tmpl_str OpenNebula template string # @return [String, Zona::Error] Response string or Error def put_resource_str(kind, id, tmpl_str) - tmpl_json = Client.to_body(kind, tmpl_str) + tmpl_json = Zona.parse_template(kind, tmpl_str) put_resource(kind, id, tmpl_json) end @@ -261,7 +260,7 @@ EOT else if Zona.is_http_error?(value) str = "Operating with #{kind} failed with HTTP error" - str = " " + str + "code: #{value.code}\n" + str += " code: #{value.code}\n" if value.body # Try to extract error message begin @@ -281,13 +280,24 @@ EOT end - # Turns a OpenNebula template string into a JSON string + # Parses a OpenNebula template string and turns it into a JSON string # @param [String] kind element kind # @param [String] tmpl_str template # @return [String, Zona::Error] JSON string or Error - def self.to_body(kind, tmpl_str) - tmpl = OpenNebula::Configuration.new(tmpl_str) - res = { "#{kind.upcase}" => tmpl.conf } + def self.parse_template(kind, tmpl_str) + name_reg =/[\w\d_-]+/ + variable_reg =/\s*(#{name_reg})\s*=\s*/ + single_variable_reg =/^#{variable_reg}([^\[]+?)(#.*)?$/ + + tmpl = Hash.new + + tmpl_str.scan(single_variable_reg) do | m | + key = m[0].strip.upcase + value = m[1].strip + tmpl[key] = value + end + + res = { "#{kind.upcase}" => tmpl } return OZonesJSON.to_json(res) end diff --git a/src/ozones/Server/lib/OZones.rb b/src/ozones/Server/lib/OZones.rb index d75f060a36..6a08b01658 100644 --- a/src/ozones/Server/lib/OZones.rb +++ b/src/ozones/Server/lib/OZones.rb @@ -34,7 +34,6 @@ require 'base64' module OZones - CIPHER="aes-256-cbc" # ------------------------------------------------------------------------- # The Error Class represents a generic error in the OZones # library. It contains a readable representation of the error. @@ -72,37 +71,4 @@ module OZones def self.str_to_json(str) return JSON.pretty_generate({:message => str}) end - - def self.readKey - begin - credentials = File.read(ENV['OZONES_AUTH']).strip - return Digest::SHA1.hexdigest(credentials); - rescue - return ""; - end - end - - def self.encrypt(plain_txt) - #prepare cipher object - cipher = OpenSSL::Cipher.new(CIPHER) - cipher.encrypt - cipher.key = OZones.readKey - - enc_txt = cipher.update(plain_txt) - enc_txt << cipher.final - - Base64::encode64(enc_txt).strip.delete("\n") - end - - def self.decrypt(b64_txt) - #prepare cipher object - cipher = OpenSSL::Cipher.new(CIPHER) - cipher.decrypt - cipher.key = OZones.readKey - - enc_txt = Base64::decode64(b64_txt) - - plain_txt = cipher.update(enc_txt) - plain_txt << cipher.final - end -end +end \ No newline at end of file diff --git a/src/ozones/Server/lib/OZones/Zones.rb b/src/ozones/Server/lib/OZones/Zones.rb index b810792431..803aef19c7 100644 --- a/src/ozones/Server/lib/OZones/Zones.rb +++ b/src/ozones/Server/lib/OZones/Zones.rb @@ -47,31 +47,40 @@ module OZones zonePoolHash["ZONE_POOL"]["ZONE"] = Array.new unless self.all.empty? self.all.each{|zone| - zonePoolHash["ZONE_POOL"]["ZONE"] << - zone.attributes.merge({:NUMBERVDCS => zone.vdcs.all.size}) + zattr = zone.attributes.clone + + zattr[:ONEPASS] = Zones.encrypt(zattr[:ONEPASS]) + zattr[:NUMBERVDCS] = zone.vdcs.all.size + + zonePoolHash["ZONE_POOL"]["ZONE"] << zattr } return zonePoolHash end def to_hash - zone_attributes = Hash.new - zone_attributes["ZONE"] = attributes - zone_attributes["ZONE"][:VDCS] = Array.new + zattr = Hash.new + + zattr["ZONE"] = attributes.clone + zattr["ZONE"][:ONEPASS] = Zones.encrypt(zattr["ZONE"][:ONEPASS]) + zattr["ZONE"][:VDCS] = Array.new self.vdcs.all.each{|vdc| - zone_attributes["ZONE"][:VDCS]<< vdc.attributes + zattr["ZONE"][:VDCS]<< vdc.attributes.clone } - return zone_attributes + return zattr end def ONEPASS pw = super - OZones.decrypt(pw) + Zones.decrypt(pw) + end + + def ONEPASS=(plain_pw) + super(Zones.encrypt(plain_pw)) end - ####################################################################### # Zone Data Management ####################################################################### @@ -88,8 +97,6 @@ module OZones name = zone_data[:ONENAME] pass = zone_data[:ONEPASS] - zone_data[:ONEPASS] = OZones.encrypt(pass) - rc = OpenNebulaZone::check_oneadmin(name, pass, zone_data[:ENDPOINT]) @@ -113,6 +120,41 @@ module OZones return zone end + + ######################################################################## + # Encryption functions for the class + ######################################################################## + CIPHER = "aes-256-cbc" + + @@cipher = "" + + def self.cipher=(cipher) + @@cipher = cipher + end + + def self.encrypt(plain_txt) + #prepare cipher object + cipher = OpenSSL::Cipher.new(CIPHER) + cipher.encrypt + cipher.key = @@cipher + + enc_txt = cipher.update(plain_txt) + enc_txt << cipher.final + + Base64::encode64(enc_txt).strip.delete("\n") + end + + def self.decrypt(b64_txt) + #prepare cipher object + cipher = OpenSSL::Cipher.new(CIPHER) + cipher.decrypt + cipher.key = @@cipher + + enc_txt = Base64::decode64(b64_txt) + + plain_txt = cipher.update(enc_txt) + plain_txt << cipher.final + end end ########################################################################### diff --git a/src/ozones/Server/models/OzonesServer.rb b/src/ozones/Server/models/OzonesServer.rb index aca3c4b665..4c167c89cd 100644 --- a/src/ozones/Server/models/OzonesServer.rb +++ b/src/ozones/Server/models/OzonesServer.rb @@ -20,6 +20,11 @@ require 'JSONUtils' class OzonesServer include OpenNebulaJSON::JSONUtils + def initialize(cipher) + #Set cipher for Zone classes + OZones::Zones.cipher = cipher + end + ############################################################################ # Get methods for the Zones and VDC interface ############################################################################ diff --git a/src/ozones/Server/ozones-server.rb b/src/ozones/Server/ozones-server.rb index 85d93fd172..ef34108ee0 100755 --- a/src/ozones/Server/ozones-server.rb +++ b/src/ozones/Server/ozones-server.rb @@ -84,7 +84,7 @@ if Auth.all.size == 0 end credentials[1] = Digest::SHA1.hexdigest(credentials[1]) @auth=Auth.create({:name => credentials[0], - :password => credentials[1]}) + :password => credentials[1]}) @auth.save else warn "oZones admin credentials not set, missing OZONES_AUTH file." @@ -119,32 +119,23 @@ set :show_exceptions, false helpers do def authorized? - if session[:ip] && session[:ip]==request.ip - return true - end - - 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]) - - if user == ADMIN_NAME && sha1_pass == ADMIN_PASS - return true - end - end - return false + session[:ip] && session[:ip]==request.ip ? true : false 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]) + + user = auth.credentials[0] + pass = auth.credentials[1] + sha1_pass = Digest::SHA1.hexdigest(pass) if user == ADMIN_NAME && sha1_pass == ADMIN_PASS - session[:user] = user - session[:password] = sha1_pass - session[:ip] = request.ip + session[:user] = user + session[:ip] = request.ip + session[:key] = Digest::SHA1.hexdigest("#{user}:#{pass}") + session[:remember] = params[:remember] if params[:remember] @@ -164,15 +155,21 @@ helpers do session.clear return [204, ""] end - end before do unless request.path=='/login' || request.path=='/' - halt 401 unless authorized? - @OzonesServer = OzonesServer.new - @pr = OZones::ProxyRules.new("apache",config[:htaccess]) + unless authorized? + rc , msg = build_session + + if rc == 401 + halt 401 + end + end + + @OzonesServer = OzonesServer.new(session[:key]) + @pr = OZones::ProxyRules.new("apache",config[:htaccess]) end end diff --git a/src/ozones/Server/public/css/application.css b/src/ozones/Server/public/css/application.css index 91022b4068..c99f7b641e 100644 --- a/src/ozones/Server/public/css/application.css +++ b/src/ozones/Server/public/css/application.css @@ -175,7 +175,7 @@ fieldset textarea{ border-bottom:1px solid #ccc; border-right:1px solid #ccc;*/ padding:1px;color:#333; - vertical-align: top; + vertical-align: middle; margin: 0 2px; margin-bottom: 4px; } @@ -382,7 +382,7 @@ tr.even:hover{ .info_table td.key_td{ - width: 100%; + width: 55%; text-align:left; font-weight:bold; } @@ -395,6 +395,7 @@ tr.even:hover{ .info_table td.value_td{ text-align:left; + width: 45%; } #dialog > div > div { diff --git a/src/ozones/Server/public/js/plugins/vdcs-tab.js b/src/ozones/Server/public/js/plugins/vdcs-tab.js index 2f9f81ca7f..06ae83e6d5 100644 --- a/src/ozones/Server/public/js/plugins/vdcs-tab.js +++ b/src/ozones/Server/public/js/plugins/vdcs-tab.js @@ -271,6 +271,21 @@ function updateVDCsView(req,vdc_list){ function updateVDCInfo(req,vdc_json){ var vdc = vdc_json.VDC; + + var zone_endpoint = getElementData(vdc.ZONES_ID, + "#zone", + dataTable_zones)[3]; + var zone_host = ""; + var zone_port = ""; + var sun_link = ""; + var zone_match = zone_endpoint.match(/^http:\/\/(\w+):(\d+)\/RPC2$/); + + if (zone_match){ + zone_host = zone_match[1]; + zone_port = zone_match[2]; + sun_link = "http://" + zone_host +"/sunstone_"+ vdc.NAME; + }; + var info_tab = { title: "VDC Information", content : @@ -307,12 +322,24 @@ function updateVDCInfo(req,vdc_json){ ACLs\ '+vdc.ACLS+'\ \ + \ + Sunstone public link\ + '+(sun_link.length? ''+sun_link+'' : "")+'\ + \ + \ + ONE_XMLPRC (to export for CLI access)\ + \ + \ \ ' }; Sunstone.updateInfoPanelTab("vdc_info_panel","vdc_info_tab",info_tab); Sunstone.popUpInfoPanel("vdc_info_panel"); + $('#vdc_info_panel input#one_xmlrpc').select(); + setTimeout(function(){ + $('#vdc_info_panel input#one_xmlrpc').select(); + }, 700); } function fillHostList(req, host_list_json){ diff --git a/src/ozones/Server/public/js/plugins/zones-tab.js b/src/ozones/Server/public/js/plugins/zones-tab.js index d58be3b244..2bce15b604 100644 --- a/src/ozones/Server/public/js/plugins/zones-tab.js +++ b/src/ozones/Server/public/js/plugins/zones-tab.js @@ -39,14 +39,20 @@ var create_zone_tmpl = \ Name:\ \ - End point:\ - \ + End point (host,port):\ + :\ + \ + \ Oneadmin user:\ - \ + \ Password:\ - \ + \ Sunstone end point:\ - \ + ://\ + :\ + /\ + \ + \ \ \ \ @@ -301,7 +307,7 @@ function updateZoneInfo(req,zone_json){ '+zone.ENDPOINT+'\ \ \ - Sunstone endpoint\ + Sunstone endpoint\ '+ (zone.SUNSENDPOINT.length? ''+zone.SUNSENDPOINT+'' : "") +'\ \ \ @@ -539,7 +545,7 @@ function setupCreateZoneDialog(){ $('#create_zone_dialog').dialog({ autoOpen: false, modal: true, - width: 500 + width: 540 }); $('#create_zone_dialog button').button(); @@ -548,9 +554,13 @@ function setupCreateZoneDialog(){ $('#create_zone_form').submit(function(){ var name = $('#name', this).val(); var endpoint = $('#endpoint',this).val(); + var endpoint_port = $('#endpoint_port',this).val(); var onename = $('#onename',this).val(); var onepass = $('#onepass',this).val(); - var sunsendpoint = $('#sunsendpoint',this).val(); + var se = $('#sunsendpoint',this).val(); + var se_ptc = $('#sunsendpoint_ptc',this).val(); + var se_port = $('#sunsendpoint_port',this).val(); + var se_path = $('#sunsendpoint_path',this).val(); if (!name.length || !endpoint.length || !onename.length || !onepass.length){ @@ -558,13 +568,20 @@ function setupCreateZoneDialog(){ return false; } + endpoint = "http://"+ + endpoint+":"+endpoint_port+"/RPC2" + + if (se.length) + se = se_ptc + "://" + se + ":" + se_port + + "/" + se_path; + var zone_json = { "ZONE": { "NAME": name, "ENDPOINT": endpoint, "ONENAME": onename, "ONEPASS": onepass, - "SUNSENDPOINT" : sunsendpoint + "SUNSENDPOINT" : se } }; diff --git a/src/scheduler/include/Client.h b/src/scheduler/include/Client.h index f3339c1eec..01f85ad7a0 100644 --- a/src/scheduler/include/Client.h +++ b/src/scheduler/include/Client.h @@ -94,7 +94,7 @@ private: void set_one_endpoint(string endpoint); - int read_oneauth(string &secret); + void read_oneauth(string &secret); }; #endif /*ONECLIENT_H_*/ diff --git a/src/scheduler/src/client/Client.cc b/src/scheduler/src/client/Client.cc index f6152e675e..253414ec41 100644 --- a/src/scheduler/src/client/Client.cc +++ b/src/scheduler/src/client/Client.cc @@ -38,11 +38,9 @@ const int Client::MESSAGE_SIZE = 51200; void Client::set_one_auth(string secret) { - int rc = 0; - - if( secret == "" ) + if (secret.empty()) { - rc = read_oneauth(secret); + read_oneauth(secret); } one_auth = secret; @@ -51,7 +49,7 @@ void Client::set_one_auth(string secret) /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -int Client::read_oneauth(string &secret) +void Client::read_oneauth(string &secret) { ostringstream oss; string one_auth_file; @@ -59,7 +57,7 @@ int Client::read_oneauth(string &secret) const char * one_auth_env; ifstream file; - bool rc = -1; + int rc = -1; // Read $ONE_AUTH file and copy its contents into secret. one_auth_env = getenv("ONE_AUTH"); @@ -111,8 +109,6 @@ int Client::read_oneauth(string &secret) NebulaLog::log("XMLRPC",Log::ERROR,oss); throw runtime_error( oss.str() ); } - - return rc; } /* -------------------------------------------------------------------------- */ diff --git a/src/sunstone/models/OpenNebulaJSON/ImageJSON.rb b/src/sunstone/models/OpenNebulaJSON/ImageJSON.rb index c88dd6dae3..5c26e22f71 100644 --- a/src/sunstone/models/OpenNebulaJSON/ImageJSON.rb +++ b/src/sunstone/models/OpenNebulaJSON/ImageJSON.rb @@ -51,6 +51,7 @@ module OpenNebulaJSON when "unpublish" then self.unpublish when "update" then self.update(action_hash['params']) when "chown" then self.chown(action_hash['params']) + when "chtype" then self.chtype(action_hash['params']) else error_msg = "#{action_hash['perform']} action not " << " available for this resource" @@ -69,5 +70,9 @@ module OpenNebulaJSON def chown(params=Hash.new) super(params['owner_id'].to_i,params['group_id'].to_i) end + + def chtype(params=Hash.new) + super(params['type']) + end end end diff --git a/src/sunstone/public/js/opennebula.js b/src/sunstone/public/js/opennebula.js index 0269c92e8e..325d07bb3a 100644 --- a/src/sunstone/public/js/opennebula.js +++ b/src/sunstone/public/js/opennebula.js @@ -745,6 +745,13 @@ var OpenNebula = { }, "nonpersistent": function(params){ OpenNebula.Action.simple_action(params,OpenNebula.Image.resource,"nonpersistent"); + }, + "chtype": function(params){ + var action_obj = {"type" : params.data.extra_param}; + OpenNebula.Action.simple_action(params, + OpenNebula.Image.resource, + "chtype", + action_obj); } }, diff --git a/src/sunstone/public/js/plugins/images-tab.js b/src/sunstone/public/js/plugins/images-tab.js index 72d9c2825a..e42254b685 100644 --- a/src/sunstone/public/js/plugins/images-tab.js +++ b/src/sunstone/public/js/plugins/images-tab.js @@ -28,6 +28,7 @@ var images_tab_content = Owner\ Group\ Name\ + Size\ Type\ Registration time\ Public\ @@ -95,6 +96,11 @@ var create_image_tmpl = \ Type of disk device to emulate.\ \ + \ + Driver:\ + \ + Specific image mapping driver. KVM: raw, qcow2 and Xen:tap:aio:, file:\ + \ \ \ \ @@ -372,7 +378,19 @@ var image_actions = { elements: imageElements, error: onError, notify: true + }, + + "Image.chtype" : { + type: "single", + call: OpenNebula.Image.chtype, + callback: function (req) { + Sunstone.runAction("Image.show",req.request.data[0]); + }, + elements: imageElements, + error: onError, + notify: true } + } @@ -473,13 +491,26 @@ function imageElements() { function imageElementArray(image_json){ //Changing this? It may affect to the is_public() and is_persistent() functions. var image = image_json.IMAGE; + + var type = $('\ + OS\ + CD-ROM\ + Datablock\ + '); + + var value = OpenNebula.Helper.image_type(image.TYPE); + $('option[value="'+value+'"]',type).replaceWith(''+value+''); + + + return [ '', image.ID, image.UNAME, image.GNAME, image.NAME, - OpenNebula.Helper.image_type(image.TYPE), + image.SIZE, + ''+type.html()+'', pretty_time(image.REGTIME), parseInt(image.PUBLIC) ? '' : '', @@ -493,7 +524,11 @@ function imageElementArray(image_json){ // Set up the listener on the table TDs to show the info panel function imageInfoListener(){ $('#tbodyimages tr',dataTable_images).live("click",function(e){ - if ($(e.target).is('input')) {return true;} + var target = $(e.target); + + if (target.is('input') || target.is('select') || target.is('option')) + return true; + popDialogLoading(); var aData = dataTable_images.fnGetData(this); var id = $(aData[0]).val(); @@ -595,12 +630,28 @@ function updateImageInfo(request,img){ \ \ Source\ - '+img_info.SOURCE+'\ + '+(typeof img_info.SOURCE === "string" ? img_info.SOURCE : "--")+'\ + \ + \ + Path\ + '+(typeof img_info.PATH === "string" ? img_info.PATH : "--")+'\ + \ + \ + Filesystem type\ + '+(typeof img_info.FSTYPE === "string" ? img_info.FSTYPE : "--")+'\ + \ + \ + Size (Mb)\ + '+img_info.SIZE+'\ \ \ State\ '+OpenNebula.Helper.resource_state("image",img_info.STATE)+'\ \ + \ + Running #VMS\ + '+img_info.RUNNING_VMS+'\ + \ ' } @@ -755,6 +806,10 @@ function setupCreateImageDialog(){ var bus = $('#img_bus',this).val(); img_json["BUS"] = bus; + var driver = $('#img_driver',this).val(); + if (driver.length) + img_json["DRIVER"] = driver; + switch ($('#src_path_select input:checked',this).val()){ case "path": path = $('#img_path',this).val(); @@ -970,6 +1025,15 @@ function setupImageActionCheckboxes(){ return true; }); + + $('select.action_cb#select_chtype_image', dataTable_images).live("change",function(){ + var $this = $(this); + var value = $this.val(); + var id = $this.attr("elem_id"); + + Sunstone.runAction("Image.chtype", id, value); + }); + } //The DOM is ready at this point @@ -982,17 +1046,17 @@ $(document).ready(function(){ "sPaginationType": "full_numbers", "aoColumnDefs": [ { "bSortable": false, "aTargets": ["check"] }, - { "sWidth": "60px", "aTargets": [0,2,3,5,7,8,9] }, - { "sWidth": "35px", "aTargets": [1,10] }, - { "sWidth": "100px", "aTargets": [9] }, - { "sWidth": "150px", "aTargets": [6] } + { "sWidth": "60px", "aTargets": [0,2,3,8,9,10] }, + { "sWidth": "35px", "aTargets": [1,5,11] }, + { "sWidth": "100px", "aTargets": [6] }, + { "sWidth": "150px", "aTargets": [7] } ] }); dataTable_images.fnClearTable(); addElement([ spinner, - '','','','','','','','','',''],dataTable_images); + '','','','','','','','','','',''],dataTable_images); Sunstone.runAction("Image.list"); setupCreateImageDialog(); diff --git a/src/sunstone/public/js/plugins/users-tab.js b/src/sunstone/public/js/plugins/users-tab.js index 0835a12c2a..50d2743a6e 100644 --- a/src/sunstone/public/js/plugins/users-tab.js +++ b/src/sunstone/public/js/plugins/users-tab.js @@ -50,9 +50,11 @@ var create_user_tmpl = Authentication:\ \ Core\ - SSH\ - x509\ - Server\ + SSH\ + x509\ + Server (Cipher)\ + Server (x509)\ + Public\ \ \ \ @@ -256,10 +258,12 @@ var user_buttons = { type: "confirm_with_select", text: "Change authentication", select: function() { - return 'Core\ - SSH\ - x509\ - Server' + return 'Core\ + SSH\ + x509\ + Server (Cipher)\ + Server (x509)\ + Public' }, tip: "Please choose the new type of authentication for the selected users:" }, diff --git a/src/sunstone/public/js/plugins/vnets-tab.js b/src/sunstone/public/js/plugins/vnets-tab.js index 208e4ce200..8523a961f5 100644 --- a/src/sunstone/public/js/plugins/vnets-tab.js +++ b/src/sunstone/public/js/plugins/vnets-tab.js @@ -526,6 +526,10 @@ function updateVNetworkInfo(request,vn){ Public\ '+(parseInt(vn_info.PUBLIC) ? "yes" : "no" )+'\ \ + \ + Physical device\ + '+(vn_info.PHYDEV ? vn_info.PHYDEV : "--" )+'\ + \ \ \ \ diff --git a/src/sunstone/public/js/sunstone-util.js b/src/sunstone/public/js/sunstone-util.js index 415f279976..8918a8cb33 100644 --- a/src/sunstone/public/js/sunstone-util.js +++ b/src/sunstone/public/js/sunstone-util.js @@ -196,19 +196,19 @@ function notifySubmit(action, args, extra_param){ msg += " >> " + extra_param; }; - $.jGrowl(msg, {theme: "jGrowl-notify-submit"}); + $.jGrowl(msg, {theme: "jGrowl-notify-submit", position: "bottom-right"}); } //Notification on error function notifyError(msg){ msg = "Error" + msg; - $.jGrowl(msg, {theme: "jGrowl-notify-error", sticky: true }); + $.jGrowl(msg, {theme: "jGrowl-notify-error", position: "bottom-right", sticky: true }); } //Standard notification function notifyMessage(msg){ msg = "Info" + msg; - $.jGrowl(msg, {theme: "jGrowl-notify-submit"}); + $.jGrowl(msg, {theme: "jGrowl-notify-submit", position: "bottom-right"}); } // Returns an HTML string with the json keys and values diff --git a/src/sunstone/sunstone-server.rb b/src/sunstone/sunstone-server.rb index 56944d0425..e901caa82c 100755 --- a/src/sunstone/sunstone-server.rb +++ b/src/sunstone/sunstone-server.rb @@ -88,11 +88,11 @@ helpers do end def build_session - # begin + begin result = settings.cloud_auth.auth(request.env, params) - # rescue Exception => e - # error 500, e.message - # end + rescue Exception => e + error 500, e.message + end if result.nil? return [401, ""] diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index 349f57b8ba..d8d4f9a526 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -759,14 +759,6 @@ int VirtualMachine::get_disk_images(string& error_str) { goto error_image; } - else if ( rc == -3) - { - goto error_name; - } - else if ( rc != -2 ) // The only known code left - { - goto error_unknown; - } } return 0; @@ -787,13 +779,6 @@ error_image: error_str = "Could not get disk image for VM."; goto error_common; -error_name: - error_str = "IMAGE is not supported for DISK. Use IMAGE_ID instead."; - goto error_common; - -error_unknown: - error_str = "Unknown error code."; - error_common: ImageManager * imagem = nd.get_imagem(); @@ -890,22 +875,12 @@ int VirtualMachine::get_network_leases(string& estr) { goto error_vnet; } - else if ( rc == -3 ) - { - goto error_name; - } } return 0; error_vnet: estr = "Could not get virtual network for VM."; - goto error_common; - -error_name: - estr = "NETWORK is not supported for NIC. Use NETWORK_ID instead."; - -error_common: return -1; } diff --git a/src/vnm/VirtualNetworkPool.cc b/src/vnm/VirtualNetworkPool.cc index 44a50d9fd2..02542b5564 100644 --- a/src/vnm/VirtualNetworkPool.cc +++ b/src/vnm/VirtualNetworkPool.cc @@ -15,7 +15,9 @@ /* -------------------------------------------------------------------------- */ #include "VirtualNetworkPool.h" +#include "UserPool.h" #include "NebulaLog.h" +#include "Nebula.h" #include "AuthManager.h" #include @@ -137,35 +139,86 @@ error_common: /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ +VirtualNetwork * VirtualNetworkPool::get_nic_by_name(VectorAttribute * nic, + const string& name, + int _uid) +{ + istringstream is; + + string uid_s ; + string uname; + int uid; + + if (!(uid_s = nic->vector_value("NETWORK_UID")).empty()) + { + is.str(uid_s); + is >> uid; + + if( is.fail() ) + { + return 0; + } + } + else if (!(uname = nic->vector_value("NETWORK_UNAME")).empty()) + { + User * user; + Nebula& nd = Nebula::instance(); + UserPool * upool = nd.get_upool(); + + user = upool->get(uname,true); + + if ( user == 0 ) + { + return 0; + } + + uid = user->get_oid(); + + user->unlock(); + } + else + { + uid = _uid; + } + + return get(name,uid,true); +} + +/* -------------------------------------------------------------------------- */ + +VirtualNetwork * VirtualNetworkPool::get_nic_by_id(const string& id_s) +{ + istringstream is; + int id; + + is.str(id_s); + is >> id; + + if( is.fail() ) + { + return 0; + } + + return get(id,true); +} + int VirtualNetworkPool::nic_attribute(VectorAttribute * nic, int uid, int vid) { string network; VirtualNetwork * vnet = 0; - istringstream is; - int network_id; - - network = nic->vector_value("NETWORK"); - - if (!network.empty()) + if (!(network = nic->vector_value("NETWORK")).empty()) { - return -3; + vnet = get_nic_by_name (nic, network, uid); } - - network = nic->vector_value("NETWORK_ID"); - - if(network.empty()) + else if (!(network = nic->vector_value("NETWORK_ID")).empty()) + { + vnet = get_nic_by_id(network); + } + else //Not using a pre-defined network { return -2; - } - - is.str(network); - is >> network_id; - - if( !is.fail() ) - { - vnet = get(network_id,true); - } + } if (vnet == 0) { @@ -194,23 +247,18 @@ void VirtualNetworkPool::authorize_nic(VectorAttribute * nic, string network; VirtualNetwork * vnet = 0; - istringstream is; - int network_id; - - network = nic->vector_value("NETWORK_ID"); - - if(network.empty()) + if (!(network = nic->vector_value("NETWORK")).empty()) + { + vnet = get_nic_by_name (nic, network, uid); + } + else if (!(network = nic->vector_value("NETWORK_ID")).empty()) + { + vnet = get_nic_by_id(network); + } + else //Not using a pre-defined network { return; - } - - is.str(network); - is >> network_id; - - if( !is.fail() ) - { - vnet = get(network_id,true); - } + } if (vnet == 0) { @@ -225,4 +273,4 @@ void VirtualNetworkPool::authorize_nic(VectorAttribute * nic, vnet->isPublic()); vnet->unlock(); -} +} \ No newline at end of file diff --git a/src/vnm/test/VirtualNetworkPoolTest.cc b/src/vnm/test/VirtualNetworkPoolTest.cc index e7854565e1..2d5801309c 100644 --- a/src/vnm/test/VirtualNetworkPoolTest.cc +++ b/src/vnm/test/VirtualNetworkPoolTest.cc @@ -1151,17 +1151,7 @@ public: // Disk using network 0 disk = new VectorAttribute("DISK"); - disk->replace("NETWORK", "A net"); - - int rc = ((VirtualNetworkPool*)vnp)->nic_attribute(disk, 0, 0); - - CPPUNIT_ASSERT( rc == -3 ); - - delete disk; - - // Disk using network 0 - disk = new VectorAttribute("DISK"); - disk->replace("NETWORK_ID", "0"); + disk->replace("NETWORK", "Net 0"); ((VirtualNetworkPool*)vnp)->nic_attribute(disk, 0, 0);