summaryrefslogtreecommitdiffstats
path: root/lib/puppet
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-05-20 23:59:04 -0500
committerLuke Kanies <luke@madstop.com>2008-05-20 23:59:04 -0500
commit419f2443c40116623b5c82f03eafcc85deeabcad (patch)
tree5cff2408998693744352c223743c43aa2c9c60cd /lib/puppet
parent3e13bd59689a27a393c847bdbed3ac38765d79e9 (diff)
downloadpuppet-419f2443c40116623b5c82f03eafcc85deeabcad.tar.gz
puppet-419f2443c40116623b5c82f03eafcc85deeabcad.tar.xz
puppet-419f2443c40116623b5c82f03eafcc85deeabcad.zip
Adding support for settings within the existing Facter provider confines.
This renames the 'facter' confine to 'variable', and it prefers settings to facts. There shouldn't really be any overlap, so it shouldn't be a problem.
Diffstat (limited to 'lib/puppet')
-rw-r--r--lib/puppet/provider/confine/variable.rb (renamed from lib/puppet/provider/confine/facter.rb)25
-rw-r--r--lib/puppet/provider/confine_collection.rb4
-rw-r--r--lib/puppet/reference/providers.rb8
3 files changed, 23 insertions, 14 deletions
diff --git a/lib/puppet/provider/confine/facter.rb b/lib/puppet/provider/confine/variable.rb
index 9bb66c058..84d17367a 100644
--- a/lib/puppet/provider/confine/facter.rb
+++ b/lib/puppet/provider/confine/variable.rb
@@ -1,32 +1,27 @@
require 'puppet/provider/confine'
-class Puppet::Provider::Confine::Facter < Puppet::Provider::Confine
+class Puppet::Provider::Confine::Variable < Puppet::Provider::Confine
def self.summarize(confines)
result = Hash.new { |hash, key| hash[key] = [] }
confines.inject(result) { |total, confine| total[confine.fact] += confine.values unless confine.valid?; total }
end
- attr_accessor :fact
-
- # Are we a facter comparison?
- def facter?
- defined?(@facter)
- end
+ attr_accessor :name
# Retrieve the value from facter
def facter_value
unless defined?(@facter_value) and @facter_value
- @facter_value = ::Facter.value(@fact).to_s.downcase
+ @facter_value = ::Facter.value(name).to_s.downcase
end
@facter_value
end
def message(value)
- "facter value '%s' for '%s' not in required list '%s'" % [value, self.fact, values.join(",")]
+ "facter value '%s' for '%s' not in required list '%s'" % [value, self.name, values.join(",")]
end
def pass?(value)
- facter_value == value.to_s.downcase
+ test_value.downcase.to_s == value.to_s.downcase
end
def reset
@@ -34,4 +29,14 @@ class Puppet::Provider::Confine::Facter < Puppet::Provider::Confine
# run, but across runs.
@facter_value = nil
end
+
+ private
+
+ def setting?
+ Puppet.settings.valid?(name)
+ end
+
+ def test_value
+ setting? ? Puppet.settings[name] : facter_value
+ end
end
diff --git a/lib/puppet/provider/confine_collection.rb b/lib/puppet/provider/confine_collection.rb
index 0c80086c9..35f461acb 100644
--- a/lib/puppet/provider/confine_collection.rb
+++ b/lib/puppet/provider/confine_collection.rb
@@ -15,8 +15,8 @@ class Puppet::Provider::ConfineCollection
@confines << klass.new(values)
@confines[-1].for_binary = true if for_binary
else
- confine = Puppet::Provider::Confine.test(:facter).new(values)
- confine.fact = test
+ confine = Puppet::Provider::Confine.test(:variable).new(values)
+ confine.name = test
@confines << confine
end
end
diff --git a/lib/puppet/reference/providers.rb b/lib/puppet/reference/providers.rb
index 610c7550d..8fd2dbadc 100644
--- a/lib/puppet/reference/providers.rb
+++ b/lib/puppet/reference/providers.rb
@@ -63,9 +63,13 @@ providers = Puppet::Util::Reference.newreference :providers, :title => "Provider
case test
when :exists:
details += " - Missing files %s\n" % values.join(", ")
- when :facter:
+ when :variable:
values.each do |name, facts|
- details += " - Fact %s (currently %s) not in list %s\n" % [name, Facter.value(name).inspect, facts.join(", ")]
+ if Puppet.settings.valid?(name)
+ details += " - Setting %s (currently %s) not in list %s\n" % [name, Puppet.settings.value(name).inspect, facts.join(", ")]
+ else
+ details += " - Fact %s (currently %s) not in list %s\n" % [name, Facter.value(name).inspect, facts.join(", ")]
+ end
end
when :true:
details += " - Got %s true tests that should have been false\n" % values