Module: Puppet::Util::IpProp
- Defined in:
- lib/puppet/util/ip_prop.rb
Overview
defines a shortcut to create properties with a single IP address as value
Instance Method Summary collapse
Instance Method Details
#newipprop(name, options = {}, &block) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/puppet/util/ip_prop.rb', line 7 def newipprop(name, = {}, &block) newproperty(name, ) do # TODO: We should replace this here with a proper Class # the current handling is just bad include Puppet::Util::NetworkDevice::IPCalc validate do |value| return true if ['absent', :absent].include?(value) self.fail "Invalid IP Address: #{value.inspect}" unless parse(value) end munge do |value| ['absent', :absent].include?(value) ? :absent : parse(value)[1] end def insync?(is) return ([is].flatten.sort == [@should].flatten.sort || [is].flatten.sort == [@should].flatten.map(&:to_s).sort) rescue => detail = "Property #{name}: could not compare IP '#{[is].flatten.sort.inspect}' to '#{[@should].flatten.sort.inspect}'" Puppet.log_exception(detail, ) return false end def change_to_s(current_value, newvalue) begin if current_value == :absent return "defined '#{name}' as #{self.class.format_value_for_display should_to_s(newvalue)}" elsif newvalue == :absent return "undefined '#{name}' from #{self.class.format_value_for_display is_to_s(current_value)}" else return "#{name} changed #{self.class.format_value_for_display is_to_s(current_value)} to #{self.class.format_value_for_display should_to_s(newvalue)}" end rescue Puppet::Error, Puppet::DevError raise rescue => detail = "Could not convert change '#{name}' to string: #{detail}" Puppet.log_exception(detail, ) raise Puppet::DevError, end end class_eval(&block) if block end end |