summaryrefslogtreecommitdiffstats
path: root/lib/puppet/interface/catalog.rb
blob: defe321276f329125339ed0d3e62d9bc42b9b757 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
require 'puppet/interface/indirector'

Puppet::Interface::Indirector.interface(:catalog) do
  action(:apply) do
    invoke do |catalog|
      report = Puppet::Transaction::Report.new("apply")
      report.configuration_version = catalog.version

      Puppet::Util::Log.newdestination(report)

      begin
        benchmark(:notice, "Finished catalog run") do
          catalog.apply(:report => report)
        end
      rescue => detail
        puts detail.backtrace if Puppet[:trace]
        Puppet.err "Failed to apply catalog: #{detail}"
      end

      report.finalize_report
      report
    end
  end

  action(:download) do
    invoke do |certname,facts|
      Puppet::Resource::Catalog.terminus_class = :rest
      facts_to_upload = {:facts_format => :b64_zlib_yaml, :facts => CGI.escape(facts.render(:b64_zlib_yaml))}
      catalog = nil
      retrieval_duration = thinmark do
        catalog = Puppet::Interface.interface(:catalog).find(certname, facts_to_upload)
      end
      catalog = catalog.to_ral
      catalog.finalize
      catalog.retrieval_duration = retrieval_duration
      catalog.write_class_file
      catalog
    end
  end
end