Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Imported by Tim 'bastelfreak' Meusel into voxpupuli/extlib because Yelp/netstdlib got abandoned | ||
# | ||
# @summary Converts an IPv4 CIDR address of the form 192.168.0.1/24 into its broadcast address | ||
# @note IPv6 supports only multicast and unicast, so this function only supports IPv4 | ||
Puppet::Functions.create_function(:'extlib::cidr_to_broadcast') do | ||
# @param ip IPv4 address in CIDR notation | ||
# @return IPv4 broadcast address | ||
# @example calling the function | ||
# extlib::cidr_to_broadcast('127.0.0.1/8') | ||
dispatch :cidr_to_broadcast do | ||
param 'Stdlib::IP::Address::V4::CIDR', :ip | ||
return_type 'Stdlib::IP::Address::V4::Nosubnet' | ||
end | ||
|
||
def cidr_to_broadcast(ip) | ||
IPAddr.new(ip).to_range.last.to_s | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
require 'spec_helper' | ||
|
||
describe 'extlib::cidr_to_broadcast' do | ||
it 'exists' do | ||
is_expected.not_to be_nil | ||
end | ||
|
||
context 'when called with no parameters' do | ||
it { is_expected.to run.with_params.and_raise_error(ArgumentError) } | ||
end | ||
|
||
context 'when called with a Integer' do | ||
it { is_expected.to run.with_params(42).and_raise_error(ArgumentError) } | ||
end | ||
|
||
context 'when called with a String thats not an ip address' do | ||
it { is_expected.to run.with_params('42').and_raise_error(ArgumentError) } | ||
end | ||
|
||
context 'when called with an IP Address that is not in the CIDR notation' do | ||
it { is_expected.to run.with_params('127.0.0.1').and_raise_error(ArgumentError) } | ||
end | ||
|
||
context 'when called with an IP Address that is not in the CIDR notation' do | ||
it { is_expected.to run.with_params('fe80::800:27ff:fe00:0').and_raise_error(ArgumentError) } | ||
end | ||
|
||
context 'when called with an IPv4 CIDR' do | ||
it { is_expected.to run.with_params('127.0.0.1/8').and_return('127.255.255.255') } | ||
end | ||
|
||
context 'when called with an IPv6 CIDR' do | ||
it { is_expected.to run.with_params('fe80::800:27ff:fe00:0/64').and_raise_error(ArgumentError) } | ||
end | ||
end |