1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-20 10:50:08 +03:00

Bug #961: Remove Configuration.rb. onedb command requires the DB connection options to be always used

This commit is contained in:
Carlos Martín 2011-11-15 17:53:43 +01:00
parent 9f2afec526
commit 271e99d654
6 changed files with 26 additions and 176 deletions

View File

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

View File

@ -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]<<value
else
@conf[key]=value
end
end
def [](key)
@conf[key.to_s.upcase]
end
########################################################################
########################################################################
private
#
#
#
def parse_conf(conf_file)
@conf=Hash.new
conf_file.scan(SINGLE_VARIABLE_REG) {|m|
key=m[0].strip.upcase
value=m[1].strip
add_value(key, value)
}
conf_file.scan(ARRAY_VARIABLE_REG) {|m|
master_key=m[0].strip.upcase
# 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
end
#
# Test program for the Configuration Parser
#
if $0 == __FILE__
require 'pp'
conf=Configuration.new_from_file('cloud.conf')
pp conf
end
end

View File

@ -133,14 +133,6 @@ DBNAME={
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.

View File

@ -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}"

View File

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

View File

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