From: František Dvořák Date: Fri, 10 Jun 2016 08:22:39 +0000 (+0200) Subject: Removed peculiar config merge - fixes compatibility with the old rubies. X-Git-Url: http://scientific.zcu.cz/git/?a=commitdiff_plain;h=e1fa897535d04137a9f3d6962fe22b77f3d5e4ab;p=now.git Removed peculiar config merge - fixes compatibility with the old rubies. --- diff --git a/.rubocop.yml b/.rubocop.yml index 2d12e50..1ec3868 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -83,3 +83,8 @@ Style/RaiseArgs: # (easy to read) Style/RedundantReturn: Enabled: false + +# Avoid comma after the last item of an array +# (do want) +Style/TrailingCommaInLiteral: + Enabled: false diff --git a/etc/now.yaml b/etc/now.yaml deleted file mode 100644 index 0909b6c..0000000 --- a/etc/now.yaml +++ /dev/null @@ -1,4 +0,0 @@ -opennebula: - admin_user: oneadmin - admin_password: 'good-password' - endpoint: 'http://localhost:2633/RPC2' diff --git a/etc/now.yml b/etc/now.yml new file mode 100644 index 0000000..c14dec3 --- /dev/null +++ b/etc/now.yml @@ -0,0 +1,4 @@ +opennebula: + admin_user: 'nowadmin' + admin_password: 'the-best-strongest-password-ever' + endpoint: http://localhost:2633/RPC2 diff --git a/lib/nebula.rb b/lib/nebula.rb index d0251cb..4c2c1cb 100644 --- a/lib/nebula.rb +++ b/lib/nebula.rb @@ -1,27 +1,14 @@ require 'opennebula' require 'yaml' -# http://stackoverflow.com/questions/9381553/ruby-merge-nested-hash -public def deep_merge(second) - merger = proc do |_key, v1, v2| - if [:undefined, nil, :nil].include?(v2) - v1 - elsif [:undefined, nil, :nil].include?(v1) - v2 - elsif v1.is_a?(Hash) && v2.is_a?(Hash) - v1.merge(v2, &merger) - elsif v1.is_a?(Array) && v2.is_a(Array) - v1 | v2 - else - v2 - end - end - merge(second.to_h, &merger) -end - module Now EXPIRE_LENGTH = 8 * 60 * 60 + CONFIG_FILES = [ + ::File.expand_path('~/.config/now.yml'), + '/etc/now.yml', + ::File.expand_path('../../etc/now.yml', __FILE__), + ] # NOW core class for communication with OpenNebula class Nebula @@ -72,13 +59,13 @@ module Now logger.info "Starting Network Orchestrator Wrapper (NOW #{VERSION})" @config = {} - c = load_config(::File.expand_path('../../etc/now.yaml', __FILE__)) - @config = @config.deep_merge(c) - #logger.debug "Configuration: #{@config}" - - c = load_config('/etc/now.yaml') - @config = @config.deep_merge(c) - #logger.debug "Configuration: #{@config}" + CONFIG_FILES.each do |path| + if ::File.exist?(path) + @config = load_config(path) + break + end + end + logger.debug "Configuration: #{@config}" @url = @config['opennebula']['endpoint'] end