summaryrefslogtreecommitdiffstats
path: root/lib/puppet/rails
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/rails
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/rails')
-rw-r--r--lib/puppet/rails/host.rb26
1 files changed, 25 insertions, 1 deletions
diff --git a/lib/puppet/rails/host.rb b/lib/puppet/rails/host.rb
index 851cc21d9..23a22553d 100644
--- a/lib/puppet/rails/host.rb
+++ b/lib/puppet/rails/host.rb
@@ -22,6 +22,18 @@ class Puppet::Rails::Host < ActiveRecord::Base
end
end
+ def self.from_puppet(node)
+ host = find_by_name(node.name) || new(:name => node.name)
+
+ {"ipaddress" => "ip", "environment" => "environment"}.each do |myparam, itsparam|
+ if value = node.send(myparam)
+ host.send(itsparam + "=", value)
+ end
+ end
+
+ host
+ end
+
# Store our host in the database.
def self.store(node, resources)
args = {}
@@ -70,6 +82,8 @@ class Puppet::Rails::Host < ActiveRecord::Base
end
# returns a hash of fact_names.name => [ fact_values ] for this host.
+ # Note that 'fact_values' is actually a list of the value instances, not
+ # just actual values.
def get_facts_hash
fact_values = self.fact_values.find(:all, :include => :fact_name)
return fact_values.inject({}) do | hash, value |
@@ -202,5 +216,15 @@ class Puppet::Rails::Host < ActiveRecord::Base
self.last_connect = Time.now
save
end
-end
+ def to_puppet
+ node = Puppet::Node.new(self.name)
+ {"ip" => "ipaddress", "environment" => "environment"}.each do |myparam, itsparam|
+ if value = send(myparam)
+ node.send(itsparam + "=", value)
+ end
+ end
+
+ node
+ end
+end