diff options
author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-11-13 07:49:48 +0000 |
---|---|---|
committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-11-13 07:49:48 +0000 |
commit | 35de0e3bd74e94de92ac0e9209a4884cf07c88a0 (patch) | |
tree | be7119181bc15dad6575cc5b7087c92cfd7fbac8 /lib/puppet/rails | |
parent | 26b32b953d8e097785b38aa90e5e4bff6ae9247e (diff) | |
download | puppet-35de0e3bd74e94de92ac0e9209a4884cf07c88a0.tar.gz puppet-35de0e3bd74e94de92ac0e9209a4884cf07c88a0.tar.xz puppet-35de0e3bd74e94de92ac0e9209a4884cf07c88a0.zip |
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
Diffstat (limited to 'lib/puppet/rails')
-rw-r--r-- | lib/puppet/rails/database/01_puppet_initialize.rb | 45 | ||||
-rw-r--r-- | lib/puppet/rails/database/schema_init.rb | 64 | ||||
-rw-r--r-- | lib/puppet/rails/fact_name.rb | 3 | ||||
-rw-r--r-- | lib/puppet/rails/fact_value.rb | 3 | ||||
-rw-r--r-- | lib/puppet/rails/host.rb | 59 | ||||
-rw-r--r-- | lib/puppet/rails/lib/README | 4 | ||||
-rw-r--r-- | lib/puppet/rails/lib/acts_as_taggable.rb | 58 | ||||
-rw-r--r-- | lib/puppet/rails/lib/init.rb | 5 | ||||
-rw-r--r-- | lib/puppet/rails/lib/tag.rb | 40 | ||||
-rw-r--r-- | lib/puppet/rails/lib/tagging.rb | 12 | ||||
-rw-r--r-- | lib/puppet/rails/param_name.rb | 13 | ||||
-rw-r--r-- | lib/puppet/rails/param_value.rb | 5 | ||||
-rw-r--r-- | lib/puppet/rails/puppet_class.rb | 7 | ||||
-rw-r--r-- | lib/puppet/rails/rails_parameter.rb | 13 | ||||
-rw-r--r-- | lib/puppet/rails/rails_resource.rb | 34 | ||||
-rw-r--r-- | lib/puppet/rails/resource.rb | 49 | ||||
-rw-r--r-- | lib/puppet/rails/source_file.rb | 3 |
17 files changed, 114 insertions, 303 deletions
diff --git a/lib/puppet/rails/database/01_puppet_initialize.rb b/lib/puppet/rails/database/01_puppet_initialize.rb new file mode 100644 index 000000000..485634004 --- /dev/null +++ b/lib/puppet/rails/database/01_puppet_initialize.rb @@ -0,0 +1,45 @@ +class PuppetInitialize < ActiveRecord::Migration + require 'sqlite3' + + def self.up + if ActiveRecord::Migration.respond_to?(:verbose) + ActiveRecord::Migration.verbose = false + end + + # 'type' cannot be a column name, apparently + create_table :rails_resources do |table| + table.column :title, :string, :null => false + table.column :restype, :string, :null => false + table.column :tags, :string + table.column :file, :string + table.column :line, :integer + table.column :host_id, :integer + table.column :exported, :boolean + end + + create_table :rails_parameters do |table| + table.column :name, :string, :null => false + table.column :value, :string, :null => false + table.column :file, :string + table.column :line, :integer + table.column :rails_resource_id, :integer + end + + create_table :hosts do |table| + table.column :name, :string, :null => false + table.column :ip, :string + table.column :facts, :string + table.column :connect, :date + table.column :success, :date + table.column :classes, :string + end + end + + def self.down + drop_table :rails_resources + drop_table :rails_parameters + drop_table :hosts + end +end + +# $Id$ diff --git a/lib/puppet/rails/database/schema_init.rb b/lib/puppet/rails/database/schema_init.rb deleted file mode 100644 index 9151bee46..000000000 --- a/lib/puppet/rails/database/schema_init.rb +++ /dev/null @@ -1,64 +0,0 @@ -class Puppet::Rails::Schema - -def self.init - ActiveRecord::Schema.define do - create_table :resources do |t| - t.column :title, :string, :null => false - t.column :type, :string - t.column :host_id, :integer - t.column :source_file_id, :integer - t.column :exported, :boolean - end - - create_table :source_files do |t| - t.column :filename, :string - t.column :path, :string - end - - create_table :puppet_classes do |t| - t.column :name, :string - t.column :host_id, :integer - t.column :source_file_id, :integer - end - - create_table :hosts do |t| - t.column :name, :string, :null => false - t.column :ip, :string - t.column :connect, :date - #Use updated_at to automatically add timestamp on save. - t.column :updated_at, :date - t.column :source_file_id, :integer - end - - create_table :fact_names do |t| - t.column :name, :string, :null => false - t.column :host_id, :integer, :null => false - end - - create_table :fact_values do |t| - t.column :value, :string, :null => false - t.column :fact_name_id, :integer, :null => false - end - - create_table :param_values do |t| - t.column :value, :string, :null => false - t.column :param_name_id, :integer, :null => false - end - - create_table :param_names do |t| - t.column :name, :string, :null => false - t.column :resource_id, :integer - end - - create_table :tags do |t| - t.column :name, :string - end - - create_table :taggings do |t| - t.column :tag_id, :integer - t.column :taggable_id, :integer - t.column :taggable_type, :string - end - end -end -end diff --git a/lib/puppet/rails/fact_name.rb b/lib/puppet/rails/fact_name.rb deleted file mode 100644 index 886618ecb..000000000 --- a/lib/puppet/rails/fact_name.rb +++ /dev/null @@ -1,3 +0,0 @@ -class Puppet::Rails::FactName < ActiveRecord::Base - has_many :fact_values -end diff --git a/lib/puppet/rails/fact_value.rb b/lib/puppet/rails/fact_value.rb deleted file mode 100644 index 4da74b713..000000000 --- a/lib/puppet/rails/fact_value.rb +++ /dev/null @@ -1,3 +0,0 @@ -class Puppet::Rails::FactValue < ActiveRecord::Base - belongs_to :fact_names -end 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 diff --git a/lib/puppet/rails/lib/README b/lib/puppet/rails/lib/README deleted file mode 100644 index 8d2f90822..000000000 --- a/lib/puppet/rails/lib/README +++ /dev/null @@ -1,4 +0,0 @@ -Acts As Taggable -================= - -Allows for tags to be added to multiple classes.
\ No newline at end of file diff --git a/lib/puppet/rails/lib/acts_as_taggable.rb b/lib/puppet/rails/lib/acts_as_taggable.rb deleted file mode 100644 index e9bd03696..000000000 --- a/lib/puppet/rails/lib/acts_as_taggable.rb +++ /dev/null @@ -1,58 +0,0 @@ -module ActiveRecord
- module Acts #:nodoc:
- module Taggable #:nodoc:
- def self.included(base)
- base.extend(ClassMethods)
- end
-
- module ClassMethods
- def acts_as_taggable(options = {})
- write_inheritable_attribute(:acts_as_taggable_options, {
- :taggable_type => ActiveRecord::Base.send(:class_name_of_active_record_descendant, self).to_s,
- :from => options[:from]
- })
-
- class_inheritable_reader :acts_as_taggable_options
-
- has_many :taggings, :as => :taggable, :dependent => true
- has_many :tags, :through => :taggings
-
- include ActiveRecord::Acts::Taggable::InstanceMethods
- extend ActiveRecord::Acts::Taggable::SingletonMethods
- end
- end
-
- module SingletonMethods
- def find_tagged_with(list)
- find_by_sql([
- "SELECT #{table_name}.* FROM #{table_name}, tags, taggings " +
- "WHERE #{table_name}.#{primary_key} = taggings.taggable_id " +
- "AND taggings.taggable_type = ? " +
- "AND taggings.tag_id = tags.id AND tags.name IN (?)",
- acts_as_taggable_options[:taggable_type], list
- ])
- end
- end
-
- module InstanceMethods
- def tag_with(list)
- Tag.transaction do
- taggings.destroy_all
-
- Tag.parse(list).each do |name|
- if acts_as_taggable_options[:from]
- send(acts_as_taggable_options[:from]).tags.find_or_create_by_name(name).on(self)
- else
- Tag.find_or_create_by_name(name).on(self)
- end
- end
- end
- end
-
- def tag_list
- tags.collect { |tag| tag.name.include?(" ") ? "'#{tag.name}'" : tag.name }.join(" ")
- end
- end
- end
- end
-end
\ No newline at end of file diff --git a/lib/puppet/rails/lib/init.rb b/lib/puppet/rails/lib/init.rb deleted file mode 100644 index 0a07e5c8e..000000000 --- a/lib/puppet/rails/lib/init.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'puppet/rails/lib/acts_as_taggable' -ActiveRecord::Base.send(:include, ActiveRecord::Acts::Taggable) - -require 'puppet/rails/lib/tagging' -require 'puppet/rails/lib/tag' diff --git a/lib/puppet/rails/lib/tag.rb b/lib/puppet/rails/lib/tag.rb deleted file mode 100644 index ca31171b2..000000000 --- a/lib/puppet/rails/lib/tag.rb +++ /dev/null @@ -1,40 +0,0 @@ -class Tag < ActiveRecord::Base - has_many :taggings - - def self.parse(list) - tag_names = [] - - # first, pull out the quoted tags - list.gsub!(/\"(.*?)\"\s*/ ) { tag_names << $1; "" } - - # then, replace all commas with a space - list.gsub!(/,/, " ") - - # then, get whatever's left - tag_names.concat list.split(/\s/) - - # strip whitespace from the names - tag_names = tag_names.map { |t| t.strip } - - # delete any blank tag names - tag_names = tag_names.delete_if { |t| t.empty? } - - return tag_names - end - - def tagged - @tagged ||= taggings.collect { |tagging| tagging.taggable } - end - - def on(taggable) - taggings.create :taggable => taggable - end - - def ==(comparison_object) - super || name == comparison_object.to_s - end - - def to_s - name - end -end
\ No newline at end of file diff --git a/lib/puppet/rails/lib/tagging.rb b/lib/puppet/rails/lib/tagging.rb deleted file mode 100644 index e06e88a14..000000000 --- a/lib/puppet/rails/lib/tagging.rb +++ /dev/null @@ -1,12 +0,0 @@ -class Tagging < ActiveRecord::Base - belongs_to :tag - belongs_to :taggable, :polymorphic => true - - def self.tagged_class(taggable) - ActiveRecord::Base.send(:class_name_of_active_record_descendant, taggable.class).to_s - end - - def self.find_taggable(tagged_class, tagged_id) - tagged_class.constantize.find(tagged_id) - end -end
\ No newline at end of file diff --git a/lib/puppet/rails/param_name.rb b/lib/puppet/rails/param_name.rb deleted file mode 100644 index 928838f5c..000000000 --- a/lib/puppet/rails/param_name.rb +++ /dev/null @@ -1,13 +0,0 @@ -class Puppet::Rails::ParamName < ActiveRecord::Base - has_many :param_values - belongs_to :resources - - def to_resourceparam(source) - hash = {} - hash[:name] = self.name.to_sym - hash[:source] = source - hash[:value] = self.param_values.find(:first).value - Puppet::Parser::Resource::Param.new hash - end -end - diff --git a/lib/puppet/rails/param_value.rb b/lib/puppet/rails/param_value.rb deleted file mode 100644 index b01add4a7..000000000 --- a/lib/puppet/rails/param_value.rb +++ /dev/null @@ -1,5 +0,0 @@ -class Puppet::Rails::ParamValue < ActiveRecord::Base - belongs_to :param_names - -end - diff --git a/lib/puppet/rails/puppet_class.rb b/lib/puppet/rails/puppet_class.rb deleted file mode 100644 index de54a31e9..000000000 --- a/lib/puppet/rails/puppet_class.rb +++ /dev/null @@ -1,7 +0,0 @@ -class Puppet::Rails::PuppetClass < ActiveRecord::Base - has_many :resources - has_many :source_files - has_many :hosts - - acts_as_taggable -end diff --git a/lib/puppet/rails/rails_parameter.rb b/lib/puppet/rails/rails_parameter.rb new file mode 100644 index 000000000..295662146 --- /dev/null +++ b/lib/puppet/rails/rails_parameter.rb @@ -0,0 +1,13 @@ +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 new file mode 100644 index 000000000..caad1b460 --- /dev/null +++ b/lib/puppet/rails/rails_resource.rb @@ -0,0 +1,34 @@ +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 + obj = Puppet::Parser::Resource.new(hash) + rails_parameters.each do |param| + obj.set(param.to_resourceparam(scope.source)) + end + + return obj + end +end + +# $Id$ diff --git a/lib/puppet/rails/resource.rb b/lib/puppet/rails/resource.rb deleted file mode 100644 index bbe71305c..000000000 --- a/lib/puppet/rails/resource.rb +++ /dev/null @@ -1,49 +0,0 @@ -require 'puppet' -require 'puppet/rails/lib/init' -require 'puppet/rails/param_name' - -class Puppet::Rails::Resource < ActiveRecord::Base - has_many :param_values, :through => :param_names - has_many :param_names - has_many :source_files - belongs_to :hosts - - acts_as_taggable - - Puppet::Type.eachtype do |type| - klass = Class.new(Puppet::Rails::Resource) - Object.const_set("Puppet%s" % type.name.to_s.capitalize, klass) - end - - def parameters - hash = {} - self.param_values.find(:all).each do |pvalue| - pname = self.param_names.find(:first) - hash.store(pname.name.to_sym, pvalue.value) - end - return hash - end - - # 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.delete("type") - hash.delete("host_id") - hash.delete("source_file_id") - hash.delete("id") - hash.each do |p, v| - hash.delete(p) if v.nil? - end - hash[:type] = self.class.to_s.gsub(/Puppet/,'').downcase - hash[:scope] = scope - hash[:source] = scope.source - obj = Puppet::Parser::Resource.new(hash) - self.param_names.each do |pname| - obj.set(pname.to_resourceparam(scope.source)) - end - - return obj - end -end diff --git a/lib/puppet/rails/source_file.rb b/lib/puppet/rails/source_file.rb deleted file mode 100644 index d300ec74c..000000000 --- a/lib/puppet/rails/source_file.rb +++ /dev/null @@ -1,3 +0,0 @@ -class Puppet::Rails::SourceFile < ActiveRecord::Base - has_many :hosts, :puppet_classes, :resources -end |