summaryrefslogtreecommitdiffstats
path: root/lib/puppet/network/handler
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2007-05-03 05:24:13 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2007-05-03 05:24:13 +0000
commit8d7ec14836809f1433e645c3069691d2f6c70e52 (patch)
tree185c06aaaade8fd87b863755eb911a3fde50821a /lib/puppet/network/handler
parent79dcd33aebf8749719e9eff009b8bb3fdaf77751 (diff)
downloadpuppet-8d7ec14836809f1433e645c3069691d2f6c70e52.tar.gz
puppet-8d7ec14836809f1433e645c3069691d2f6c70e52.tar.xz
puppet-8d7ec14836809f1433e645c3069691d2f6c70e52.zip
Adding a fact handler, along with an abstract interface for fact stores and a simple yaml fact store, towards the Node Classification work.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2457 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/puppet/network/handler')
-rwxr-xr-xlib/puppet/network/handler/facts.rb67
1 files changed, 67 insertions, 0 deletions
diff --git a/lib/puppet/network/handler/facts.rb b/lib/puppet/network/handler/facts.rb
new file mode 100755
index 000000000..46c94b91a
--- /dev/null
+++ b/lib/puppet/network/handler/facts.rb
@@ -0,0 +1,67 @@
+require 'yaml'
+require 'puppet/util/fact_store'
+
+class Puppet::Network::Handler
+ # Receive logs from remote hosts.
+ class Facts < Handler
+ @interface = XMLRPC::Service::Interface.new("facts") { |iface|
+ iface.add_method("void set(string, string)")
+ iface.add_method("string get(string)")
+ iface.add_method("integer store_date(string)")
+ }
+
+ def initialize(hash = {})
+ super
+
+ backend = Puppet[:factstore]
+
+ unless klass = Puppet::Util::FactStore.store(backend)
+ raise Puppet::Error, "Could not find fact store %s" % backend
+ end
+
+ @backend = klass.new
+ end
+
+ # Get the facts from our back end.
+ def get(node)
+ if facts = @backend.get(node)
+ return strip_internal(facts)
+ else
+ return nil
+ end
+ end
+
+ # Set the facts in the backend.
+ def set(node, facts)
+ @backend.set(node, add_internal(facts))
+ nil
+ end
+
+ # Retrieve a client's storage date.
+ def store_date(node)
+ if facts = get(node)
+ facts[:_puppet_timestamp].to_i
+ else
+ nil
+ end
+ end
+
+ private
+
+ # Add internal data to the facts for storage.
+ def add_internal(facts)
+ facts = facts.dup
+ facts[:_puppet_timestamp] = Time.now
+ facts
+ end
+
+ # Strip out that internal data.
+ def strip_internal(facts)
+ facts = facts.dup
+ facts.find_all { |name, value| name.to_s =~ /^_puppet_/ }.each { |name, value| facts.delete(name) }
+ facts
+ end
+ end
+end
+
+# $Id$