class Puppet::Node::Facts::InventoryActiveRecord

Public Instance Methods

find(request) click to toggle source
# File lib/puppet/indirector/facts/inventory_active_record.rb, line 19
def find(request)
  node = Puppet::Rails::InventoryNode.find_by_name(request.key)
  return nil unless node
  facts = Puppet::Node::Facts.new(node.name, node.facts_to_hash)
  facts.timestamp = node.timestamp
  facts
end
save(request) click to toggle source
# File lib/puppet/indirector/facts/inventory_active_record.rb, line 27
def save(request)
  Puppet::Util::RetryAction.retry_action :retries => 4, :retry_exceptions => {ActiveRecord::StatementInvalid => 'MySQL Error.  Retrying'} do
    facts = request.instance
    node = Puppet::Rails::InventoryNode.find_by_name(request.key) || Puppet::Rails::InventoryNode.create(:name => request.key, :timestamp => facts.timestamp)
    node.timestamp = facts.timestamp

    ActiveRecord::Base.transaction do
      Puppet::Rails::InventoryFact.delete_all(:node_id => node.id)
      # We don't want to save internal values as facts, because those are
      # metadata that belong on the node
      facts.values.each do |name,value|
        next if name.to_s =~ /^_/
        node.facts.build(:name => name, :value => value)
      end
      node.save
    end
  end
end

Public Class Methods

new() click to toggle source
# File lib/puppet/indirector/facts/inventory_active_record.rb, line 13
def initialize
  raise Puppet::Error, "ActiveRecords-based inventory is unsupported with Ruby 2 and Rails 3.0" if RUBY_VERSION[0] == '2'
  Puppet.deprecation_warning "ActiveRecord-based storeconfigs and inventory are deprecated. See http://links.puppetlabs.com/activerecord-deprecation"
  super
end