module Puppet::Configurer::FactHandler
Break out the code related to facts. This module is just included into the agent, but having it here makes it easier to test.
Public Instance Methods
encode_facts(facts)
click to toggle source
# File lib/puppet/configurer/fact_handler.rb 34 def encode_facts(facts) 35 #facts = find_facts 36 37 # NOTE: :facts specified as parameters are URI encoded here, 38 # then encoded for a second time depending on their length: 39 # 40 # <= 1024 characters sent via query string of a HTTP GET, additionally query string encoded 41 # > 1024 characters sent in POST data, additionally x-www-form-urlencoded 42 # so it's only important that encoding method here return original values 43 # correctly when CGI.unescape called against it (in compiler code) 44 if Puppet[:preferred_serialization_format] == "pson" 45 {:facts_format => :pson, :facts => Puppet::Util.uri_query_encode(facts.render(:pson)) } 46 else 47 {:facts_format => 'application/json', :facts => Puppet::Util.uri_query_encode(facts.render(:json)) } 48 end 49 end
facts_for_uploading()
click to toggle source
# File lib/puppet/configurer/fact_handler.rb 30 def facts_for_uploading 31 encode_facts(find_facts) 32 end
find_facts()
click to toggle source
# File lib/puppet/configurer/fact_handler.rb 10 def find_facts 11 # This works because puppet agent configures Facts to use 'facter' for 12 # finding facts and the 'rest' terminus for caching them. Thus, we'll 13 # compile them and then "cache" them on the server. 14 begin 15 facts = Puppet::Node::Facts.indirection.find(Puppet[:node_name_value], :environment => Puppet::Node::Environment.remote(@environment)) 16 unless Puppet[:node_name_fact].empty? 17 Puppet[:node_name_value] = facts.values[Puppet[:node_name_fact]] 18 facts.name = Puppet[:node_name_value] 19 end 20 facts 21 rescue SystemExit,NoMemoryError 22 raise 23 rescue Exception => detail 24 message = _("Could not retrieve local facts: %{detail}") % { detail: detail } 25 Puppet.log_exception(detail, message) 26 raise Puppet::Error, message, detail.backtrace 27 end 28 end