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