Skip to content

Commit

Permalink
Merge pull request #155 from fraenki/ipaddress_fix
Browse files Browse the repository at this point in the history
soft fail on missing ipaddress gem
  • Loading branch information
jyaworski committed Apr 21, 2016
2 parents 7b7165c + 85108bc commit 5301da3
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions lib/puppet/type/network_config.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
require 'puppet/property/boolean'
require 'ipaddress'

begin
require 'ipaddress'
rescue LoadError
Puppet.warning("#{__FILE__}:#{__LINE__}: ipaddress gem was not found")
end

Puppet::Type.newtype(:network_config) do
@doc = 'Manage non-volatile network configuration information'
Expand All @@ -26,17 +31,21 @@

newproperty(:ipaddress) do
desc 'The IP address of the network interfaces'
validate do |value|
raise ArgumentError, "#{self.class} requires a valid ipaddress for the ipaddress property" unless IPAddress.valid? value
# provider.validate
if defined? IPAddress
validate do |value|
raise ArgumentError, "#{self.class} requires a valid ipaddress for the ipaddress property" unless IPAddress.valid? value
# provider.validate
end
end
end

newproperty(:netmask) do
desc 'The subnet mask to apply to the interface'
validate do |value|
raise ArgumentError, "#{self.class} requires a valid netmask for the netmask property" unless IPAddress.valid_ipv4_netmask? value
# provider.validate
if defined? IPAddress
validate do |value|
raise ArgumentError, "#{self.class} requires a valid netmask for the netmask property" unless IPAddress.valid_ipv4_netmask? value
# provider.validate
end
end
end

Expand Down

0 comments on commit 5301da3

Please sign in to comment.