summaryrefslogtreecommitdiffstats
path: root/lib/puppet/indirector/facts
diff options
context:
space:
mode:
authorNick Lewis <nick@puppetlabs.com>2011-03-09 12:55:03 -0800
committerNick Lewis <nick@puppetlabs.com>2011-03-09 12:55:03 -0800
commit3489412a03fec009bc42222f449077e6f14998a4 (patch)
tree150d8cf61ea26caf00cd4add5934d83fd1b70027 /lib/puppet/indirector/facts
parente8763415627cf41cefece00bf4dbc48e9be81d1d (diff)
downloadpuppet-3489412a03fec009bc42222f449077e6f14998a4.tar.gz
puppet-3489412a03fec009bc42222f449077e6f14998a4.tar.xz
puppet-3489412a03fec009bc42222f449077e6f14998a4.zip
maint: Rename InventoryHost to InventoryNode
This had been conflating hosts and nodes, when nodes is the most accurate.
Diffstat (limited to 'lib/puppet/indirector/facts')
-rw-r--r--lib/puppet/indirector/facts/inventory_active_record.rb48
1 files changed, 24 insertions, 24 deletions
diff --git a/lib/puppet/indirector/facts/inventory_active_record.rb b/lib/puppet/indirector/facts/inventory_active_record.rb
index 5b8606839..2c2597f81 100644
--- a/lib/puppet/indirector/facts/inventory_active_record.rb
+++ b/lib/puppet/indirector/facts/inventory_active_record.rb
@@ -1,13 +1,13 @@
-require 'puppet/rails/inventory_host'
+require 'puppet/rails/inventory_node'
require 'puppet/rails/inventory_fact'
require 'puppet/indirector/active_record'
class Puppet::Node::Facts::InventoryActiveRecord < Puppet::Indirector::ActiveRecord
def find(request)
- host = Puppet::Rails::InventoryHost.find_by_name(request.key)
- return nil unless host
- facts = Puppet::Node::Facts.new(host.name, host.facts_to_hash)
- facts.timestamp = host.timestamp
+ 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.values.each do |key,value|
facts.values[key] = value.first if value.is_a?(Array) && value.length == 1
end
@@ -16,18 +16,18 @@ class Puppet::Node::Facts::InventoryActiveRecord < Puppet::Indirector::ActiveRec
def save(request)
facts = request.instance
- host = Puppet::Rails::InventoryHost.find_by_name(request.key) || Puppet::Rails::InventoryHost.create(:name => request.key, :timestamp => facts.timestamp)
- host.timestamp = facts.timestamp
+ 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(:inventory_host_id => host.id)
+ Puppet::Rails::InventoryFact.delete_all(:inventory_node_id => node.id)
# We don't want to save internal values as facts, because those are
- # metadata that belong on the host
+ # metadata that belong on the node
facts.values.each do |name,value|
next if name.to_s =~ /^_/
- host.facts.build(:name => name, :value => value)
+ node.facts.build(:name => name, :value => value)
end
- host.save
+ node.save
end
end
@@ -46,21 +46,21 @@ class Puppet::Node::Facts::InventoryActiveRecord < Puppet::Indirector::ActiveRec
end
end
- matching_hosts = hosts_matching_fact_filters(fact_filters) + hosts_matching_meta_filters(meta_filters)
+ matching_nodes = nodes_matching_fact_filters(fact_filters) + nodes_matching_meta_filters(meta_filters)
# to_a because [].inject == nil
- matching_hosts.inject {|hosts,this_set| hosts & this_set}.to_a.sort
+ matching_nodes.inject {|nodes,this_set| nodes & this_set}.to_a.sort
end
private
- def hosts_matching_fact_filters(fact_filters)
- host_sets = []
+ def nodes_matching_fact_filters(fact_filters)
+ node_sets = []
fact_filters['eq'].each do |name,value|
- host_sets << Puppet::Rails::InventoryHost.has_fact_with_value(name,value).map {|host| host.name}
+ node_sets << Puppet::Rails::InventoryNode.has_fact_with_value(name,value).map {|node| node.name}
end
fact_filters['ne'].each do |name,value|
- host_sets << Puppet::Rails::InventoryHost.has_fact_without_value(name,value).map {|host| host.name}
+ node_sets << Puppet::Rails::InventoryNode.has_fact_without_value(name,value).map {|node| node.name}
end
{
'gt' => '>',
@@ -69,15 +69,15 @@ class Puppet::Node::Facts::InventoryActiveRecord < Puppet::Indirector::ActiveRec
'le' => '<='
}.each do |operator_name,operator|
fact_filters[operator_name].each do |name,value|
- hosts_with_fact = Puppet::Rails::InventoryHost.has_fact(name)
- host_sets << hosts_with_fact.select {|h| h.value_for(name).to_f.send(operator, value.to_f)}.map {|host| host.name}
+ nodes_with_fact = Puppet::Rails::InventoryNode.has_fact(name)
+ node_sets << nodes_with_fact.select {|h| h.value_for(name).to_f.send(operator, value.to_f)}.map {|node| node.name}
end
end
- host_sets
+ node_sets
end
- def hosts_matching_meta_filters(meta_filters)
- host_sets = []
+ def nodes_matching_meta_filters(meta_filters)
+ node_sets = []
{
'eq' => '=',
'ne' => '!=',
@@ -87,9 +87,9 @@ class Puppet::Node::Facts::InventoryActiveRecord < Puppet::Indirector::ActiveRec
'le' => '<='
}.each do |operator_name,operator|
meta_filters[operator_name].each do |name,value|
- host_sets << Puppet::Rails::InventoryHost.find(:all, :conditions => ["timestamp #{operator} ?", value]).map {|host| host.name}
+ node_sets << Puppet::Rails::InventoryNode.find(:all, :conditions => ["timestamp #{operator} ?", value]).map {|node| node.name}
end
end
- host_sets
+ node_sets
end
end