Puppet Function: bracketize
- Defined in:
- lib/puppet/parser/functions/bracketize.rb
- Function type:
- Ruby 3.x API
Overview
Add brackets to IP addresses and Arrays
of IP addresses based
on the rules for bracketing IPv6 addresses.
Ignore anything that does not look like an IPv6 address.
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/puppet/parser/functions/bracketize.rb', line 2 newfunction(:bracketize, :type => :rvalue, :doc => <<-'ENDHEREDOC') do |ipaddr| ipaddr = Array(ipaddr).flatten Add brackets to IP addresses and `Arrays` of IP addresses based on the rules for bracketing IPv6 addresses. Ignore anything that does not look like an IPv6 address. @return [Variant[String, Array[String]]] ENDHEREDOC toret = ipaddr.map { |x| # IPv6 Address? if x.include?(':') and x !~ /\./ then if x[0].chr != '[' then y = x.split('/') y[0] = "[#{y[0]}]" y.join('/') end else x end } toret = toret.first if toret.size == 1 return toret end |