From 35de0e3bd74e94de92ac0e9209a4884cf07c88a0 Mon Sep 17 00:00:00 2001 From: luke Date: Mon, 13 Nov 2006 07:49:48 +0000 Subject: Temporarily reverting all of the recent rails work so that I can release 0.20.1 git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1873 980ebf18-57e1-0310-9a29-db15c13687c0 --- lib/puppet/rails/host.rb | 59 ++++++++++++++++++------------------------------ 1 file changed, 22 insertions(+), 37 deletions(-) (limited to 'lib/puppet/rails/host.rb') diff --git a/lib/puppet/rails/host.rb b/lib/puppet/rails/host.rb index 72ec64815..ccda1af64 100644 --- a/lib/puppet/rails/host.rb +++ b/lib/puppet/rails/host.rb @@ -1,18 +1,12 @@ -require 'puppet/rails/resource' +require 'puppet/rails/rails_resource' +#RailsObject = Puppet::Rails::RailsObject class Puppet::Rails::Host < ActiveRecord::Base - 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 ] + serialize :facts, Hash + serialize :classes, Array - acts_as_taggable - - def facts(name) - fv = self.fact_values.find(:first, :conditions => "fact_names.name = '#{name}'") - return fv.value - end + has_many :rails_resources, :dependent => :delete_all, + :include => :rails_parameters # If the host already exists, get rid of its objects def self.clean(host) @@ -31,42 +25,33 @@ 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 - typenames = [] - Puppet::Type.eachtype do |type| - typenames << type.name.to_s - end - - hash[:resources].each do |resource| - resargs = resource.to_hash.stringify_keys - - if typenames.include?(resource.instance_eval("type")) - rtype = "Puppet#{resource.instance_eval("type").capitalize}" + 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) + end - res = host.resources.find_or_create_by_title(resource[:title]) - res.type = 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 + hash[:resources].each do |res| + res.store(host) end Puppet::Util.benchmark(:info, "Saved host to database") do -- cgit