value.cidr
end
+ # Takes an address mask and converts the host portion to CIDR notation.
+ #
+ # This takes into account you can negate a mask but follows all rules
+ # defined in host_to_ip for the host/address part.
+ #
+ def host_to_mask(value)
+ match = value.match /(!)\s?(.*)$/
+ return host_to_ip(value) unless match
+
+ cidr = host_to_ip(match[2])
+ return nil if cidr == nil
+ "#{match[1]} #{cidr}"
+ end
+
# Validates the argument is int or hex, and returns valid hex
# conversion of the value or nil otherwise.
def to_hex32(value)
specify { subject.host_to_ip('::/0').should == nil }
end
+ describe '#host_to_mask' do
+ subject { resource }
+ specify { subject.host_to_mask('puppetlabs.com').should == '96.126.112.51/32' }
+ specify { subject.host_to_mask('!puppetlabs.com').should == '! 96.126.112.51/32' }
+ specify { subject.host_to_mask('96.126.112.51').should == '96.126.112.51/32' }
+ specify { subject.host_to_mask('!96.126.112.51').should == '! 96.126.112.51/32' }
+ specify { subject.host_to_mask('96.126.112.51/32').should == '96.126.112.51/32' }
+ specify { subject.host_to_mask('! 96.126.112.51/32').should == '! 96.126.112.51/32' }
+ specify { subject.host_to_mask('2001:db8:85a3:0:0:8a2e:370:7334').should == '2001:db8:85a3::8a2e:370:7334/128' }
+ specify { subject.host_to_mask('!2001:db8:85a3:0:0:8a2e:370:7334').should == '! 2001:db8:85a3::8a2e:370:7334/128' }
+ specify { subject.host_to_mask('2001:db8:1234::/48').should == '2001:db8:1234::/48' }
+ specify { subject.host_to_mask('! 2001:db8:1234::/48').should == '! 2001:db8:1234::/48' }
+ specify { subject.host_to_mask('0.0.0.0/0').should == nil }
+ specify { subject.host_to_mask('!0.0.0.0/0').should == nil }
+ specify { subject.host_to_mask('::/0').should == nil }
+ specify { subject.host_to_mask('! ::/0').should == nil }
+ end
+
describe '#icmp_name_to_number' do
describe 'proto unsupported' do
subject { resource }