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] 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