summaryrefslogtreecommitdiffstats
path: root/lib/puppet/agent/downloader.rb
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-07-15 23:05:45 -0500
committerLuke Kanies <luke@madstop.com>2009-02-06 18:08:39 -0600
commit25b28c58c22bae718794dc679f10c61665af0b15 (patch)
tree8d8ebf094326f99dd3a9f7cfac7c329831f402c7 /lib/puppet/agent/downloader.rb
parent1afb8216f166dc375dec5778890985a6635aa54f (diff)
downloadpuppet-25b28c58c22bae718794dc679f10c61665af0b15.tar.gz
puppet-25b28c58c22bae718794dc679f10c61665af0b15.tar.xz
puppet-25b28c58c22bae718794dc679f10c61665af0b15.zip
Adding a new Agent::Downloader class for downloading files.
This will handling downloading facts and plugins. Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'lib/puppet/agent/downloader.rb')
-rw-r--r--lib/puppet/agent/downloader.rb78
1 files changed, 78 insertions, 0 deletions
diff --git a/lib/puppet/agent/downloader.rb b/lib/puppet/agent/downloader.rb
new file mode 100644
index 000000000..46a64d52d
--- /dev/null
+++ b/lib/puppet/agent/downloader.rb
@@ -0,0 +1,78 @@
+require 'puppet/agent'
+
+class Puppet::Agent::Downloader
+ attr_reader :name, :path, :source, :ignore
+
+ # Determine the timeout value to use.
+ def self.timeout
+ timeout = Puppet[:configtimeout]
+ case timeout
+ when String:
+ if timeout =~ /^\d+$/
+ timeout = Integer(timeout)
+ else
+ raise ArgumentError, "Configuration timeout must be an integer"
+ end
+ when Integer: # nothing
+ else
+ raise ArgumentError, "Configuration timeout must be an integer"
+ end
+
+ return timeout
+ end
+
+ # Evaluate our download, returning the list of changed values.
+ def evaluate
+ Puppet.info "Retrieving #{name}"
+
+ files = []
+ begin
+ Timeout.timeout(self.class.timeout) do
+ catalog.apply do |trans|
+ trans.changed?.find_all do |resource|
+ yield resource if block_given?
+ files << resource[:path]
+ end
+ end
+ end
+ rescue Puppet::Error, Timeout::Error => detail
+ puts detail.backtrace if Puppet[:debug]
+ Puppet.err "Could not retrieve #{name}: %s" % detail
+ end
+
+ return files
+ end
+
+ def initialize(name, path, source, ignore = nil)
+ @name, @path, @source, @ignore = name, path, source, ignore
+ end
+
+ def catalog
+ catalog = Puppet::Node::Catalog.new
+ catalog.add_resource(file)
+ catalog
+ end
+
+ def file
+ args = default_arguments.merge(:path => path, :source => source)
+ args[:ignore] = ignore if ignore
+ Puppet::Type.type(:file).create(args)
+ end
+
+ private
+
+ def default_arguments
+ {
+ :path => path,
+ :recurse => true,
+ :source => source,
+ :tag => name,
+ :owner => Process.uid,
+ :group => Process.gid,
+ :purge => true,
+ :force => true,
+ :backup => false,
+ :noop => false
+ }
+ end
+end