Fix IPv6
Change-Id: Ide88c35590a69bbb7e18a77a688103d5996ffa03
This commit is contained in:
parent
2d9c274846
commit
d5cb42f059
@ -102,7 +102,7 @@ def is_ipv6(host):
|
||||
)
|
||||
host = host.strip()
|
||||
try:
|
||||
return netaddr.IPAddress(host).version == 6
|
||||
return netaddr.IPAddress(host.strip('[]')).version == 6
|
||||
except netaddr.core.AddrFormatError:
|
||||
# Most probably a hostname
|
||||
return False
|
||||
@ -122,7 +122,7 @@ def is_ipv4(host):
|
||||
|
||||
|
||||
def force_ip(host, allow_localhost=False):
|
||||
if not is_ipv6(host) or not is_ipv4(host):
|
||||
if not(is_ipv6(host) or is_ipv4(host)):
|
||||
host = host2ip(host, allow_localhost=allow_localhost)
|
||||
return host
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
|
||||
require 'resolv'
|
||||
require 'ipaddr'
|
||||
|
||||
|
||||
module Puppet::Parser::Functions
|
||||
@ -10,6 +11,10 @@ module Puppet::Parser::Functions
|
||||
"force_ip(): Wrong number of arguments given (#{args.size} for 1)"
|
||||
)
|
||||
end
|
||||
Resolv.getaddress args[0]
|
||||
if (!!IPAddr.new(args[0]) rescue false)
|
||||
args[0]
|
||||
else
|
||||
Resolv.getaddress args[0]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user