Puppet Function: wmflib::cidr_first_address

Defined in:
modules/wmflib/lib/puppet/functions/wmflib/cidr_first_address.rb
Function type:
Ruby 4.x API

Summary

eturns the first usable address of a cidr network

Overview

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

SPDX-License-Identifier: Apache-2.0

Examples:

calling the function

wmflib::cidr_first_address('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



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'modules/wmflib/lib/puppet/functions/wmflib/cidr_first_address.rb', line 4

Puppet::Functions.create_function(:'wmflib::cidr_first_address') do
  # @param ip IPv6 or IPv4 address in CIDR notation
  # @return IPv6 or IPv4 network/net address
  # @example calling the function
  #   wmflib::cidr_first_address('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(2)[1].to_s
  end
end