summaryrefslogtreecommitdiffstats
path: root/lib/puppet/rails
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-12-15 00:11:00 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-12-15 00:11:00 +0000
commit0cd579997a8ea619968c58a39493d28b9af87e6d (patch)
tree7dae1fec31ee2545b98fd10c0a581c641270c950 /lib/puppet/rails
parent6d9ae0cf32f43cbcffa2ac8fb355c65d8ceeb9a0 (diff)
downloadpuppet-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/puppet/rails')
-rw-r--r--lib/puppet/rails/database/01_puppet_initialize.rb45
-rw-r--r--lib/puppet/rails/host.rb33
2 files changed, 19 insertions, 59 deletions
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