diff options
| author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-12-15 00:11:00 +0000 |
|---|---|---|
| committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-12-15 00:11:00 +0000 |
| commit | 0cd579997a8ea619968c58a39493d28b9af87e6d (patch) | |
| tree | 7dae1fec31ee2545b98fd10c0a581c641270c950 /lib | |
| parent | 6d9ae0cf32f43cbcffa2ac8fb355c65d8ceeb9a0 (diff) | |
| download | puppet-0cd579997a8ea619968c58a39493d28b9af87e6d.tar.gz puppet-0cd579997a8ea619968c58a39493d28b9af87e6d.tar.xz puppet-0cd579997a8ea619968c58a39493d28b9af87e6d.zip | |
Some rails modifications
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1931 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/puppet/rails.rb | 10 | ||||
| -rw-r--r-- | lib/puppet/rails/database/01_puppet_initialize.rb | 45 | ||||
| -rw-r--r-- | lib/puppet/rails/host.rb | 33 |
3 files changed, 24 insertions, 64 deletions
diff --git a/lib/puppet/rails.rb b/lib/puppet/rails.rb index 90330c2f2..2ad25a003 100644 --- a/lib/puppet/rails.rb +++ b/lib/puppet/rails.rb @@ -12,7 +12,8 @@ module Puppet::Rails :desc => "The database cache for client configurations. Used for querying within the language." }, - :dbadapter => [ "mysql", "The type of database to use." ], + :dbadapter => [ "sqlite3", "The type of database to use." ], + :dbmigrate => [ false, "Whether to automatically migrate the database." ], :dbname => [ "puppet", "The name of the database to use." ], :dbserver => [ "localhost", "The database server for Client caching. Only used when networked databases are used."], @@ -108,20 +109,19 @@ module Puppet::Rails end unless ActiveRecord::Base.connection.tables.include?("resources") require 'puppet/rails/database/schema' - Puppet::Rails::Schema.init - #puts "Database initialized: #{@inited.inspect} " + Puppet::Rails::Schema.init end @inited = true end ActiveRecord::Base.logger = Logger.new(Puppet[:railslog]) - if Puppet[:dbadapter] == "sqlite3" and ! FileTest.exists?(Puppet[:dblocation]) - + if Puppet[:dbmigrate] dbdir = nil $:.each { |d| tmp = File.join(d, "puppet/rails/database") if FileTest.directory?(tmp) dbdir = tmp + break end } diff --git a/lib/puppet/rails/database/01_puppet_initialize.rb b/lib/puppet/rails/database/01_puppet_initialize.rb deleted file mode 100644 index 485634004..000000000 --- a/lib/puppet/rails/database/01_puppet_initialize.rb +++ /dev/null @@ -1,45 +0,0 @@ -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/host.rb b/lib/puppet/rails/host.rb index dd6ffce0e..441b9ee54 100644 --- a/lib/puppet/rails/host.rb +++ b/lib/puppet/rails/host.rb @@ -36,7 +36,10 @@ class Puppet::Rails::Host < ActiveRecord::Base if hash[:facts].include?("ipaddress") args[:ip] = hash[:facts]["ipaddress"] end - host = self.find_or_create_by_name(hash[:facts]["hostname"], args) + 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) @@ -48,27 +51,29 @@ class Puppet::Rails::Host < ActiveRecord::Base raise ArgumentError, "You must pass resources" end - typenames = [] + typenames = [] Puppet::Type.loadall Puppet::Type.eachtype do |type| typenames << type.name.to_s end - hash[:resources].each do |resource| - resargs = resource.to_hash.stringify_keys + 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 + 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 + 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 |
