From e540743a3b26161092ceed215ef63e6bfeb90967 Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Thu, 8 Sep 2011 19:23:43 +0200 Subject: [PATCH 01/34] Sunstone: Fix some widths in create ACL dialog Affects the proper alignment of the deploy checkbox and the acl string preview field position. --- src/sunstone/public/js/plugins/acls-tab.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sunstone/public/js/plugins/acls-tab.js b/src/sunstone/public/js/plugins/acls-tab.js index d25e45dc49..d78f542fd4 100644 --- a/src/sunstone/public/js/plugins/acls-tab.js +++ b/src/sunstone/public/js/plugins/acls-tab.js @@ -65,7 +65,7 @@ var create_acl_tmpl = \ \
\ - \ + \ Create
\ Delete
\ Use
\ @@ -312,7 +312,7 @@ function setupCreateAclDialog(){ dialog.dialog({ autoOpen: false, modal:true, - width: 600, + width: 650, height: height }); From 67bc4108b30ed3fa8bc0abac465f5560e5a3d6bd Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Sat, 24 Sep 2011 20:57:16 +0200 Subject: [PATCH 02/34] Bug #829: Typo in config variable in Sunstone Server --- src/sunstone/sunstone-server.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sunstone/sunstone-server.rb b/src/sunstone/sunstone-server.rb index 392579bb1c..8935afd89e 100755 --- a/src/sunstone/sunstone-server.rb +++ b/src/sunstone/sunstone-server.rb @@ -167,7 +167,7 @@ end get '/login' do if !authorized? - templ = settings.confing[:auth]=="basic"? "login.html" : "login_x509.html" + templ = settings.config[:auth]=="basic"? "login.html" : "login_x509.html" return File.read(File.dirname(__FILE__)+'/templates/'+templ) end end From a190dd1499c1e716fad3238d23ddcef75f1795bd Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Mon, 31 Oct 2011 18:04:22 +0100 Subject: [PATCH 03/34] Notifications in bottom-right corner --- src/sunstone/public/js/sunstone-util.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 From ec7f0c3275da04f6a9deeaea93ed9f9c847bd656 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Mon, 31 Oct 2011 23:38:41 +0100 Subject: [PATCH 04/34] Make auth_mad enabled by default as now is needed by the servers --- share/etc/oned.conf | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) 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 From 45e4923dc0fec7cd99e0c9e6c5953473e4747bad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Wed, 2 Nov 2011 17:36:53 +0100 Subject: [PATCH 05/34] Fixes outdated xml-rpc methods signatures --- include/RequestManagerAllocate.h | 2 +- include/RequestManagerVirtualMachine.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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(){}; From e2f5a0734974645f8d80fe0a20c829f8e17f4adb Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Thu, 3 Nov 2011 01:21:30 +0100 Subject: [PATCH 06/34] feature #959: cipher to encrypt/decrypt oneadmin pass is now set for the Zone classes. Now it does not require it to be set in OZONE_AUTH file --- src/ozones/Server/lib/OZones.rb | 36 +------------------ src/ozones/Server/lib/OZones/Zones.rb | 44 +++++++++++++++++++++--- src/ozones/Server/models/OzonesServer.rb | 5 +++ src/ozones/Server/ozones-server.rb | 3 +- 4 files changed, 48 insertions(+), 40 deletions(-) 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..e652666742 100644 --- a/src/ozones/Server/lib/OZones/Zones.rb +++ b/src/ozones/Server/lib/OZones/Zones.rb @@ -68,10 +68,13 @@ module OZones def ONEPASS pw = super - OZones.decrypt(pw) + decrypt(pw) + end + + def ONEPASS=(plain_pw) + super(encrypt(plain_pw)) end - ####################################################################### # Zone Data Management ####################################################################### @@ -88,8 +91,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 +114,41 @@ module OZones return zone end + + ######################################################################## + # Encryption functions for the class + ######################################################################## + CIPHER = "aes-256-cbc" + + @@cipher = "" + + def self.cipher=(cipher) + @@cipher = cipher + end + + def 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 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..c5b64120f8 100755 --- a/src/ozones/Server/ozones-server.rb +++ b/src/ozones/Server/ozones-server.rb @@ -96,6 +96,7 @@ end ADMIN_NAME = @auth.name ADMIN_PASS = @auth.password +ADMIN_KEY = Digest::SHA1.hexdigest("ADMIN_NAME:ADMIN_PASS") begin OZones::ProxyRules.new("apache",config[:htaccess]) @@ -171,7 +172,7 @@ before do unless request.path=='/login' || request.path=='/' halt 401 unless authorized? - @OzonesServer = OzonesServer.new + @OzonesServer = OzonesServer.new(ADMIN_KEY) @pr = OZones::ProxyRules.new("apache",config[:htaccess]) end end From 648cf2e8faf2792accb10bfca348c96d691a5f2e Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Thu, 3 Nov 2011 01:45:06 +0100 Subject: [PATCH 07/34] featurei #952: Key now is generated with zones admin. Key can not be regenerated with DB data --- src/ozones/Server/ozones-server.rb | 37 +++++++++++------------------- src/sunstone/sunstone-server.rb | 8 +++---- 2 files changed, 17 insertions(+), 28 deletions(-) diff --git a/src/ozones/Server/ozones-server.rb b/src/ozones/Server/ozones-server.rb index c5b64120f8..7863c4b64a 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." @@ -96,7 +96,6 @@ end ADMIN_NAME = @auth.name ADMIN_PASS = @auth.password -ADMIN_KEY = Digest::SHA1.hexdigest("ADMIN_NAME:ADMIN_PASS") begin OZones::ProxyRules.new("apache",config[:htaccess]) @@ -120,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] @@ -165,15 +155,14 @@ helpers do session.clear return [204, ""] end - end before do unless request.path=='/login' || request.path=='/' halt 401 unless authorized? - @OzonesServer = OzonesServer.new(ADMIN_KEY) - @pr = OZones::ProxyRules.new("apache",config[:htaccess]) + @OzonesServer = OzonesServer.new(session[:key]) + @pr = OZones::ProxyRules.new("apache",config[:htaccess]) end end 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, ""] From 32752aa87cc0a82bac30aa379a96971c5039f640 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Thu, 3 Nov 2011 02:01:10 +0100 Subject: [PATCH 08/34] featurei #952: Send oneadmin password for a zone encryted through the REST API --- src/ozones/Server/lib/OZones/Zones.rb | 28 ++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/ozones/Server/lib/OZones/Zones.rb b/src/ozones/Server/lib/OZones/Zones.rb index e652666742..59075f24f1 100644 --- a/src/ozones/Server/lib/OZones/Zones.rb +++ b/src/ozones/Server/lib/OZones/Zones.rb @@ -47,32 +47,38 @@ 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[:ONE_PASS] = Zones.encrypt(zattr[:ONEPASS]) + zattr.merge({: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 - decrypt(pw) + Zones.decrypt(pw) end def ONEPASS=(plain_pw) - super(encrypt(plain_pw)) + super(Zones.encrypt(plain_pw)) end ####################################################################### @@ -126,7 +132,7 @@ module OZones @@cipher = cipher end - def encrypt(plain_txt) + def self.encrypt(plain_txt) #prepare cipher object cipher = OpenSSL::Cipher.new(CIPHER) cipher.encrypt @@ -138,7 +144,7 @@ module OZones Base64::encode64(enc_txt).strip.delete("\n") end - def decrypt(b64_txt) + def self.decrypt(b64_txt) #prepare cipher object cipher = OpenSSL::Cipher.new(CIPHER) cipher.decrypt From d578c13ab3b48163cf4c68521bbbe1ffddda2132 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Thu, 3 Nov 2011 02:05:18 +0100 Subject: [PATCH 09/34] feature #952: Fix wrong symbol name for ONEPASS --- src/ozones/Server/lib/OZones/Zones.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ozones/Server/lib/OZones/Zones.rb b/src/ozones/Server/lib/OZones/Zones.rb index 59075f24f1..36ad9c709b 100644 --- a/src/ozones/Server/lib/OZones/Zones.rb +++ b/src/ozones/Server/lib/OZones/Zones.rb @@ -49,7 +49,7 @@ module OZones self.all.each{|zone| zattr = zone.attributes.clone - zattr[:ONE_PASS] = Zones.encrypt(zattr[:ONEPASS]) + zattr[:ONEPASS] = Zones.encrypt(zattr[:ONEPASS]) zattr.merge({:NUMBERVDCS => zone.vdcs.all.size}) zonePoolHash["ZONE_POOL"]["ZONE"] << zattr From 05df65f119e2ce033b19067261c3363586182f55 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Thu, 3 Nov 2011 02:06:22 +0100 Subject: [PATCH 10/34] feature #952: Better zone render --- src/ozones/Server/lib/OZones/Zones.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ozones/Server/lib/OZones/Zones.rb b/src/ozones/Server/lib/OZones/Zones.rb index 36ad9c709b..803aef19c7 100644 --- a/src/ozones/Server/lib/OZones/Zones.rb +++ b/src/ozones/Server/lib/OZones/Zones.rb @@ -49,8 +49,8 @@ module OZones self.all.each{|zone| zattr = zone.attributes.clone - zattr[:ONEPASS] = Zones.encrypt(zattr[:ONEPASS]) - zattr.merge({:NUMBERVDCS => zone.vdcs.all.size}) + zattr[:ONEPASS] = Zones.encrypt(zattr[:ONEPASS]) + zattr[:NUMBERVDCS] = zone.vdcs.all.size zonePoolHash["ZONE_POOL"]["ZONE"] << zattr } From 74dd9055836ad9e0a6aaf33ae346dc6700311aed Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Wed, 2 Nov 2011 21:15:42 +0100 Subject: [PATCH 11/34] Feature #959: Add chtype support in images table. (cherry picked from commit 67792bc663ea51352bbf5e3ce377becb0b71cb9b) --- .../models/OpenNebulaJSON/ImageJSON.rb | 5 +++ src/sunstone/public/js/opennebula.js | 7 ++++ src/sunstone/public/js/plugins/images-tab.js | 41 ++++++++++++++++++- 3 files changed, 51 insertions(+), 2 deletions(-) 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..78a23a84f1 100644 --- a/src/sunstone/public/js/plugins/images-tab.js +++ b/src/sunstone/public/js/plugins/images-tab.js @@ -372,7 +372,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 +485,25 @@ 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 = $(''); + + var value = OpenNebula.Helper.image_type(image.TYPE); + $('option[value="'+value+'"]',type).replaceWith(''); + + + return [ '', image.ID, image.UNAME, image.GNAME, image.NAME, - OpenNebula.Helper.image_type(image.TYPE), + '', pretty_time(image.REGTIME), parseInt(image.PUBLIC) ? '' : '', @@ -493,7 +517,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(); @@ -970,6 +998,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 From ddff4af949fb5d2cb58437c8f6b9f89058a8d096 Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Wed, 2 Nov 2011 23:07:57 +0100 Subject: [PATCH 12/34] Feature #898: Add driver attribute to image wizard (cherry picked from commit b3ea3bee5133773a4aa7cd78570674098f166ec8) --- src/sunstone/public/js/plugins/images-tab.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/sunstone/public/js/plugins/images-tab.js b/src/sunstone/public/js/plugins/images-tab.js index 78a23a84f1..8f5f7c57d8 100644 --- a/src/sunstone/public/js/plugins/images-tab.js +++ b/src/sunstone/public/js/plugins/images-tab.js @@ -95,6 +95,11 @@ var create_image_tmpl = \
Type of disk device to emulate.
\ \ +
\ + \ + \ +
Specific image mapping driver. KVM: raw, qcow2 and Xen:tap:aio:, file:
\ +
\ \
\
\ @@ -783,6 +788,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(); From ec54b609c9f99237cbf2cf97a31c2800133fb490 Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Tue, 1 Nov 2011 00:37:18 +0100 Subject: [PATCH 13/34] Task #912: Update again the possible user auth drivers with the latest possible list. (cherry picked from commit 255c6fef2706806881a04ddc7a454f5f95950c0a) --- src/sunstone/public/js/plugins/users-tab.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) 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 = \ \
\
\ @@ -256,10 +258,12 @@ var user_buttons = { type: "confirm_with_select", text: "Change authentication", select: function() { - return '\ - \ - \ - ' + return '\ + \ + \ + \ + \ + ' }, tip: "Please choose the new type of authentication for the selected users:" }, From 3986ef27f798e2afd6297ba0b0a962dd525e6d8b Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Thu, 3 Nov 2011 09:19:29 +0100 Subject: [PATCH 14/34] Fix image type select width (cherry picked from commit ad7644ad56993b2625901c8014437e599d21092d) --- src/sunstone/public/js/plugins/images-tab.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/sunstone/public/js/plugins/images-tab.js b/src/sunstone/public/js/plugins/images-tab.js index 8f5f7c57d8..332971326a 100644 --- a/src/sunstone/public/js/plugins/images-tab.js +++ b/src/sunstone/public/js/plugins/images-tab.js @@ -508,7 +508,7 @@ function imageElementArray(image_json){ image.UNAME, image.GNAME, image.NAME, - '', + '', pretty_time(image.REGTIME), parseInt(image.PUBLIC) ? '' : '', @@ -1028,9 +1028,9 @@ $(document).ready(function(){ "sPaginationType": "full_numbers", "aoColumnDefs": [ { "bSortable": false, "aTargets": ["check"] }, - { "sWidth": "60px", "aTargets": [0,2,3,5,7,8,9] }, + { "sWidth": "60px", "aTargets": [0,2,3,7,8,9] }, { "sWidth": "35px", "aTargets": [1,10] }, - { "sWidth": "100px", "aTargets": [9] }, + { "sWidth": "100px", "aTargets": [5,9] }, { "sWidth": "150px", "aTargets": [6] } ] }); From fdaaa3644faad23ee7b8cfee334824eb30c3f390 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Thu, 3 Nov 2011 23:40:24 +0100 Subject: [PATCH 15/34] bug #955: Fix file size calculation --- src/image_mad/remotes/fs/fsrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/image_mad/remotes/fs/fsrc b/src/image_mad/remotes/fs/fsrc index dcf439837c..24ad43fbd6 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 From 95f61805d64416f528142363e733f8d7af1ad435 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Thu, 27 Oct 2011 11:55:39 +0200 Subject: [PATCH 16/34] fix accounting (cherry picked from commit 9e15507429b46789455f66babb4efe74e168a26c) --- src/acct/watch_helper.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 } From a1b72d534a0130cbe8503fb6109f9020e82ce52b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Fri, 4 Nov 2011 18:18:37 +0100 Subject: [PATCH 17/34] Bug #964: Fix the onedb command options parsing, the mysql options were ignored --- src/onedb/onedb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/onedb/onedb b/src/onedb/onedb index 1f94760aa5..12551c3b3b 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,7 +127,7 @@ DBNAME={ :description => "MySQL DB name for OpenNebula", :proc => lambda { |o, options| options[:backend] = :mysql - options[:dbname] = o + options[:db_name] = o } } From 39e93340af651f0009ad7e410bcb1f2c2f4c4783 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Fri, 4 Nov 2011 18:58:24 +0100 Subject: [PATCH 18/34] Improve onedb error handling --- src/onedb/onedb_backend.rb | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) 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 From 5923fc665727056af80732ca7cd86123ae174ffc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Mon, 7 Nov 2011 12:34:16 +0100 Subject: [PATCH 19/34] Bug #961: Temp. fix to parse only DB attribute from oned.conf --- src/oca/ruby/OpenNebula/Configuration.rb | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/oca/ruby/OpenNebula/Configuration.rb b/src/oca/ruby/OpenNebula/Configuration.rb index aaef7fe89f..aab519973a 100644 --- a/src/oca/ruby/OpenNebula/Configuration.rb +++ b/src/oca/ruby/OpenNebula/Configuration.rb @@ -78,16 +78,20 @@ module OpenNebula 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(master_key, vars) + # TODO: This method is only used by onedb. + # Temporary workaround to parse only the DB array, see Bug #961 + if ( master_key == "DB" ) + pieces=m[1].split(',') + + vars=Hash.new + pieces.each {|p| + key, value=p.split('=') + vars[key.strip.upcase]=value.strip + } + + add_value(master_key, vars) + end } end From 624fe79a9fd3bb9f6dcc5f24c62c1d81b03d58f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Mon, 7 Nov 2011 12:35:15 +0100 Subject: [PATCH 20/34] onedb asks for the external authentication driver in the 3.0 to 3.1 upgrade --- src/onedb/3.0.0_to_3.1.0.rb | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/onedb/3.0.0_to_3.1.0.rb b/src/onedb/3.0.0_to_3.1.0.rb index c68b9122ed..c7ebf0caa5 100644 --- a/src/onedb/3.0.0_to_3.1.0.rb +++ b/src/onedb/3.0.0_to_3.1.0.rb @@ -31,6 +31,12 @@ module Migrator # Update table definitions ######################################################################## + puts " > 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") From 38b2718c876bce73463efe70a8eb5753b4f13d68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Mon, 7 Nov 2011 18:26:53 +0100 Subject: [PATCH 21/34] Avoid using the find command to check if new image files are safe, for better performance --- src/image_mad/remotes/fs/fsrc | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/image_mad/remotes/fs/fsrc b/src/image_mad/remotes/fs/fsrc index 24ad43fbd6..fb3980a2af 100644 --- a/src/image_mad/remotes/fs/fsrc +++ b/src/image_mad/remotes/fs/fsrc @@ -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 From f2b57d77d257d3bdfe67772fb1f53c639523dc0b Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Mon, 7 Nov 2011 17:56:38 +0100 Subject: [PATCH 22/34] Feature #954: Add some new resource attributes to Sunstone. Size, Path for images, PhyDev for vnets... (cherry picked from commit 4d25b5a655701c76c01df8ee65eb694a4c316c38) --- src/sunstone/public/js/plugins/images-tab.js | 30 ++++++++++++++++---- src/sunstone/public/js/plugins/vnets-tab.js | 4 +++ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/sunstone/public/js/plugins/images-tab.js b/src/sunstone/public/js/plugins/images-tab.js index 332971326a..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\ @@ -508,6 +509,7 @@ function imageElementArray(image_json){ image.UNAME, image.GNAME, image.NAME, + image.SIZE, '', pretty_time(image.REGTIME), parseInt(image.PUBLIC) ? '' @@ -628,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+'\ + \ ' } @@ -1028,17 +1046,17 @@ $(document).ready(function(){ "sPaginationType": "full_numbers", "aoColumnDefs": [ { "bSortable": false, "aTargets": ["check"] }, - { "sWidth": "60px", "aTargets": [0,2,3,7,8,9] }, - { "sWidth": "35px", "aTargets": [1,10] }, - { "sWidth": "100px", "aTargets": [5,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/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 : "--" )+'\ + \ \ \ \ From f4d9769fcd2a35661a8367585e5d8874d0d6de85 Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Mon, 7 Nov 2011 18:01:12 +0100 Subject: [PATCH 23/34] Feature #841: Make oZones more user friedly. This commit makes the following improvements to the oZones GUI: * The zone creation dialog has some default values. * Protocol and /RPC2 tail are added by default to the endpoint data, which has been divided in host and port, with default values. * Sunstone endpoint field has been divided in protocol,host,port,subdir. Default values provided. * VDCs extended information contains a link to the Sunstone instance for the specified VDC. * VDCs extended information contains a selected text field with the value to set ONEXML_RPC, in order to manage the VDC from the CLI. (cherry picked from commit 55fa96153f7f9c87fb1a2dacb49c00e40f7ccbf9) --- src/ozones/Server/public/css/application.css | 5 +-- .../Server/public/js/plugins/vdcs-tab.js | 27 ++++++++++++++ .../Server/public/js/plugins/zones-tab.js | 35 ++++++++++++++----- 3 files changed, 56 insertions(+), 11 deletions(-) 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 =
\ \
\ - \ -
\ + \ + :\ + \ +
\ \ -
\ +
\ \ - \ +
\ \ -
\ + ://\ + :\ + /\ + \ +
\
\ \
\ @@ -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 } }; From 42ac27032176b7dfca8fe73d818443e191dc9c73 Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Thu, 10 Nov 2011 23:04:11 +0100 Subject: [PATCH 24/34] Feature #969: Remove dependency from Configuration.rb (cherry picked from commit a54ce0af0109082a672db7549894df83c12e3410) --- src/ozones/Client/lib/zona.rb | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) 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 From 7cb203760edcb17f0f89fc63d87df738837978e3 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Sat, 12 Nov 2011 00:31:20 +0100 Subject: [PATCH 25/34] Ozones CLI was broken. When there is no session associated to a client a new auth process is started --- src/ozones/Server/ozones-server.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ozones/Server/ozones-server.rb b/src/ozones/Server/ozones-server.rb index 7863c4b64a..f45332957b 100755 --- a/src/ozones/Server/ozones-server.rb +++ b/src/ozones/Server/ozones-server.rb @@ -159,7 +159,7 @@ end before do unless request.path=='/login' || request.path=='/' - halt 401 unless authorized? + build_session unless authorized? @OzonesServer = OzonesServer.new(session[:key]) @pr = OZones::ProxyRules.new("apache",config[:htaccess]) From 6748d19d14a316c9663513b1b02cf1f473929f4e Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Sat, 12 Nov 2011 03:19:24 +0100 Subject: [PATCH 26/34] Fix unused variable in function --- src/scheduler/include/Client.h | 2 +- src/scheduler/src/client/Client.cc | 12 ++++-------- 2 files changed, 5 insertions(+), 9 deletions(-) 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; } /* -------------------------------------------------------------------------- */ From 34cb7a19be6aa1c4ba8334484ee6dd8d12786b2c Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Sat, 12 Nov 2011 03:20:59 +0100 Subject: [PATCH 27/34] feature #966: Images can now be referred by name with IMAGE. Conflicts for images with the same name can be resolved with IMAGE_UID and IMAGE_UNAME --- include/ImageManager.h | 8 ++ include/ImagePool.h | 1 - src/image/ImageManagerActions.cc | 25 +++++ src/image/ImagePool.cc | 155 +++++++++++++++++++++++-------- src/image/test/ImagePoolTest.cc | 61 +++++++++++- src/vm/VirtualMachine.cc | 15 --- 6 files changed, 208 insertions(+), 57 deletions(-) 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/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..3c38972236 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,10 +269,9 @@ int ImagePool::disk_attribute(VectorAttribute * disk, disk->replace("TARGET", dev_prefix); } } - - rc = -2; } - else + + if ( img != 0 ) { img->disk_attribute(disk, index, img_type); @@ -224,22 +294,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/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index 349f57b8ba..a0adc62b1d 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(); From 0b417d6eb1b5e4f2e137eb653bb0e61734059667 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Sat, 12 Nov 2011 23:38:30 +0100 Subject: [PATCH 28/34] feature #966: Bug returning the id of the acquired image --- src/image/ImagePool.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/image/ImagePool.cc b/src/image/ImagePool.cc index 3c38972236..b282e72a04 100644 --- a/src/image/ImagePool.cc +++ b/src/image/ImagePool.cc @@ -224,7 +224,7 @@ int ImagePool::disk_attribute(VectorAttribute * disk, return -1; } - img = imagem->acquire_image(source , uiid); + img = imagem->acquire_image(source, uiid); if ( img == 0 ) { @@ -275,6 +275,8 @@ int ImagePool::disk_attribute(VectorAttribute * disk, { img->disk_attribute(disk, index, img_type); + image_id = img->get_oid(); + update(img); img->unlock(); From 535d1c06c4a1cef1424e17c6b25346390626c344 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Sat, 12 Nov 2011 23:39:10 +0100 Subject: [PATCH 29/34] feature #966: Vnet can now be referred by name with NETWORK --- include/VirtualNetworkPool.h | 16 +++- src/vm/VirtualMachine.cc | 10 --- src/vnm/VirtualNetworkPool.cc | 120 +++++++++++++++++-------- src/vnm/test/VirtualNetworkPoolTest.cc | 12 +-- 4 files changed, 99 insertions(+), 59 deletions(-) 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/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index a0adc62b1d..d8d4f9a526 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -875,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); From 9f2afec52614ae840959ae8c8b950038b2febcff Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Mon, 14 Nov 2011 09:15:51 +0100 Subject: [PATCH 30/34] Better handling of unathoreized requests in Ozones --- src/ozones/Server/ozones-server.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/ozones/Server/ozones-server.rb b/src/ozones/Server/ozones-server.rb index f45332957b..9315b2cc3d 100755 --- a/src/ozones/Server/ozones-server.rb +++ b/src/ozones/Server/ozones-server.rb @@ -159,7 +159,11 @@ end before do unless request.path=='/login' || request.path=='/' - build_session unless authorized? + rc , msg = build_session unless authorized? + + if rc == 401 + halt 401 + end @OzonesServer = OzonesServer.new(session[:key]) @pr = OZones::ProxyRules.new("apache",config[:htaccess]) From 271e99d654e8585d2d1d9c6b78e8d635d37dbd8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Tue, 15 Nov 2011 17:53:43 +0100 Subject: [PATCH 31/34] Bug #961: Remove Configuration.rb. onedb command requires the DB connection options to be always used --- install.sh | 3 +- src/oca/ruby/OpenNebula/Configuration.rb | 112 ----------------------- src/onedb/onedb | 8 -- src/onedb/onedb.rb | 71 +++++--------- src/onedb/test/test_mysql.sh | 6 +- src/onedb/test/test_sqlite.sh | 2 +- 6 files changed, 26 insertions(+), 176 deletions(-) delete mode 100644 src/oca/ruby/OpenNebula/Configuration.rb 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/src/oca/ruby/OpenNebula/Configuration.rb b/src/oca/ruby/OpenNebula/Configuration.rb deleted file mode 100644 index aab519973a..0000000000 --- a/src/oca/ruby/OpenNebula/Configuration.rb +++ /dev/null @@ -1,112 +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]< 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/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 From 51cd4a26bb913d299893ce6da42e6f7ead06f822 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Tue, 15 Nov 2011 23:22:32 +0100 Subject: [PATCH 32/34] Better check for unauthorized sessions in ozones --- src/ozones/Server/ozones-server.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/ozones/Server/ozones-server.rb b/src/ozones/Server/ozones-server.rb index 9315b2cc3d..ef34108ee0 100755 --- a/src/ozones/Server/ozones-server.rb +++ b/src/ozones/Server/ozones-server.rb @@ -159,10 +159,13 @@ end before do unless request.path=='/login' || request.path=='/' - rc , msg = build_session unless authorized? - if rc == 401 - halt 401 + unless authorized? + rc , msg = build_session + + if rc == 401 + halt 401 + end end @OzonesServer = OzonesServer.new(session[:key]) From 003a47fb8a8a21886b5267e134a214aeb946ec5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tino=20V=C3=A1zquez?= Date: Wed, 27 Jul 2011 20:03:03 +0200 Subject: [PATCH 33/34] Add instance types retrieval through OCCI New get method over /compute/types, returns XML in the following format: XLARGE 4 1024 SMALL 1 512 --- src/cloud/occi/lib/OCCIServer.rb | 39 +++++++++++++++++++++++++++++++ src/cloud/occi/lib/occi-server.rb | 8 +++++-- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/src/cloud/occi/lib/OCCIServer.rb b/src/cloud/occi/lib/OCCIServer.rb index 841f45fa49..1f537ca902 100755 --- a/src/cloud/occi/lib/OCCIServer.rb +++ b/src/cloud/occi/lib/OCCIServer.rb @@ -504,4 +504,43 @@ class OCCIServer < CloudServer return to_occi_xml(user, 200) end + + ############################################################################ + ############################################################################ + # BonFIRE Specific + ############################################################################ + ############################################################################ + 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 86f9a1959b..ba0199f584 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" # Specific BonFIRE functionality + 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 From aac300b6f7b9ee7b51112447898abd52dc747bb6 Mon Sep 17 00:00:00 2001 From: Tino Vazquez Date: Wed, 16 Nov 2011 16:47:45 +0100 Subject: [PATCH 34/34] Get ride of unneeded comments --- src/cloud/occi/lib/OCCIServer.rb | 5 ----- src/cloud/occi/lib/occi-server.rb | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/src/cloud/occi/lib/OCCIServer.rb b/src/cloud/occi/lib/OCCIServer.rb index 1f537ca902..954248d3db 100755 --- a/src/cloud/occi/lib/OCCIServer.rb +++ b/src/cloud/occi/lib/OCCIServer.rb @@ -505,11 +505,6 @@ class OCCIServer < CloudServer return to_occi_xml(user, 200) end - ############################################################################ - ############################################################################ - # BonFIRE Specific - ############################################################################ - ############################################################################ def get_computes_types etc_location=ONE_LOCATION ? ONE_LOCATION+"/etc" : "/etc/one" begin diff --git a/src/cloud/occi/lib/occi-server.rb b/src/cloud/occi/lib/occi-server.rb index ba0199f584..672ab65d06 100755 --- a/src/cloud/occi/lib/occi-server.rb +++ b/src/cloud/occi/lib/occi-server.rb @@ -172,7 +172,7 @@ end ################################################### get '/compute/:id' do - if params[:id] == "types" # Specific BonFIRE functionality + if params[:id] == "types" result,rc = @occi_server.get_computes_types else result,rc = @occi_server.get_compute(request, params)