From a2ad103ad9375ac364b950fa13321952d5d78179 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Mon, 26 Sep 2011 16:31:54 +0200 Subject: [PATCH] Bug #832: Restore src/cloud/common/Configuration.rb This reverts 7a530fb77c0334d36b4b2404fc09792e1444197b (cherry picked from commit 9fc7f582e238110e2153bc9083c4345e0cb0417b) --- install.sh | 3 +- src/cloud/common/Configuration.rb | 115 ++++++++++++++++++++++++++++++ 2 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 src/cloud/common/Configuration.rb diff --git a/install.sh b/install.sh index ef9069846a..d187f9b443 100755 --- a/install.sh +++ b/install.sh @@ -792,7 +792,8 @@ RUBY_OPENNEBULA_LIB_FILES="src/oca/ruby/OpenNebula/Host.rb \ COMMON_CLOUD_LIB_FILES="src/cloud/common/CloudServer.rb \ src/cloud/common/CloudClient.rb \ - src/cloud/common/CloudAuth.rb" + src/cloud/common/CloudAuth.rb \ + src/cloud/common/Configuration.rb" COMMON_CLOUD_CLIENT_LIB_FILES="src/cloud/common/CloudClient.rb" diff --git a/src/cloud/common/Configuration.rb b/src/cloud/common/Configuration.rb new file mode 100644 index 0000000000..2189e4ad1a --- /dev/null +++ b/src/cloud/common/Configuration.rb @@ -0,0 +1,115 @@ +# -------------------------------------------------------------------------- # +# 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. # +#--------------------------------------------------------------------------- # + +############################################################################### +# The Configuration Class represents a simple configuration file for the +# Cloud servers. It does not check syntax. +############################################################################### +class Configuration + + ########################################################################### + # 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(file) + @conf=parse_conf(file) + end + + def add_configuration_value(key,value) + add_value(@conf,key,value) + end + + def [](key) + @conf[key.to_s.upcase] + end + + ########################################################################### + ########################################################################### + +private + + # + # + # + def add_value(conf, key, value) + if conf[key] + if !conf[key].kind_of?(Array) + conf[key]=[conf[key]] + end + conf[key]<