summaryrefslogtreecommitdiffstats
path: root/lib/puppet/indirector/facts
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2009-04-06 16:38:14 -0500
committerJames Turnbull <james@lovedthanlost.net>2009-04-22 14:39:35 +1000
commitb9c95ebf81eeb78297003de2d0ed4ca048412393 (patch)
tree184d2f5c693c6183ac59414ff339553744d110cd /lib/puppet/indirector/facts
parent8d0e9976b199a637d82d70701db6c682a89b9d6a (diff)
downloadpuppet-b9c95ebf81eeb78297003de2d0ed4ca048412393.tar.gz
puppet-b9c95ebf81eeb78297003de2d0ed4ca048412393.tar.xz
puppet-b9c95ebf81eeb78297003de2d0ed4ca048412393.zip
Adding ActiveRecord terminus classes for Node and Facts.
This is most of the way to replacing standard StoreConfigs integration with the Indirector. We still need to convert the Catalog and then change all of the integraiton points (which is mostly the 'store' call in the Compiler). Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'lib/puppet/indirector/facts')
-rw-r--r--lib/puppet/indirector/facts/active_record.rb35
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/puppet/indirector/facts/active_record.rb b/lib/puppet/indirector/facts/active_record.rb
new file mode 100644
index 000000000..5fb2596d7
--- /dev/null
+++ b/lib/puppet/indirector/facts/active_record.rb
@@ -0,0 +1,35 @@
+require 'puppet/rails/fact_name'
+require 'puppet/rails/fact_value'
+require 'puppet/indirector/active_record'
+
+class Puppet::Node::Facts::ActiveRecord < Puppet::Indirector::ActiveRecord
+ use_ar_model Puppet::Rails::Host
+
+ # Find the Rails host and pull its facts as a Facts instance.
+ def find(request)
+ return nil unless host = ar_model.find_by_name(request.key, :include => {:fact_values => :fact_name})
+
+ facts = Puppet::Node::Facts.new(host.name)
+ facts.values = host.get_facts_hash.inject({}) do |hash, ary|
+ # Convert all single-member arrays into plain values.
+ param = ary[0]
+ values = ary[1].collect { |v| v.value }
+ values = values[0] if values.length == 1
+ hash[param] = values
+ hash
+ end
+
+ facts
+ end
+
+ # Save the values from a Facts instance as the facts on a Rails Host instance.
+ def save(request)
+ facts = request.instance
+
+ host = ar_model.find_by_name(facts.name) || ar_model.create(:name => facts.name)
+
+ host.setfacts(facts.values)
+
+ host.save
+ end
+end