diff --git a/lib/puppet/rails/host.rb b/lib/puppet/rails/host.rb index 441b9ee54..3ab483654 100644 --- a/lib/puppet/rails/host.rb +++ b/lib/puppet/rails/host.rb @@ -1,110 +1,109 @@ require 'puppet/rails/resource' -require 'pp' 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 ] 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) if obj = self.find_by_name(host) obj.rails_objects.clear return obj else return nil end end # Store our host in the database. def self.store(hash) unless hash[:name] raise ArgumentError, "You must specify the hostname for storage" end args = {} if hash[:facts].include?("ipaddress") args[:ip] = hash[:facts]["ipaddress"] end host = nil Puppet::Util.benchmark(:info, "Found/created host") do host = self.find_or_create_by_name(hash[:facts]["hostname"], args) end 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.loadall Puppet::Type.eachtype do |type| typenames << type.name.to_s end Puppet::Util.benchmark(:info, "Converted resources") do 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 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 end Puppet::Util.benchmark(:info, "Saved host to database") do host.save end return host end # Add all of our RailsObjects def addobjects(objects) objects.each do |tobj| params = {} tobj.each do |p,v| params[p] = v end args = {:ptype => tobj.type, :name => tobj.name} [:tags, :file, :line].each do |param| if val = tobj.send(param) args[param] = val end end robj = rails_objects.build(args) robj.addparams(params) if tobj.collectable robj.toggle(:collectable) end end end end # $Id$ diff --git a/lib/puppet/rails/rails_parameter.rb b/lib/puppet/rails/rails_parameter.rb deleted file mode 100644 index 295662146..000000000 --- a/lib/puppet/rails/rails_parameter.rb +++ /dev/null @@ -1,13 +0,0 @@ -class Puppet::Rails::RailsParameter < ActiveRecord::Base - belongs_to :rails_resources - - def to_resourceparam(source) - hash = self.attributes - hash[:source] = source - hash.delete("rails_resource_id") - hash.delete("id") - Puppet::Parser::Resource::Param.new hash - end -end - -# $Id$ diff --git a/lib/puppet/rails/rails_resource.rb b/lib/puppet/rails/rails_resource.rb deleted file mode 100644 index 0b981f963..000000000 --- a/lib/puppet/rails/rails_resource.rb +++ /dev/null @@ -1,35 +0,0 @@ -require 'puppet' -require 'puppet/rails/rails_parameter' - -#RailsParameter = Puppet::Rails::RailsParameter -class Puppet::Rails::RailsResource < ActiveRecord::Base - has_many :rails_parameters, :dependent => :delete_all - serialize :tags, Array - - belongs_to :host - - # Convert our object to a resource. Do not retain whether the object - # is collectable, though, since that would cause it to get stripped - # from the configuration. - def to_resource(scope) - hash = self.attributes - hash["type"] = hash["restype"] - hash.delete("restype") - hash.delete("host_id") - hash.delete("id") - hash.each do |p, v| - hash.delete(p) if v.nil? - end - hash[:scope] = scope - hash[:source] = scope.source - hash[:rails_id] = self.id - obj = Puppet::Parser::Resource.new(hash) - rails_parameters.each do |param| - obj.set(param.to_resourceparam(scope.source)) - end - - return obj - end -end - -# $Id$