49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
# File 'lib/hapi/application/app.rb', line 49
def render(config)
content = ""
f = File.open($haproxy_config, "r")
in_gen_section = false
f.each_line do |line|
if line =~ /HAPROXY_API_GENERATED/
if in_gen_section
in_gen_section = false
else
in_gen_section = true
end
else
if !in_gen_section
content += line
end
end
end
f.close
content += "# HAPROXY_API_GENERATED - START\n"
config['frontend'].each_pair do |name, frontend|
content += "frontend #{name}\n"
content += " bind 0.0.0.0:#{frontend['port']}\n"
content += " default_backend #{name}-backend\n"
content += "\n"
end
config['backend'].each_pair do |name, backend|
content += "backend #{name}\n"
content += " balance #{backend['lbmethod']}\n"
if backend.has_key?('options')
backend['options'].each_pair do |k,v|
content += " option #{k} #{v}\n"
end
end
port = backend['port']
server_options = ""
if backend.has_key?('server_options')
backend['server_options'].each_pair do |k,v|
server_options += "#{k} #{v} "
end
end
backend['servers'].each do |server|
content += " server #{server}:#{port} #{server}:#{port} #{server_options} \n"
end
content += "\n"
end
content += "# HAPROXY_API_GENERATED - END\n"
return content
end
|