diff options
author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-05-13 04:52:34 +0000 |
---|---|---|
committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-05-13 04:52:34 +0000 |
commit | 5863a0336e1f3bd5e1be85676bb0e7ac7337f2e6 (patch) | |
tree | 7d6cadbf16f19cab8d3c89db3a4b95161241c88b /lib/puppet/rails.rb | |
parent | 0819e35be74bc997c3a953f05bab874b8d76429d (diff) | |
download | puppet-5863a0336e1f3bd5e1be85676bb0e7ac7337f2e6.tar.gz puppet-5863a0336e1f3bd5e1be85676bb0e7ac7337f2e6.tar.xz puppet-5863a0336e1f3bd5e1be85676bb0e7ac7337f2e6.zip |
Adding initial rails support. One can now store host configurations using ActiveRecord into a database (I have only tested sqlite3). Tomorrow will be the grammars used to retrieve those records for object collection.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1187 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/puppet/rails.rb')
-rw-r--r-- | lib/puppet/rails.rb | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/lib/puppet/rails.rb b/lib/puppet/rails.rb new file mode 100644 index 000000000..e9eeeaed5 --- /dev/null +++ b/lib/puppet/rails.rb @@ -0,0 +1,80 @@ +# Load the appropriate libraries, or set a class indicating they aren't available + +require 'facter' +require 'puppet' + +begin + require 'active_record' +rescue LoadError => detail + if Facter["operatingsystem"].value == "Debian" + count = 0 + Dir.entries("/usr/share/rails").each do |dir| + libdir = File.join("/usr/share/rails", dir, "lib") + if FileTest.exists?(libdir) and ! $:.include?(libdir) + count += 1 + $: << libdir + end + end + + if count > 0 + retry + end + end +end + +module Puppet::Rails + Puppet.config.setdefaults(:puppetmaster, + :dblocation => { :default => "$statedir/clientconfigs.sqlite3", + :mode => 0600, + :desc => "The database cache for client configurations. Used for + querying within the language." + }, + :dbadapter => [ "sqlite3", "The type of database to use." ], + :dbname => [ "puppet", "The name of the database to use." ], + :dbserver => [ "puppet", "The database server for Client caching. Only + used when networked databases are used."], + :dbuser => [ "puppet", "The database user for Client caching. Only + used when networked databases are used."], + :dbpassword => [ "puppet", "The database password for Client caching. Only + used when networked databases are used."], + :railslog => {:default => "$logdir/puppetrails.log", + :mode => 0600, + :desc => "Where Rails-specific logs are sent" + } + ) + + def self.setupdb + + end + + def self.init + Puppet.config.use(:puppet) + Puppet.config.use(:puppetmaster) + + ActiveRecord::Base.logger = Logger.new(Puppet[:railslog]) + args = {:adapter => Puppet[:dbadapter]} + + case Puppet[:dbadapter] + when "sqlite3": + args[:database] = Puppet[:dblocation] + when "mysql": + args[:host] = Puppet[:dbserver] + args[:username] = Puppet[:dbuser] + args[:password] = Puppet[:dbpassword] + args[:database] = Puppet[:dbname] + end + + ActiveRecord::Base.establish_connection(args) + + unless FileTest.exists?(args[:database]) + require 'puppet/rails/database' + Puppet::Rails::Database.up + end + end +end + +if defined? ActiveRecord::Base + require 'puppet/rails/host' +end + +# $Id$ |