Class: Puppet::Configurer::Downloader

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet/configurer/downloader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, path, source, ignore = nil, environment = nil, source_permissions = :ignore) ⇒ Downloader

Returns a new instance of Downloader.



28
29
30
# File 'lib/puppet/configurer/downloader.rb', line 28

def initialize(name, path, source, ignore = nil, environment = nil, source_permissions = :ignore)
  @name, @path, @source, @ignore, @environment, @source_permissions = name, path, source, ignore, environment, source_permissions
end

Instance Attribute Details

#ignoreObject (readonly)



5
6
7
# File 'lib/puppet/configurer/downloader.rb', line 5

def ignore
  @ignore
end

#nameObject (readonly)



5
6
7
# File 'lib/puppet/configurer/downloader.rb', line 5

def name
  @name
end

#pathObject (readonly)



5
6
7
# File 'lib/puppet/configurer/downloader.rb', line 5

def path
  @path
end

#sourceObject (readonly)



5
6
7
# File 'lib/puppet/configurer/downloader.rb', line 5

def source
  @source
end

Instance Method Details

#catalogObject



32
33
34
35
36
37
# File 'lib/puppet/configurer/downloader.rb', line 32

def catalog
  catalog = Puppet::Resource::Catalog.new("PluginSync", @environment)
  catalog.host_config = false
  catalog.add_resource(file)
  catalog
end

#evaluateObject

Evaluate our download, returning the list of changed values.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/puppet/configurer/downloader.rb', line 8

def evaluate
  Puppet.info "Retrieving #{name}"

  files = []
  begin
    ::Timeout.timeout(Puppet[:configtimeout]) 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
    Puppet.log_exception(detail, "Could not retrieve #{name}: #{detail}")
  end

  files
end

#fileObject



39
40
41
42
43
# File 'lib/puppet/configurer/downloader.rb', line 39

def file
  args = default_arguments.merge(:path => path, :source => source)
  args[:ignore] = ignore.split if ignore
  Puppet::Type.type(:file).new(args)
end