fluke/devops-service/core/devops-config.rb
amartynov b70165c3b4 \#780: done
fixed role name

new field validators

without validate fields types

fixed error with user parser

todo: project tests

returned  some tests, users fixed

some more tests: filters

images tests

network tests

keys tests

test generator

fixed run_list validator
2015-10-20 13:36:44 +03:00

59 lines
1.3 KiB
Ruby

require "socket"
class DevopsConfig
OBJECT_NAME = /([\w\-]+)/
@@config = nil
class << self
def read config_file=nil
if config_file.nil?
config_file = ENV['DEVOPS_CONFIG'] || ENV['CONFIG'] || File.join(File.dirname(__FILE__), '../config.rb')
end
config = {
:url_prefix => "",
:devops_dir => File.join(ENV["HOME"], ".devops")
}
if File.exists? config_file
eval File.read config_file
else
raise "No config file '#{config_file}' found"
end
addr = first_public_ipv4 || first_private_ipv4
config[:address] = if addr.nil?
"localhost"
else
addr.ip_address
end
config[:report_dir_v2] = File.expand_path(File.join(config[:devops_dir], "report", "v2"))
config[:project_info_dir] = File.expand_path(File.join(config[:devops_dir], "project_info", "v2"))
DevopsConfig.config = config
end
def config= config
@@config = config
end
def config
@@config
end
def [](key)
@@config[key]
end
def first_private_ipv4
Socket.ip_address_list.detect{|intf| intf.ipv4_private?}
end
def first_public_ipv4
Socket.ip_address_list.detect{|intf| intf.ipv4? and !intf.ipv4_loopback? and !intf.ipv4_multicast? and !intf.ipv4_private?}
end
end
end