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