summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2007-09-21 15:49:25 -0500
committerLuke Kanies <luke@madstop.com>2007-09-21 15:49:25 -0500
commit02275f0b29cee70e3f02d6d8f911eaaf3fad579d (patch)
tree83e6aa336221432bc40eea72013cff4571bacd81 /lib
parentda0555d948b837e7c16bdca164780c9e71353e4a (diff)
downloadpuppet-02275f0b29cee70e3f02d6d8f911eaaf3fad579d.tar.gz
puppet-02275f0b29cee70e3f02d6d8f911eaaf3fad579d.tar.xz
puppet-02275f0b29cee70e3f02d6d8f911eaaf3fad579d.zip
Adding automatic association between terminus subclasses and
the indirection they're working with. It looks like I'll be moving terminus registration to the indirection rather than the top-level Indirector.
Diffstat (limited to 'lib')
-rw-r--r--lib/puppet/indirector/facts/yaml.rb41
-rw-r--r--lib/puppet/indirector/terminus.rb23
-rw-r--r--lib/puppet/indirector/yaml/facts.rb7
3 files changed, 30 insertions, 41 deletions
diff --git a/lib/puppet/indirector/facts/yaml.rb b/lib/puppet/indirector/facts/yaml.rb
deleted file mode 100644
index cb02f05c6..000000000
--- a/lib/puppet/indirector/facts/yaml.rb
+++ /dev/null
@@ -1,41 +0,0 @@
-Puppet::Indirector.register_terminus :facts, :yaml do
- desc "Store client facts as flat files, serialized using YAML."
-
- # Get a client's facts.
- def find(node)
- file = path(node)
-
- return nil unless FileTest.exists?(file)
-
- begin
- values = YAML::load(File.read(file))
- rescue => detail
- Puppet.err "Could not load facts for %s: %s" % [node, detail]
- end
-
- Puppet::Node::Facts.new(node, values)
- end
-
- def initialize
- Puppet.config.use(:yamlfacts)
- end
-
- # Store the facts to disk.
- def save(facts)
- File.open(path(facts.name), "w", 0600) do |f|
- begin
- f.print YAML::dump(facts.values)
- rescue => detail
- Puppet.err "Could not write facts for %s: %s" % [facts.name, detail]
- end
- end
- nil
- end
-
- private
-
- # Return the path to a given node's file.
- def path(name)
- File.join(Puppet[:yamlfactdir], name + ".yaml")
- end
-end
diff --git a/lib/puppet/indirector/terminus.rb b/lib/puppet/indirector/terminus.rb
index 4d550e9ba..a98f6dff0 100644
--- a/lib/puppet/indirector/terminus.rb
+++ b/lib/puppet/indirector/terminus.rb
@@ -20,6 +20,29 @@ class Puppet::Indirector::Terminus
raise ArgumentError, "Could not find indirection instance %s" % name
end
end
+
+ # Register our subclass with the appropriate indirection.
+ # This follows the convention that our terminus is named after the
+ # indirection.
+ def inherited(subclass)
+ longname = subclass.to_s
+ if longname =~ /#<Class/
+ raise ArgumentError, "Terminus subclasses must have associated constants"
+ end
+ names = longname.split("::")
+
+ # First figure out the indirection
+ shortname = names.pop.downcase.intern
+ subclass.indirection = shortname
+
+ if names.empty?
+ raise ArgumentError, "Terminus subclasses need to have their constants include the parent class for setting the terminus name"
+ end
+
+ # And then the name (e.g., ldap or yaml)
+ termtype = names.pop.downcase.intern
+ subclass.name = termtype
+ end
end
def initialize
diff --git a/lib/puppet/indirector/yaml/facts.rb b/lib/puppet/indirector/yaml/facts.rb
new file mode 100644
index 000000000..c09eaeab1
--- /dev/null
+++ b/lib/puppet/indirector/yaml/facts.rb
@@ -0,0 +1,7 @@
+require 'puppet/indirector/yaml'
+
+class Puppet::Indirector::Yaml::Facts < Puppet::Indirector::Yaml
+ desc "Store client facts as flat files, serialized using YAML."
+
+ register_terminus
+end