forked from glarizza/puppet-haproxy
-
Notifications
You must be signed in to change notification settings - Fork 268
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #119 from Spredzy/more_listen_flexibility
Allow greater flexibility in listen directive.
- Loading branch information
Showing
6 changed files
with
161 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,34 @@ | ||
<% require 'ipaddr' -%> | ||
<% Array(@ipaddress).uniq.each do |virtual_ip| (@ports.is_a?(Array) ? @ports : Array(@ports.split(","))).each do |port| -%> | ||
<%- | ||
begin | ||
IPAddr.new(virtual_ip) | ||
valid_ip = true | ||
rescue ArgumentError => e | ||
valid_ip = false | ||
end | ||
if ! valid_ip and ! virtual_ip.match(/^[A-Za-z][A-Za-z0-9\.-]+$/) and virtual_ip != "*" | ||
scope.function_fail(["Invalid IP address or hostname [#{virtual_ip}]"]) | ||
end | ||
-%> | ||
<%- scope.function_fail(["Port [#{port}] is outside of range 1-65535"]) if port.to_i < 1 or port.to_i > 65535 -%> | ||
bind <%= virtual_ip %>:<%= port %> <%= Array(@bind_options).join(" ") %> | ||
<% end end -%> | ||
<% if @bind | ||
@bind.keys.uniq.sort.each do |virtual_ip| | ||
if ip_port = virtual_ip.match(/^([A-Za-z0-9\.-]+):([0-9]+)$/) | ||
ip = ip_port[1] | ||
port = ip_port[2] | ||
elsif virtual_ip.match(/^([A-Za-z0-9\.-]+)$/) | ||
ip = virtual_ip | ||
end | ||
begin | ||
IPAddr.new(ip) | ||
valid_ip = true | ||
rescue ArgumentError => e | ||
valid_ip = false | ||
end | ||
if ! valid_ip and ! ip.match(/^[A-Za-z][A-Za-z0-9\.-]+$/) and ip != "*" | ||
scope.function_fail(["Invalid IP address or hostname [#{ip}]"]) | ||
end | ||
scope.function_fail(["Port #{port} for IP #{ip} is outside of range 1-65535"]) if port and (port.to_i < 1 or port.to_i > 65535) -%> | ||
bind <%= ip -%>:<%= port -%> <%= Array(@bind[virtual_ip]).join(" ") %> | ||
<%- end else | ||
Array(@ipaddress).uniq.each do |virtual_ip| (@ports.is_a?(Array) ? @ports : Array(@ports.split(","))).each do |port| | ||
begin | ||
IPAddr.new(virtual_ip) | ||
valid_ip = true | ||
rescue ArgumentError => e | ||
valid_ip = false | ||
end | ||
if ! valid_ip and ! virtual_ip.match(/^[A-Za-z][A-Za-z0-9\.-]+$/) and virtual_ip != "*" | ||
scope.function_fail(["Invalid IP address or hostname [#{virtual_ip}]"]) | ||
end | ||
scope.function_fail(["Port [#{port}] is outside of range 1-65535"]) if port.to_i < 1 or port.to_i > 65535 -%> | ||
bind <%= virtual_ip -%>:<%= port -%> <%= Array(@bind_options).join(" ") %> | ||
<%- end end end -%> |