summaryrefslogtreecommitdiffstats
path: root/lib/puppet/network/handler
diff options
context:
space:
mode:
Diffstat (limited to 'lib/puppet/network/handler')
-rw-r--r--lib/puppet/network/handler/ca.rb2
-rw-r--r--lib/puppet/network/handler/configuration.rb14
-rwxr-xr-xlib/puppet/network/handler/facts.rb68
-rwxr-xr-xlib/puppet/network/handler/filebucket.rb2
-rwxr-xr-xlib/puppet/network/handler/fileserver.rb15
-rw-r--r--lib/puppet/network/handler/master.rb9
-rw-r--r--lib/puppet/network/handler/node.rb242
-rwxr-xr-xlib/puppet/network/handler/report.rb4
-rwxr-xr-xlib/puppet/network/handler/resource.rb13
-rwxr-xr-xlib/puppet/network/handler/runner.rb4
10 files changed, 18 insertions, 355 deletions
diff --git a/lib/puppet/network/handler/ca.rb b/lib/puppet/network/handler/ca.rb
index 422b21ae1..052eb5c19 100644
--- a/lib/puppet/network/handler/ca.rb
+++ b/lib/puppet/network/handler/ca.rb
@@ -60,7 +60,7 @@ class Puppet::Network::Handler
end
def initialize(hash = {})
- Puppet.config.use(:main, :ssl, :ca)
+ Puppet.settings.use(:main, :ssl, :ca)
if hash.include? :autosign
@autosign = hash[:autosign]
end
diff --git a/lib/puppet/network/handler/configuration.rb b/lib/puppet/network/handler/configuration.rb
index 2c72d3d2b..2df1b3ab4 100644
--- a/lib/puppet/network/handler/configuration.rb
+++ b/lib/puppet/network/handler/configuration.rb
@@ -30,7 +30,7 @@ class Puppet::Network::Handler
# Note that this is reasonable, because either their node source should actually
# know about the node, or they should be using the ``none`` node source, which
# will always return data.
- unless node = node_handler.details(key)
+ unless node = Puppet::Node.search(key)
raise Puppet::Error, "Could not find node '%s'" % key
end
@@ -64,7 +64,7 @@ class Puppet::Network::Handler
# Return the configuration version.
def version(client = nil, clientip = nil)
- if client and node = node_handler.details(client)
+ if client and node = Puppet::Node.search(client)
update_node_check(node)
return interpreter.configuration_version(node)
else
@@ -79,7 +79,7 @@ class Puppet::Network::Handler
# Add any extra data necessary to the node.
def add_node_data(node)
# Merge in our server-side facts, so they can be used during compilation.
- node.fact_merge(@server_facts)
+ node.merge(@server_facts)
# Add any specified classes to the node's class list.
if classes = @options[:Classes]
@@ -159,14 +159,6 @@ class Puppet::Network::Handler
@interpreter
end
- # Create a node handler instance for looking up our nodes.
- def node_handler
- unless defined?(@node_handler)
- @node_handler = Puppet::Network::Handler.handler(:node).create
- end
- @node_handler
- end
-
# Initialize our server fact hash; we add these to each client, and they
# won't change while we're running, so it's safe to cache the values.
def set_server_facts
diff --git a/lib/puppet/network/handler/facts.rb b/lib/puppet/network/handler/facts.rb
deleted file mode 100755
index 4767e8be4..000000000
--- a/lib/puppet/network/handler/facts.rb
+++ /dev/null
@@ -1,68 +0,0 @@
-require 'yaml'
-require 'puppet/util/fact_store'
-
-class Puppet::Network::Handler
- # Receive logs from remote hosts.
- class Facts < Handler
- desc "An interface for storing and retrieving client facts. Currently only
- used internally by Puppet."
-
- @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
diff --git a/lib/puppet/network/handler/filebucket.rb b/lib/puppet/network/handler/filebucket.rb
index bb6a0e6d3..1bf8da854 100755
--- a/lib/puppet/network/handler/filebucket.rb
+++ b/lib/puppet/network/handler/filebucket.rb
@@ -64,7 +64,7 @@ class Puppet::Network::Handler # :nodoc:
end
end
- Puppet.config.use(:filebucket)
+ Puppet.settings.use(:filebucket)
@name = "Filebucket[#{@path}]"
end
diff --git a/lib/puppet/network/handler/fileserver.rb b/lib/puppet/network/handler/fileserver.rb
index a429412d2..ae0e6553d 100755
--- a/lib/puppet/network/handler/fileserver.rb
+++ b/lib/puppet/network/handler/fileserver.rb
@@ -243,7 +243,10 @@ class Puppet::Network::Handler
# the modules.
def modules_mount(module_name, client)
# Find our environment, if we have one.
- if node = node_handler.details(client || Facter.value("hostname"))
+ unless hostname = (client || Facter.value("hostname"))
+ raise ArgumentError, "Could not find hostname"
+ end
+ if node = Puppet::Node.find(hostname)
env = node.environment
else
env = nil
@@ -258,14 +261,6 @@ class Puppet::Network::Handler
end
end
- # Create a node handler instance for looking up our nodes.
- def node_handler
- unless defined?(@node_handler)
- @node_handler = Puppet::Network::Handler.handler(:node).create
- end
- @node_handler
- end
-
# Read the configuration file.
def readconfig(check = true)
return if @noreadconfig
@@ -455,7 +450,7 @@ class Puppet::Network::Handler
def getfileobject(dir, links)
unless FileTest.exists?(dir)
- self.notice "File source %s does not exist" % dir
+ self.debug "File source %s does not exist" % dir
return nil
end
diff --git a/lib/puppet/network/handler/master.rb b/lib/puppet/network/handler/master.rb
index c8db277ba..030950c61 100644
--- a/lib/puppet/network/handler/master.rb
+++ b/lib/puppet/network/handler/master.rb
@@ -74,7 +74,7 @@ class Puppet::Network::Handler
client, clientip = clientname(client, clientip, facts)
# Pass the facts to the fact handler
- fact_handler.set(client, facts)
+ Puppet::Node::Facts.new(client, facts).save
# And get the configuration from the config handler
begin
@@ -134,13 +134,6 @@ class Puppet::Network::Handler
return facts
end
- def fact_handler
- unless defined? @fact_handler
- @fact_handler = Puppet::Network::Handler.handler(:facts).new :local => local?
- end
- @fact_handler
- end
-
# Translate our configuration appropriately for sending back to a client.
def translate(config)
if local?
diff --git a/lib/puppet/network/handler/node.rb b/lib/puppet/network/handler/node.rb
deleted file mode 100644
index c6ccc2eb6..000000000
--- a/lib/puppet/network/handler/node.rb
+++ /dev/null
@@ -1,242 +0,0 @@
-# Created by Luke A. Kanies on 2007-08-13.
-# Copyright (c) 2007. All rights reserved.
-
-require 'puppet/util'
-require 'puppet/node'
-require 'puppet/util/classgen'
-require 'puppet/util/instance_loader'
-
-# Look up a node, along with all the details about it.
-class Puppet::Network::Handler::Node < Puppet::Network::Handler
- desc "Retrieve information about nodes."
-
- # Create a singleton node handler
- def self.create
- unless @handler
- @handler = new
- end
- @handler
- end
-
- # Add a new node source.
- def self.newnode_source(name, options = {}, &block)
- name = symbolize(name)
-
- fact_merge = options[:fact_merge]
- mod = genmodule(name, :extend => SourceBase, :hash => instance_hash(:node_source), :block => block)
- mod.send(:define_method, :fact_merge?) do
- fact_merge
- end
- mod
- end
-
- # Collect the docs for all of our node sources.
- def self.node_source_docs
- docs = ""
-
- # Use this method so they all get loaded
- instance_loader(:node_source).loadall
- loaded_instances(:node_source).sort { |a,b| a.to_s <=> b.to_s }.each do |name|
- mod = self.node_source(name)
- docs += "%s\n%s\n" % [name, "-" * name.to_s.length]
-
- docs += Puppet::Util::Docs.scrub(mod.doc) + "\n\n"
- end
-
- docs
- end
-
- # List each of the node sources.
- def self.node_sources
- instance_loader(:node_source).loadall
- loaded_instances(:node_source)
- end
-
- # Remove a defined node source; basically only used for testing.
- def self.rm_node_source(name)
- rmclass(name, :hash => instance_hash(:node_source))
- end
-
- extend Puppet::Util::ClassGen
- extend Puppet::Util::InstanceLoader
-
- # A simple base module we can use for modifying how our node sources work.
- module SourceBase
- include Puppet::Util::Docs
- end
-
- @interface = XMLRPC::Service::Interface.new("nodes") { |iface|
- iface.add_method("string details(key)")
- iface.add_method("string parameters(key)")
- iface.add_method("string environment(key)")
- iface.add_method("string classes(key)")
- }
-
- # Set up autoloading and retrieving of reports.
- instance_load :node_source, 'puppet/node_source'
-
- attr_reader :source
-
- # Return a given node's classes.
- def classes(key)
- if node = details(key)
- node.classes
- else
- nil
- end
- end
-
- # Return an entire node configuration. This uses the 'nodesearch' method
- # defined in the node_source to look for the node.
- def details(key, client = nil, clientip = nil)
- return nil unless key
- if node = cached?(key)
- return node
- end
- facts = node_facts(key)
- node = nil
- names = node_names(key, facts)
- names.each do |name|
- name = name.to_s if name.is_a?(Symbol)
- if node = nodesearch(name) and @source != "none"
- Puppet.info "Found %s in %s" % [name, @source]
- break
- end
- end
-
- # If they made it this far, we haven't found anything, so look for a
- # default node.
- unless node or names.include?("default")
- if node = nodesearch("default")
- Puppet.notice "Using default node for %s" % key
- end
- end
-
- if node
- node.source = @source
- node.names = names
-
- # Merge the facts into the parameters.
- if fact_merge?
- node.fact_merge(facts)
- end
-
- cache(node)
-
- return node
- else
- return nil
- end
- end
-
- # Return a given node's environment.
- def environment(key, client = nil, clientip = nil)
- if node = details(key)
- node.environment
- else
- nil
- end
- end
-
- # Create our node lookup tool.
- def initialize(hash = {})
- @source = hash[:Source] || Puppet[:node_source]
-
- unless mod = self.class.node_source(@source)
- raise ArgumentError, "Unknown node source '%s'" % @source
- end
-
- extend(mod)
-
- super
-
- # We cache node info for speed
- @node_cache = {}
- end
-
- # Try to retrieve a given node's parameters.
- def parameters(key, client = nil, clientip = nil)
- if node = details(key)
- node.parameters
- else
- nil
- end
- end
-
- private
-
- # Store the node to make things a bit faster.
- def cache(node)
- @node_cache[node.name] = node
- end
-
- # If the node is cached, return it.
- def cached?(name)
- # Don't use cache when the filetimeout is set to 0
- return false if [0, "0"].include?(Puppet[:filetimeout])
-
- if node = @node_cache[name] and Time.now - node.time < Puppet[:filetimeout]
- return node
- else
- return false
- end
- end
-
- # Create/cache a fact handler.
- def fact_handler
- unless defined?(@fact_handler)
- @fact_handler = Puppet::Network::Handler.handler(:facts).new
- end
- @fact_handler
- end
-
- # Short-hand for creating a new node, so the node sources don't need to
- # specify the constant.
- def newnode(options)
- Puppet::Node.new(options)
- end
-
- # Look up the node facts from our fact handler.
- def node_facts(key)
- if facts = fact_handler.get(key)
- facts
- else
- {}
- end
- end
-
- # Calculate the list of node names we should use for looking
- # up our node.
- def node_names(key, facts = nil)
- facts ||= node_facts(key)
- names = []
-
- if hostname = facts["hostname"]
- unless hostname == key
- names << hostname
- end
- else
- hostname = key
- end
-
- if fqdn = facts["fqdn"]
- hostname = fqdn
- names << fqdn
- end
-
- # Make sure both the fqdn and the short name of the
- # host can be used in the manifest
- if hostname =~ /\./
- names << hostname.sub(/\..+/,'')
- elsif domain = facts['domain']
- names << hostname + "." + domain
- end
-
- # Sort the names inversely by name length.
- names.sort! { |a,b| b.length <=> a.length }
-
- # And make sure the key is first, since that's the most
- # likely usage.
- ([key] + names).uniq
- end
-end
diff --git a/lib/puppet/network/handler/report.rb b/lib/puppet/network/handler/report.rb
index 81aee6a3c..62e9cfdec 100755
--- a/lib/puppet/network/handler/report.rb
+++ b/lib/puppet/network/handler/report.rb
@@ -71,8 +71,8 @@ class Puppet::Network::Handler
def initialize(*args)
super
- Puppet.config.use(:reporting)
- Puppet.config.use(:metrics)
+ Puppet.settings.use(:reporting)
+ Puppet.settings.use(:metrics)
end
# Accept a report from a client.
diff --git a/lib/puppet/network/handler/resource.rb b/lib/puppet/network/handler/resource.rb
index ac29dce53..7709b85fe 100755
--- a/lib/puppet/network/handler/resource.rb
+++ b/lib/puppet/network/handler/resource.rb
@@ -39,21 +39,14 @@ class Puppet::Network::Handler
end
end
- component = bucket.to_type
-
- # Create a client, but specify the remote machine as the server
- # because the class requires it, even though it's unused
- client = Puppet::Network::Client.client(:Master).new(:Master => client||"localhost")
-
- # Set the objects
- client.objects = component
+ config = bucket.to_configuration
# And then apply the configuration. This way we're reusing all
# the code in there. It should probably just be separated out, though.
- transaction = client.apply
+ transaction = config.apply
# And then clean up
- component.remove
+ config.clear(true)
# It'd be nice to return some kind of report, but... at this point
# we have no such facility.
diff --git a/lib/puppet/network/handler/runner.rb b/lib/puppet/network/handler/runner.rb
index c41e83608..4b9ccab75 100755
--- a/lib/puppet/network/handler/runner.rb
+++ b/lib/puppet/network/handler/runner.rb
@@ -50,10 +50,10 @@ class Puppet::Network::Handler
# And then we need to tell it to run, with this extra info.
if fg
- master.run(tags, ignoreschedules)
+ master.run(:tags => tags, :ignoreschedules => ignoreschedules)
else
Puppet.newthread do
- master.run(tags, ignoreschedules)
+ master.run(:tags => tags, :ignoreschedules => ignoreschedules)
end
end