diff --git a/include/Nebula.h b/include/Nebula.h index cf0b81696b..082c4f5fb7 100644 --- a/include/Nebula.h +++ b/include/Nebula.h @@ -231,10 +231,10 @@ public: return "OpenNebula 2.3.0"; }; - static int db_version() + static string db_version() { - return 1; - }; + return "2.9.80"; + } void start(); diff --git a/install.sh b/install.sh index 931b2ded42..b74d9c9864 100755 --- a/install.sh +++ b/install.sh @@ -548,7 +548,7 @@ IMAGE_DRIVER_FS_SCRIPTS="src/image_mad/remotes/fs/cp \ #------------------------------------------------------------------------------- # Migration scripts for onedb command, to be installed under $LIB_LOCATION #------------------------------------------------------------------------------- -ONEDB_MIGRATOR_FILES="src/onedb/1.rb \ +ONEDB_MIGRATOR_FILES="src/onedb/2.0_to_2.9.80.rb \ src/onedb/onedb.rb \ src/onedb/onedb_backend.rb" diff --git a/Gemfile b/share/bundler/Gemfile similarity index 51% rename from Gemfile rename to share/bundler/Gemfile index 3237adf825..aeea6a1363 100644 --- a/Gemfile +++ b/share/bundler/Gemfile @@ -29,6 +29,35 @@ group :cloud do gem 'thin', '1.2.7' gem 'uuid' gem 'curb' - gem 'sqlite3-ruby' +end + +group :ozones_client do + gem 'json', '= 1.5.1' +end + +group :ozones_server do + gem 'json', '= 1.5.1' + gem 'datamapper' + gem 'dm-sqlite-adapter' + gem 'dm-mysql-adapter' +end + +group :ozones_server_mysql do + gem 'json', '= 1.5.1' + gem 'datamapper' + gem 'dm-mysql-adapter' +end + +group :ozones_server_sqlite do + gem 'json', '= 1.5.1' + gem 'datamapper' + gem 'dm-sqlite-adapter' +end + + + + +group :dummy do + gem 'rake' end diff --git a/share/bundler/install_gems b/share/bundler/install_gems new file mode 100755 index 0000000000..baee64cb18 --- /dev/null +++ b/share/bundler/install_gems @@ -0,0 +1,65 @@ +#!/usr/bin/env ruby + +PACKAGES=%w{optional sunstone quota cloud ozones_client ozones_server + ozones_server_mysql ozones_server_sqlite} + +DEFAULT=%w{optional sunstone quota cloud ozones_server} + + +class String + def unindent(spaces=4) + self.gsub!(/^ {#{spaces}}/, '') + end +end + +def try_library(name, error_message) + begin + require name.to_s + rescue LoadError + STDERR.puts error_message + exit -1 + end +end + + +try_library :rubygems, <<-EOT.unindent + rubygems required to use this tool + + Use one of these methods: + + * Debian/Ubuntu + apt-get install rubygems libopenssl-ruby + + * RHEL/CENTOS + yum install rubygems + + * Specific rubygems package for your distro + + * Follow the instructions from http://rubygems.org/pages/download +EOT + +try_library :bundler, <<-EOT.unindent + bundler needed to install gems + + execute this to install it: + + [sudo] gem install bundler +EOT + + +if ARGV.length>0 + packages=ARGV +else + packages=DEFAULT +end + +no_packages=PACKAGES-packages +no_packages<<'dummy' + +without="--without #{no_packages.join(' ')}" + +command_string = "bundle #{without}" + +puts command_string + +#system command_string diff --git a/src/nebula/Nebula.cc b/src/nebula/Nebula.cc index f109d89462..ac51bb2200 100644 --- a/src/nebula/Nebula.cc +++ b/src/nebula/Nebula.cc @@ -635,7 +635,7 @@ void Nebula::bootstrap() oss.str(""); oss << "CREATE TABLE db_versioning (oid INTEGER PRIMARY KEY, " - "version INTEGER, timestamp INTEGER, comment VARCHAR(256))"; + "version VARCHAR(256), timestamp INTEGER, comment VARCHAR(256))"; db->exec(oss); @@ -656,7 +656,7 @@ int Nebula::check_db_version() ostringstream oss; - int loaded_db_version = 0; + string loaded_db_version = ""; // Try to read latest version set_callback( static_cast(&Nebula::select_cb), @@ -670,7 +670,7 @@ int Nebula::check_db_version() oss.str(""); unset_callback(); - if( loaded_db_version == 0 ) + if( loaded_db_version == "" ) { // Table user_pool is present for all OpenNebula versions, and it // always contains at least the oneadmin user. @@ -703,16 +703,13 @@ int Nebula::select_cb(void *_loaded_db_version, int num, char **values, char **names) { istringstream iss; - int * loaded_db_version; + string * loaded_db_version; - loaded_db_version = static_cast(_loaded_db_version); - - *loaded_db_version = 0; + loaded_db_version = static_cast(_loaded_db_version); if ( (values[0]) && (num == 1) ) { - iss.str(values[0]); - iss >> *loaded_db_version; + *loaded_db_version = values[0]; } return 0; diff --git a/src/onedb/1.rb b/src/onedb/2.0_to_2.9.80.rb similarity index 99% rename from src/onedb/1.rb rename to src/onedb/2.0_to_2.9.80.rb index 98db3116c3..01054ecb4d 100644 --- a/src/onedb/1.rb +++ b/src/onedb/2.0_to_2.9.80.rb @@ -17,11 +17,11 @@ require "rexml/document" module Migrator def db_version - 1 + "2.9.80" end def one_version - "OpenNebula 2.3.0" + "OpenNebula 2.9.80" end def up @@ -292,7 +292,7 @@ module Migrator # New tables in DB version 1 ######################################################################## - @db.run "CREATE TABLE db_versioning (oid INTEGER PRIMARY KEY, version INTEGER, timestamp INTEGER, comment VARCHAR(256));" + @db.run "CREATE TABLE db_versioning (oid INTEGER PRIMARY KEY, version VARCHAR(256), timestamp INTEGER, comment VARCHAR(256));" @db.run "CREATE TABLE template_pool (oid INTEGER PRIMARY KEY, name VARCHAR(256), body TEXT, uid INTEGER, gid INTEGER, public INTEGER);" @db.run "CREATE TABLE acl (oid INT PRIMARY KEY, user BIGINT, resource BIGINT, rights BIGINT);" diff --git a/src/onedb/onedb.rb b/src/onedb/onedb.rb index e0c1d8e987..3bccae244a 100644 --- a/src/onedb/onedb.rb +++ b/src/onedb/onedb.rb @@ -78,7 +78,7 @@ class OneDB if(ops[:verbose]) puts "Version: #{version}" - time = version == 0 ? Time.now : Time.at(timestamp) + time = version == "2.0" ? Time.now : Time.at(timestamp) puts "Timestamp: #{time.strftime("%m/%d %H:%M:%S")}" puts "Comment: #{comment}" else @@ -93,6 +93,8 @@ class OneDB return 0 end + # max_version is ignored for now, as this is the first onedb release. + # May be used in next releases def upgrade(max_version, ops) version, timestamp, comment = @backend.read_db_version @@ -101,19 +103,18 @@ class OneDB puts "#{version} : #{comment}" puts "" end - - migrator_version = version + 1 - result = nil - file = "#{RUBY_LIB_LOCATION}/onedb/#{migrator_version}.rb" - if File.exists?(file) && - (max_version == nil || migrator_version <= max_version) + ######################################################################## + # For now, look for the only file we can migrate to, *_to_2.9.80.rb + ######################################################################## + + result = nil + file = "#{RUBY_LIB_LOCATION}/onedb/#{version}_to_2.9.80.rb" + + if File.exists?(file) # At least one upgrade will be executed, make DB backup backup(ops[:backup], ops) - end - while File.exists?(file) && - (max_version == nil || migrator_version <= max_version) puts " > Running migrator #{file}" if ops[:verbose] @@ -122,18 +123,15 @@ class OneDB result = @backend.up if !result - puts "Error while upgrading from #{migrator_version-1} to " << + puts "Error while upgrading from #{version} to " << " #{@backend.db_version}" return -1 end puts " > Done" if ops[:verbose] puts "" if ops[:verbose] - - migrator_version += 1 - file = "#{RUBY_LIB_LOCATION}/onedb/#{migrator_version}.rb" end - + # Modify db_versioning table if result != nil @backend.update_db_version(version) diff --git a/src/onedb/onedb_backend.rb b/src/onedb/onedb_backend.rb index 5db64124fc..f9b8ce2f76 100644 --- a/src/onedb/onedb_backend.rb +++ b/src/onedb/onedb_backend.rb @@ -21,7 +21,7 @@ class OneDBBacKEnd def read_db_version connect_db - version = 0 + version = "2.0" timestamp = 0 comment = "" @@ -32,7 +32,7 @@ class OneDBBacKEnd comment = row[:comment] end - return [version.to_i, timestamp, comment] + return [version, timestamp, comment] rescue # If the DB doesn't have db_version table, it means it is empty or a 2.x @@ -54,7 +54,7 @@ class OneDBBacKEnd comment = "Could not read any previous db_versioning data, " << "assuming it is an OpenNebula 2.0 or 2.2 DB." - return [0, 0, comment] + return [version, timestamp, comment] end def history