Puppet Function: extlib::cidr_to_network

Defined in:
lib/puppet/functions/extlib/cidr_to_network.rb
Function type:
Ruby 4.x API

Summary

Converts a CIDR address of the form 2001:DB8::/32 or 192.0.2.0/24 into their network address (also known as net address)

Overview

extlib::cidr_to_network(Variant[Stdlib::IP::Address::V4::CIDR,Stdlib::IP::Address::V6::CIDR] $ip)Variant[Stdlib::IP::Address::V4::Nosubnet,Stdlib::IP::Address::V6::Nosubnet]

Imported by Tim ‘bastelfreak’ Meusel into voxpupuli/extlib because Yelp/netstdlib got abandoned

Examples:

calling the function

extlib::cidr_to_network('2001:DB8::/32')

Parameters:

  • ip (Variant[Stdlib::IP::Address::V4::CIDR,Stdlib::IP::Address::V6::CIDR])

    IPv6 or IPv4 address in CIDR notation

Returns:

  • (Variant[Stdlib::IP::Address::V4::Nosubnet,Stdlib::IP::Address::V6::Nosubnet])

    IPv6 or IPv4 network/net address



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/puppet/functions/extlib/cidr_to_network.rb', line 7

Puppet::Functions.create_function(:'extlib::cidr_to_network') do
  # @param ip IPv6 or IPv4 address in CIDR notation
  # @return IPv6 or IPv4 network/net address
  # @example calling the function
  #   extlib::cidr_to_network('2001:DB8::/32')
  dispatch :cidr_to_network do
    param 'Variant[Stdlib::IP::Address::V4::CIDR,Stdlib::IP::Address::V6::CIDR]', :ip
    return_type 'Variant[Stdlib::IP::Address::V4::Nosubnet,Stdlib::IP::Address::V6::Nosubnet]'
  end

  def cidr_to_network(ip)
    IPAddr.new(ip).to_range.first.to_s
  end
end