Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

soft fail on missing ipaddress gem #155

Merged
merged 1 commit into from
Apr 21, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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