diff options
| author | Luke Kanies <luke@madstop.com> | 2007-08-26 19:03:25 -0500 |
|---|---|---|
| committer | Luke Kanies <luke@madstop.com> | 2007-08-26 19:03:25 -0500 |
| commit | 9ea8e6cc8772053548d3438393dd1ead986ed719 (patch) | |
| tree | ff97f65095d4b5b516dd800dd6197638787cc4dd /lib/puppet/network/handler | |
| parent | 51ff72c42447e5b9e05db3b24530a4e628454396 (diff) | |
| download | puppet-9ea8e6cc8772053548d3438393dd1ead986ed719.tar.gz puppet-9ea8e6cc8772053548d3438393dd1ead986ed719.tar.xz puppet-9ea8e6cc8772053548d3438393dd1ead986ed719.zip | |
The fileserver now uses an environment-specific module path. I also made various bug fixes around the network tree.
Diffstat (limited to 'lib/puppet/network/handler')
| -rw-r--r-- | lib/puppet/network/handler/configuration.rb | 14 | ||||
| -rwxr-xr-x | lib/puppet/network/handler/fileserver.rb | 42 | ||||
| -rw-r--r-- | lib/puppet/network/handler/master.rb | 1 | ||||
| -rw-r--r-- | lib/puppet/network/handler/node.rb | 15 |
4 files changed, 54 insertions, 18 deletions
diff --git a/lib/puppet/network/handler/configuration.rb b/lib/puppet/network/handler/configuration.rb index a1b22207e..fd1ee86ed 100644 --- a/lib/puppet/network/handler/configuration.rb +++ b/lib/puppet/network/handler/configuration.rb @@ -57,17 +57,13 @@ class Puppet::Network::Handler # Return the configuration version. def version(client = nil, clientip = nil) - if client - if node = node_handler.details(client) - update_node_check(node) - return interpreter.configuration_version(node) - else - raise Puppet::Error, "Could not find node '%s'" % client - end + if client and node = node_handler.details(client) + update_node_check(node) + return interpreter.configuration_version(node) else # Just return something that will always result in a recompile, because # this is local. - return 0 + return (Time.now + 1000).to_i end end @@ -153,7 +149,7 @@ class Puppet::Network::Handler # Create a node handler instance for looking up our nodes. def node_handler unless defined?(@node_handler) - @node_handler = Puppet::Network::Handler.handler(:node).new + @node_handler = Puppet::Network::Handler.handler(:node).create end @node_handler end diff --git a/lib/puppet/network/handler/fileserver.rb b/lib/puppet/network/handler/fileserver.rb index fdf515d6e..a429412d2 100755 --- a/lib/puppet/network/handler/fileserver.rb +++ b/lib/puppet/network/handler/fileserver.rb @@ -239,6 +239,33 @@ class Puppet::Network::Handler return children end + # Return the mount for the Puppet modules; allows file copying from + # the modules. + def modules_mount(module_name, client) + # Find our environment, if we have one. + if node = node_handler.details(client || Facter.value("hostname")) + env = node.environment + else + env = nil + end + + # And use the environment to look up the module. + mod = Puppet::Module::find(module_name, env) + if mod + return @mounts[MODULES].copy(mod.name, mod.files) + else + return nil + 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 @@ -388,15 +415,12 @@ class Puppet::Network::Handler mount = nil path = nil if dir =~ %r{/([-\w]+)/?} - tmp = $1 - path = dir.sub(%r{/#{tmp}/?}, '') + # Strip off the mount name. + mount_name, path = dir.sub(%r{^/}, '').split(File::Separator, 2) - mod = Puppet::Module::find(tmp) - if mod - mount = @mounts[MODULES].copy(mod.name, mod.files) - else - unless mount = @mounts[tmp] - raise FileServerError, "Fileserver module '%s' not mounted" % tmp + unless mount = modules_mount(mount_name, client) + unless mount = @mounts[mount_name] + raise FileServerError, "Fileserver module '%s' not mounted" % mount_name end end else @@ -405,7 +429,7 @@ class Puppet::Network::Handler if path == "" path = nil - else + elsif path # Remove any double slashes that might have occurred path = URI.unescape(path.gsub(/\/\//, "/")) end diff --git a/lib/puppet/network/handler/master.rb b/lib/puppet/network/handler/master.rb index 0cab94f69..e5bfa8122 100644 --- a/lib/puppet/network/handler/master.rb +++ b/lib/puppet/network/handler/master.rb @@ -23,6 +23,7 @@ class Puppet::Network::Handler # Tell a client whether there's a fresh config for it def freshness(client = nil, clientip = nil) + client ||= Facter.value("hostname") config_handler.version(client, clientip) end diff --git a/lib/puppet/network/handler/node.rb b/lib/puppet/network/handler/node.rb index 2c4d3e1b5..bf2424b18 100644 --- a/lib/puppet/network/handler/node.rb +++ b/lib/puppet/network/handler/node.rb @@ -10,6 +10,14 @@ require 'puppet/util/instance_loader' 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) @@ -81,6 +89,10 @@ class Puppet::Network::Handler::Node < Puppet::Network::Handler # 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) @@ -108,6 +120,9 @@ class Puppet::Network::Handler::Node < Puppet::Network::Handler if fact_merge? node.fact_merge(facts) end + + cache(node) + return node else return nil |
