diff options
author | shadoi <shadoi@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-12-14 23:20:26 +0000 |
---|---|---|
committer | shadoi <shadoi@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-12-14 23:20:26 +0000 |
commit | 8714e14c10492361cac62726a3c1abe44d9ec23f (patch) | |
tree | 007d3d0e5351222a4f49a3d6827b352c1421a538 /lib/puppet/rails/host.rb | |
parent | 026ec4f3996655f01b85b03c6db79c9e15d035c5 (diff) | |
download | puppet-8714e14c10492361cac62726a3c1abe44d9ec23f.tar.gz puppet-8714e14c10492361cac62726a3c1abe44d9ec23f.tar.xz puppet-8714e14c10492361cac62726a3c1abe44d9ec23f.zip |
New rails stuff redux.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1925 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/puppet/rails/host.rb')
-rw-r--r-- | lib/puppet/rails/host.rb | 64 |
1 files changed, 42 insertions, 22 deletions
diff --git a/lib/puppet/rails/host.rb b/lib/puppet/rails/host.rb index ccda1af64..ab435caa4 100644 --- a/lib/puppet/rails/host.rb +++ b/lib/puppet/rails/host.rb @@ -1,12 +1,19 @@ -require 'puppet/rails/rails_resource' +require 'puppet/rails/resource' +require 'pp' -#RailsObject = Puppet::Rails::RailsObject class Puppet::Rails::Host < ActiveRecord::Base - serialize :facts, Hash - serialize :classes, Array + has_many :fact_values, :through => :fact_names + has_many :fact_names + belongs_to :puppet_classes + has_many :source_files + has_many :resources, :include => [ :param_names, :param_values ] - has_many :rails_resources, :dependent => :delete_all, - :include => :rails_parameters + acts_as_taggable + + def facts(name) + fv = self.fact_values.find(:first, :conditions => "fact_names.name = '#{name}'") + return fv.value + end # If the host already exists, get rid of its objects def self.clean(host) @@ -25,33 +32,46 @@ class Puppet::Rails::Host < ActiveRecord::Base end args = {} - [:name, :facts, :classes].each do |param| - if hash[param] - args[param] = hash[param] - end - end if hash[:facts].include?("ipaddress") args[:ip] = hash[:facts]["ipaddress"] end + host = self.find_or_create_by_name(hash[:facts]["hostname"], args) + + hash[:facts].each do |name, value| + fn = host.fact_names.find_or_create_by_name(name) + fv = fn.fact_values.find_or_create_by_value(value) + host.fact_names << fn + end unless hash[:resources] raise ArgumentError, "You must pass resources" end - if host = self.find_by_name(hash[:name]) - args.each do |param, value| - unless host[param] == args[param] - host[param] = args[param] - end - end - else - # Create it anew - host = self.new(args) + typenames = [] + Puppet::Type.loadall + Puppet::Type.eachtype do |type| + typenames << type.name.to_s end - hash[:resources].each do |res| - res.store(host) + hash[:resources].each do |resource| + resargs = resource.to_hash.stringify_keys + + + if typenames.include?(resource.type) + rtype = "Puppet#{resource.type.to_s.capitalize}" + end + + res = host.resources.find_or_create_by_title(resource[:title]) + res.type = rtype +f = File.new("/tmp/rtype.dump", "w+") +f.puts rtype + res.save + resargs.each do |param, value| + pn = res.param_names.find_or_create_by_name(param) + pv = pn.param_values.find_or_create_by_value(value) + res.param_names << pn + end end Puppet::Util.benchmark(:info, "Saved host to database") do |