# 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
# 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
# File lib/puppet/indirector/facts/inventory_active_record.rb, line 46 def search(request) return [] unless request.options matching_nodes = [] fact_filters = Hash.new {|h,k| h[k] = []} meta_filters = Hash.new {|h,k| h[k] = []} request.options.each do |key,value| type, name, operator = key.to_s.split(".") operator ||= "eq" if type == "facts" fact_filters[operator] << [name,value] elsif type == "meta" and name == "timestamp" meta_filters[operator] << [name,value] end end matching_nodes = nodes_matching_fact_filters(fact_filters) + nodes_matching_meta_filters(meta_filters) # to_a because [].inject == nil matching_nodes.inject {|nodes,this_set| nodes & this_set}.to_a.sort end
# 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