summaryrefslogtreecommitdiffstats
path: root/lib/puppet
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2009-04-06 19:10:59 -0500
committerJames Turnbull <james@lovedthanlost.net>2009-04-22 14:39:35 +1000
commita137146562fecc909afe7fc81f0033fccbb36393 (patch)
tree1e140829efe5addd07a1a0ce20b8e9905cbd8bf5 /lib/puppet
parentb9c95ebf81eeb78297003de2d0ed4ca048412393 (diff)
downloadpuppet-a137146562fecc909afe7fc81f0033fccbb36393.tar.gz
puppet-a137146562fecc909afe7fc81f0033fccbb36393.tar.xz
puppet-a137146562fecc909afe7fc81f0033fccbb36393.zip
Adding ActiveRecord terminus classes for Catalog
This provides the last piece of ActiveRecord integration. It's pretty much just pass-through and *only* works if you're storing Parser resources to the db. Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'lib/puppet')
-rw-r--r--lib/puppet/indirector/catalog/active_record.rb34
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/puppet/indirector/catalog/active_record.rb b/lib/puppet/indirector/catalog/active_record.rb
new file mode 100644
index 000000000..f57427e92
--- /dev/null
+++ b/lib/puppet/indirector/catalog/active_record.rb
@@ -0,0 +1,34 @@
+require 'puppet/rails/host'
+require 'puppet/indirector/active_record'
+require 'puppet/node/catalog'
+
+class Puppet::Node::Catalog::ActiveRecord < Puppet::Indirector::ActiveRecord
+ use_ar_model Puppet::Rails::Host
+
+ # If we can find the host, then return a catalog with the host's resources
+ # as the vertices.
+ def find(request)
+ return nil unless request.options[:cache_integration_hack]
+ return nil unless host = ar_model.find_by_name(request.key)
+
+ catalog = Puppet::Node::Catalog.new(host.name)
+
+ host.resources.each do |resource|
+ catalog.add_resource resource.to_transportable
+ end
+
+ catalog
+ end
+
+ # Save the values from a Facts instance as the facts on a Rails Host instance.
+ def save(request)
+ catalog = request.instance
+
+ host = ar_model.find_by_name(catalog.name) || ar_model.create(:name => catalog.name)
+
+ host.setresources(catalog.vertices)
+ host.last_compile = Time.now
+
+ host.save
+ end
+end