Sha256: 10b9536a65914bfa8c8c6793fd11a8bae33a67d1cf1c618ba28038ff05d5165e

Contents?: true

Size: 1.04 KB

Versions: 65

Compression:

Stored size: 1.04 KB

Contents

require 'puppet/rails/fact_name'
require 'puppet/rails/fact_value'
require 'puppet/rails/host'
require 'puppet/indirector/active_record'

class Puppet::Node::Facts::ActiveRecord < Puppet::Indirector::ActiveRecord
  use_ar_model Puppet::Rails::Host

  # Find the Rails host and pull its facts as a Facts instance.
  def find(request)
    return nil unless host = ar_model.find_by_name(request.key, :include => {:fact_values => :fact_name})

    facts = Puppet::Node::Facts.new(host.name)
    facts.values = host.get_facts_hash.inject({}) do |hash, ary|
      # Convert all single-member arrays into plain values.
      param = ary[0]
      values = ary[1].collect { |v| v.value }
      values = values[0] if values.length == 1
      hash[param] = values
      hash
    end

    facts
  end

  # Save the values from a Facts instance as the facts on a Rails Host instance.
  def save(request)
    facts = request.instance

    host = ar_model.find_by_name(facts.name) || ar_model.create(:name => facts.name)

    host.merge_facts(facts.values)

    host.save
  end
end

Version data entries

65 entries across 65 versions & 4 rubygems

Version Path
puppet-parse-0.1.4 lib/vendor/puppet/indirector/facts/active_record.rb
puppet-parse-0.1.3 lib/vendor/puppet/indirector/facts/active_record.rb
puppet-parse-0.1.2 lib/vendor/puppet/indirector/facts/active_record.rb
puppet-parse-0.1.1 lib/vendor/puppet/indirector/facts/active_record.rb
puppet-2.7.26 lib/puppet/indirector/facts/active_record.rb
puppet-2.7.25 lib/puppet/indirector/facts/active_record.rb
puppet-2.7.24 lib/puppet/indirector/facts/active_record.rb
puppet-2.7.23 lib/puppet/indirector/facts/active_record.rb
puppet-2.7.22 lib/puppet/indirector/facts/active_record.rb
puppet-parse-0.1.0 lib/vendor/puppet/indirector/facts/active_record.rb
puppet-parse-0.0.6 lib/vendor/puppet/indirector/facts/active_record.rb
puppet-2.7.21 lib/puppet/indirector/facts/active_record.rb
puppet-2.6.18 lib/puppet/indirector/facts/active_record.rb
puppet-parse-0.0.5 lib/vendor/puppet/indirector/facts/active_record.rb
puppet-parse-0.0.4 lib/vendor/puppet/indirector/facts/active_record.rb
puppet-parse-0.0.2 lib/vendor/puppet/indirector/facts/active_record.rb
puppet-2.7.20 lib/puppet/indirector/facts/active_record.rb
puppet-2.7.20.rc1 lib/puppet/indirector/facts/active_record.rb
librarian-puppet-0.9.4 vendor/gems/ruby/1.8/gems/puppet-2.7.18/lib/puppet/indirector/facts/active_record.rb
puppet-3.0.0.rc5 lib/puppet/indirector/facts/active_record.rb