Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for loadbalancer member without ports #120

Merged
merged 2 commits into from
Jan 23, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ Specifies the title of the resource. The `name` is arbitrary and only utilized i
An array of options to be specified after the server declaration in the listening service's configuration block.

#####`ports`
Sets the ports on which the balancer member will accept connections from the load balancer. Must be an array. If you use an array in `server\_names` and `ipaddresses`, the number of ports specified will multiply the number of balancermembers formed from the IP address and server name pairs.
Sets the ports on which the balancer member will accept connections from the load balancer. If ports are specified, it must be an array. If you use an array in `server\_names` and `ipaddresses`, the number of ports specified will multiply the number of balancermembers formed from the IP address and server name pairs. If no port is specified, the balancermember will receive the traffic on the same port the frontend receive it (Very useful if used with a frontend with multiple bind ports).

#####`server_names`
Sets the name of the balancermember server in the listening service's configuration block. Defaults to the hostname. Can be an array. If this parameter is specified as an array, it must be the same length as the [`ipaddresses`](#ipaddresses) parameter's array. A balancermember is created for each pair of `server\_names` and `ipaddresses` in the array.hese pairs will be multiplied, and additional balancermembers created, based on the number of `ports` specified.
Expand Down
2 changes: 1 addition & 1 deletion manifests/balancermember.pp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
#
define haproxy::balancermember (
$listening_service,
$ports,
$ports = undef,
$server_names = $::hostname,
$ipaddresses = $::ipaddress,
$ensure = 'present',
Expand Down
17 changes: 17 additions & 0 deletions spec/defines/balancermember_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,21 @@
'content' => " server server01 192.168.56.200:18140 check\n server server01 192.168.56.200:18150 check\n server server02 192.168.56.201:18140 check\n server server02 192.168.56.201:18150 check\n"
) }
end
context 'with multiple servers and no port' do
let(:params) do
{
:name => 'tyler',
:listening_service => 'croy',
:server_names => ['server01', 'server02'],
:ipaddresses => ['192.168.56.200', '192.168.56.201'],
:options => ['check']
}
end

it { should contain_concat__fragment('croy_balancermember_tyler').with(
'order' => '20-croy-01-tyler',
'target' => '/etc/haproxy/haproxy.cfg',
'content' => " server server01 192.168.56.200 check\n server server02 192.168.56.201 check\n"
) }
end
end
8 changes: 6 additions & 2 deletions templates/haproxy_balancermember.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<% Array(@ipaddresses).zip(Array(@server_names)).each do |ipaddress,host| -%>
<%- Array(@ports).each do |port| -%>
<% if @ports -%>
<%- Array(@ports).each do |port| -%>
server <%= host %> <%= ipaddress %>:<%= port %><%= if @define_cookies then " cookie " + host end %> <%= Array(@options).sort.join(" ") %>
<%- end -%>
<%- end -%>
<% else -%>
server <%= host %> <%= ipaddress %><%= if @define_cookies then " cookie " + host end %> <%= Array(@options).sort.join(" ") %>
<%- end -%>
<% end -%>