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 balancermember weights #280

Merged
merged 1 commit into from
Jul 3, 2017
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: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,8 @@ Configures a service inside a listening or backend service configuration block i

* `verifyhost`: *Optional.* Will add the verifyhost option to the server line, using the specific host from server_names as an argument. Defaults to false

* `weight`: *Optional.* Will add the weight option to the server line. Defaults to undef

#### Define: `haproxy::backend`

Sets up a backend service configuration block inside haproxy.cfg. Each backend service needs one or more balancermember services (declared with the [`haproxy::balancermember` define](#define-haproxybalancermember)).
Expand Down
5 changes: 5 additions & 0 deletions manifests/balancermember.pp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@
# specific host from server_names as an argument.
# Default: false
#
# [*weight*]
# Optional. Will add the weight option to the server line
# Default: undef
#
# === Examples
#
# Exporting the resource for a balancer member:
Expand Down Expand Up @@ -103,6 +107,7 @@
$defaults = undef,
$config_file = undef,
$verifyhost = false,
$weight = undef,
) {

include haproxy::params
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 @@ -151,4 +151,21 @@
'content' => " server server01 10.0.0.1 check\n server server02 10.0.0.2 check\n",
) }
end
context 'with weight' do
let(:params) do
{
:name => 'tyler',
:listening_service => 'croy',
:ports => '18140',
:options => 'check',
:weight => '100',
}
end

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