Puppet Function: network::build_cidr_array
- Defined in:
- lib/puppet/functions/network/build_cidr_array.rb
- Function type:
- Ruby 4.x API
Summary
Summarise what the function does hereOverview
—- original file header —-
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/puppet/functions/network/build_cidr_array.rb', line 15 Puppet::Functions.create_function(:'network::build_cidr_array') do # @param args # The original array of arguments. Port this to individually managed params # to get the full benefit of the modern function API. # # @return [Data type] # Describe what the function returns here # dispatch :default_impl do # Call the method named 'default_impl' when this is matched # Port this to match individual params for better type safety repeated_param 'Any', :args end def default_impl(*args) unless args.length == 1 then raise Puppet::ParseError, ("build_cidr_array(): wrong number of arguments (#{args.length}; must be 1)") end new_array = [] args[0].each do |item| begin new_array.push(IPAddr.new(item).to_i.to_s(2).count('1')) rescue ArgumentError => e raise Puppet::ParseError, (e) end end new_array end end |