Skip to content

Commit

Permalink
Merge pull request #280 from sohonet/feature/balancer-weights
Browse files Browse the repository at this point in the history
Add support for balancermember weights
  • Loading branch information
tphoney authored Jul 3, 2017
2 parents 49d6769 + b905b18 commit ca893a2
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
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 -%>

0 comments on commit ca893a2

Please sign in to comment.