diff options
| author | Stefan Schulte <stefan.schulte@taunusstein.net> | 2010-11-18 23:38:10 +0100 |
|---|---|---|
| committer | Matt Robinson <matt@puppetlabs.com> | 2010-12-14 11:52:24 -0800 |
| commit | b94c1b444d76a7fa1bcd63dd6ba653abf0b49826 (patch) | |
| tree | 3616805644b3fd5cd6ee3cc298ca0850ff8591b6 /lib | |
| parent | cca3436db8ba90eeaeefd8a58567becfcb330acc (diff) | |
| download | puppet-b94c1b444d76a7fa1bcd63dd6ba653abf0b49826.tar.gz puppet-b94c1b444d76a7fa1bcd63dd6ba653abf0b49826.tar.xz puppet-b94c1b444d76a7fa1bcd63dd6ba653abf0b49826.zip | |
(#5427) Using Propery::OrderedList for host_alias
This uses the propertyclass Puppet::Property::OrderedList to represent
the list of host_aliases. This lets us remove the in_sync, should_to_s
etc overrides.
In the provider class the list is represented by a string (=no array)
so there were a few changes necessary as well.
Because Puppet::Property::List uses the specified delimiter when
converting should values to strings, I changed the delimiter to a simple
space instead a tab. This keeps messages produced by puppet in a nice
format.
The tests had to be changed to work with the new behaviour of
host_aliases. There are a few additional tests as well.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/puppet/provider/host/parsed.rb | 8 | ||||
| -rwxr-xr-x | lib/puppet/type/host.rb | 33 |
2 files changed, 12 insertions, 29 deletions
diff --git a/lib/puppet/provider/host/parsed.rb b/lib/puppet/provider/host/parsed.rb index a303c4bcf..2ba01a41c 100644 --- a/lib/puppet/provider/host/parsed.rb +++ b/lib/puppet/provider/host/parsed.rb @@ -22,9 +22,7 @@ Puppet::Type.type(:host).provide(:parsed,:parent => Puppet::Provider::ParsedFile # An absent comment should match "comment => ''" hash[:comment] = '' if hash[:comment].nil? or hash[:comment] == :absent unless hash[:host_aliases].nil? or hash[:host_aliases] == :absent - hash[:host_aliases] = hash[:host_aliases].split(/\s+/) - else - hash[:host_aliases] = [] + hash[:host_aliases].gsub!(/\s+/,' ') # Change delimiter end }, :to_line => proc { |hash| @@ -32,8 +30,8 @@ Puppet::Type.type(:host).provide(:parsed,:parent => Puppet::Provider::ParsedFile raise ArgumentError, "#{n} is a required attribute for hosts" unless hash[n] and hash[n] != :absent end str = "#{hash[:ip]}\t#{hash[:name]}" - if hash.include? :host_aliases and !hash[:host_aliases].empty? - str += "\t#{hash[:host_aliases].join("\t")}" + if hash.include? :host_aliases and !hash[:host_aliases].nil? and hash[:host_aliases] != :absent + str += "\t#{hash[:host_aliases]}" end if hash.include? :comment and !hash[:comment].empty? str += "\t# #{hash[:comment]}" diff --git a/lib/puppet/type/host.rb b/lib/puppet/type/host.rb index 1af74d886..867ef2ab3 100755 --- a/lib/puppet/type/host.rb +++ b/lib/puppet/type/host.rb @@ -1,3 +1,5 @@ +require 'puppet/property/ordered_list' + module Puppet newtype(:host) do ensurable @@ -13,41 +15,24 @@ module Puppet end - newproperty(:host_aliases) do + # for now we use OrderedList to indicate that the order does matter. + newproperty(:host_aliases, :parent => Puppet::Property::OrderedList) do desc "Any aliases the host might have. Multiple values must be specified as an array." - def insync?(is) - is == @should + def delimiter + " " end - def is_to_s(currentvalue = @is) - currentvalue = [currentvalue] unless currentvalue.is_a? Array - currentvalue.join(" ") - end - - # We actually want to return the whole array here, not just the first - # value. - def should - if defined?(@should) - if @should == [:absent] - return :absent - else - return @should - end - else - return nil - end - end - - def should_to_s(newvalue = @should) - newvalue.join(" ") + def inclusive? + true end validate do |value| raise Puppet::Error, "Host aliases cannot include whitespace" if value =~ /\s/ raise Puppet::Error, "Host alias cannot be an empty string. Use an empty array to delete all host_aliases " if value =~ /^\s*$/ end + end newproperty(:comment) do |
