diff options
author | Luke Kanies <luke@madstop.com> | 2009-01-14 15:33:48 -0600 |
---|---|---|
committer | James Turnbull <james@lovedthanlost.net> | 2009-02-11 08:41:16 +1100 |
commit | 671d73c1f7799e685ab484c91b7f92d16e21e256 (patch) | |
tree | 852cde95ff51d0eec8a3d96ccdaed7fd1afc8a9a /lib/puppet | |
parent | 063871fab0b96111d16b6df19511e1034cc02a42 (diff) | |
download | puppet-671d73c1f7799e685ab484c91b7f92d16e21e256.tar.gz puppet-671d73c1f7799e685ab484c91b7f92d16e21e256.tar.xz puppet-671d73c1f7799e685ab484c91b7f92d16e21e256.zip |
Prefetching, and thus purging, Nagios resources now works
*only* if you use the default configuration file locations.
In the end, this was a relatively minor change; most of the actual
diff centers around making the code more readable so I could think
my way into the fix, and adding tests for cases that were either
untested or refactored slightly.
Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'lib/puppet')
-rwxr-xr-x | lib/puppet/provider/parsedfile.rb | 53 | ||||
-rw-r--r-- | lib/puppet/util/nagios_maker.rb | 4 |
2 files changed, 35 insertions, 22 deletions
diff --git a/lib/puppet/provider/parsedfile.rb b/lib/puppet/provider/parsedfile.rb index b4a4a3b91..a4c4bc87c 100755 --- a/lib/puppet/provider/parsedfile.rb +++ b/lib/puppet/provider/parsedfile.rb @@ -108,10 +108,11 @@ class Puppet::Provider::ParsedFile < Puppet::Provider # Return a list of all of the records we can find. def self.instances - prefetch() - @records.find_all { |r| r[:record_type] == self.name }.collect { |r| - new(r) - } + targets.collect do |target| + prefetch_target(target) + end.flatten.reject { |r| skip_record?(r) }.collect do |record| + new(record) + end end # Override the default method with a lot more functionality. @@ -171,31 +172,39 @@ class Puppet::Provider::ParsedFile < Puppet::Provider # resource instance. def self.prefetch(resources = nil) # Reset the record list. - @records = [] - targets(resources).each do |target| - @records += prefetch_target(target) - end + @records = prefetch_all_targets(resources) - if resources - matchers = resources.dup - @records.each do |record| - # Skip things like comments and blank lines - next if skip_record?(record) + match_providers_with_resources(resources) + end - if name = record[:name] and resource = resources[name] + def self.match_providers_with_resources(resources) + return unless resources + matchers = resources.dup + @records.each do |record| + # Skip things like comments and blank lines + next if skip_record?(record) + + if name = record[:name] and resource = resources[name] + resource.provider = new(record) + elsif respond_to?(:match) + if resource = match(record, matchers) + # Remove this resource from circulation so we don't unnecessarily try to match + matchers.delete(resource.title) + record[:name] = resource[:name] resource.provider = new(record) - elsif respond_to?(:match) - if resource = match(record, matchers) - # Remove this resource from circulation so we don't unnecessarily try to match - matchers.delete(resource.title) - record[:name] = resource[:name] - resource.provider = new(record) - end end end end end + def self.prefetch_all_targets(resources) + records = [] + targets(resources).each do |target| + records += prefetch_target(target) + end + records + end + # Prefetch an individual target. def self.prefetch_target(target) target_records = retrieve(target).each do |r| @@ -217,6 +226,7 @@ class Puppet::Provider::ParsedFile < Puppet::Provider # Is there an existing record with this name? def self.record?(name) + return nil unless @records @records.find { |r| r[:name] == name } end @@ -367,4 +377,3 @@ class Puppet::Provider::ParsedFile < Puppet::Provider end end end - diff --git a/lib/puppet/util/nagios_maker.rb b/lib/puppet/util/nagios_maker.rb index a7aae4e70..316334929 100644 --- a/lib/puppet/util/nagios_maker.rb +++ b/lib/puppet/util/nagios_maker.rb @@ -42,6 +42,7 @@ module Puppet::Util::NagiosMaker target = "/etc/nagios/#{full_name.to_s}.cfg" provider = type.provide(:naginator, :parent => Puppet::Provider::Naginator, :default_target => target) {} + provider.nagios_type type.desc "The Nagios type #{name.to_s}. This resource type is autogenerated using the model developed in Naginator_, and all of the Nagios types are generated using the @@ -51,6 +52,9 @@ module Puppet::Util::NagiosMaker files. By default, the statements will be added to ``#{target}``, but you can send them to a different file by setting their ``target`` attribute. + You can purge Nagios resources using the ``resources`` type, but *only* + in the default file locations. This is an architectural limitation. + .. _naginator: http://reductivelabs.com/trac/naginator " end |