Skip to content
Snippets Groups Projects
Commit eeb80701 authored by Thomas Bellman's avatar Thomas Bellman
Browse files

Handle resolve_ipnets() returning multiple addresses.

In a soon to be coming release of the nsc-puppet-utils module, the
resolve_ipnets() function will be able to return multiple addresses
even for a single host.  Handle that (as well as the old version).

Also some fixes for handling IPv6 addresses.
parent 6f2ff7db
Branches
Tags
No related merge requests found
<% <%
listen_on = [] listen_on = []
[@urls].flatten.sort.uniq.each { |u| [@urls].flatten.sort.uniq.each do |u|
u =~ /^([a-z]*):\/\/([^:\/]+|\[[^\[\]]+\])(:([0-9]+))?\/?$/ u =~ /^([a-z]*):\/\/([^:\/]+|\[[^\[\]]+\])(:([0-9]+))?\/?$/
(schema,host,port) = $1,$2,$4 (schema,host,port) = $1,$2,$4
if host == '' if host == ''
host = @name host = @name
end end
if host == '*' if host == '*'
addr = host addrs = host
elsif host =~ /^\[[0-9a-f:]*:[0-9a-f:]*\]$/ elsif host =~ /^\[[0-9A-Fa-f:]*:[0-9A-Fa-f:]*:[0-9A-Fa-f:]*\]$/
addr = host # IPv6 numeric address "[0000:1111::eeee:ffff]" # IPv6 numeric address "[0000:1111::eeee:ffff]"
# Note: keep brackets, as those are needed below
addrs = host
elsif host =~ /^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/ elsif host =~ /^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/
addr = host # IPv4 numeric address "111.222.333.444" # IPv4 numeric address "111.222.333.444"
addrs = host
elsif host =~ /^\[(.+)\]$/ elsif host =~ /^\[(.+)\]$/
# Hostname within brackets "[www.example.com]", not to be resolved # Hostname within brackets "[www.example.com]", not to be resolved
host = addr = $1 addrs = host = $1
else else
addr = scope.function_resolve_ipnets([host, 'failerrors']) addrs = scope.function_resolve_ipnets([host, 'failerrors'])
end end
if port == nil if port == nil
if schema == 'http' if schema == 'http'
...@@ -29,8 +32,14 @@ ...@@ -29,8 +32,14 @@
raise(Puppet::Error, "Unknown URL schema and no port: #{u}") raise(Puppet::Error, "Unknown URL schema and no port: #{u}")
end end
end end
listen_on << addr + ':' + port + ' ' + schema [addrs].flatten.each do |a|
} if a =~ /^[0-9A-Fa-f:]*:[0-9A-Fa-f:]*:[0-9A-Fa-f:]*$/
# IPv6 addresses need to be enclosed within square brackets
a = '[' + a + ']'
end
listen_on << a + ':' + port + ' ' + schema
end
end
listen_on.sort!.uniq! listen_on.sort!.uniq!
-%> -%>
<% listen_on.each do |listen_spec| -%> <% listen_on.each do |listen_spec| -%>
......
<% <%
server_names = [] server_names = []
server_addrs = [] server_addrs = []
[@urls].flatten.sort.each { |u| [@urls].flatten.sort.each do |u|
u =~ /^([a-z]*):\/\/([^:\/]+|\[[^\[\]]+\])(:([0-9]+))?\/?$/ u =~ /^([a-z]*):\/\/([^:\/]+|\[[^\[\]]+\])(:([0-9]+))?\/?$/
(schema,host,port) = $1,$2,$4 (schema,host,port) = $1,$2,$4
if host == '' if host == ''
host = @name host = @name
end end
if host == '*' if host == '*'
addr = host addrs = host
elsif host =~ /^\[[0-9a-f:]*:[0-9a-f:]*\]$/ elsif host =~ /^\[[0-9A-Fa-f:]*:[0-9A-Fa-f:]*:[0-9A-Fa-f:]*\]$/
addr = host # IPv6 numeric address "[0000:1111::eeee:ffff]" # IPv6 numeric address "[0000:1111::eeee:ffff]"
# Note: keep brackets, as those are needed below
addrs = host
elsif host =~ /^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/ elsif host =~ /^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/
addr = host # IPv4 numeric address "111.222.333.444" # IPv4 numeric address "111.222.333.444"
addrs = host
elsif host =~ /^\[(.+)\]$/ elsif host =~ /^\[(.+)\]$/
# Hostname within brackets "[www.example.com]", not to be resolved # Hostname within brackets "[www.example.com]", not to be resolved
host = addr = $1 addrs = host = $1
else else
addr = scope.function_resolve_ipnets([host, 'failerrors']) addrs = scope.function_resolve_ipnets([host, 'failerrors'])
end end
if port == nil if port == nil
if schema == 'http' if schema == 'http'
...@@ -31,8 +34,14 @@ ...@@ -31,8 +34,14 @@
end end
end end
server_names << host + ':' + port server_names << host + ':' + port
server_addrs << addr + ':' + port [addrs].flatten.each do |a|
} if a =~ /^[0-9A-Fa-f:]*:[0-9A-Fa-f:]*:[0-9A-Fa-f:]*$/
# IPv6 addresses need to be enclosed within square brackets
a = '[' + a + ']'
end
server_addrs << a + ':' + port
end
end
if @servernames != [] if @servernames != []
server_names = @servernames server_names = @servernames
end end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment