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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
require 'puppet/indirector/face'
Puppet::Indirector::Face.define(:catalog, '0.0.1') do
copyright "Puppet Labs", 2011
license "Apache 2 license; see COPYING"
summary "Compile, save, view, and convert catalogs."
description <<-'EOT'
This subcommand deals with catalogs, which are compiled per-node artifacts
generated from a set of Puppet manifests. By default, it interacts with the
compiling subsystem and compiles a catalog using the default manifest and
`certname`, but you can change the source of the catalog with the
`--terminus` option. You can also choose to print any catalog in 'dot'
format (for easy graph viewing with OmniGraffle or Graphviz) with
'--render-as dot'.
EOT
short_description <<-'EOT'
This subcommand deals with catalogs, which are compiled per-node artifacts
generated from a set of Puppet manifests. By default, it interacts with the
compiling subsystem and compiles a catalog using the default manifest and
`certname`; use the `--terminus` option to change the source of the catalog.
EOT
get_action(:destroy).summary "Invalid for this subcommand."
get_action(:search).summary "Invalid for this subcommand."
find = get_action(:find)
find.summary "Retrieve the catalog for a node."
find.arguments "<certname>"
find.returns <<-'EOT'
A serialized catalog. When used from the Ruby API, returns a
Puppet::Resource::Catalog object.
EOT
action(:apply) do
summary "Find and apply a catalog."
description <<-'EOT'
Finds and applies a catalog. This action takes no arguments, but
the source of the catalog can be managed with the `--terminus` option.
EOT
returns <<-'EOT'
Nothing. When used from the Ruby API, returns a
Puppet::Transaction::Report object.
EOT
examples <<-'EOT'
Apply the locally cached catalog:
$ puppet catalog apply --terminus yaml
Retrieve a catalog from the master and apply it, in one step:
$ puppet catalog apply --terminus rest
From `secret_agent.rb` (API example):
# ...
Puppet::Face[:catalog, '0.0.1'].download
# (Termini are singletons; catalog.download has a side effect of
# setting the catalog terminus to yaml)
report = Puppet::Face[:catalog, '0.0.1'].apply
# ...
EOT
when_invoked do |options|
catalog = Puppet::Face[:catalog, "0.0.1"].find(Puppet[:certname]) or raise "Could not find catalog for #{Puppet[:certname]}"
catalog = catalog.to_ral
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
summary "Download this node's catalog from the puppet master server."
description <<-'EOT'
Retrieves a catalog from the puppet master and saves it to the local yaml
cache. This action always contacts the puppet master and will ignore
alternate termini.
The saved catalog can be used in any subsequent catalog action by specifying
'--terminus yaml' for that action.
EOT
returns "Nothing."
notes <<-'EOT'
When used from the Ruby API, this action has a side effect of leaving
Puppet::Resource::Catalog.indirection.terminus_class set to yaml. The
terminus must be explicitly re-set for subsequent catalog actions.
EOT
examples <<-'EOT'
Retrieve and store a catalog:
$ puppet catalog download
From `secret_agent.rb` (API example):
Puppet::Face[:plugin, '0.0.1'].download
Puppet::Face[:facts, '0.0.1'].upload
Puppet::Face[:catalog, '0.0.1'].download
# ...
EOT
when_invoked do |options|
Puppet::Resource::Catalog.indirection.terminus_class = :rest
Puppet::Resource::Catalog.indirection.cache_class = nil
catalog = nil
retrieval_duration = thinmark do
catalog = Puppet::Face[:catalog, '0.0.1'].find(Puppet[:certname])
end
catalog.retrieval_duration = retrieval_duration
catalog.write_class_file
Puppet::Resource::Catalog.indirection.terminus_class = :yaml
Puppet::Face[:catalog, "0.0.1"].save(catalog)
Puppet.notice "Saved catalog for #{Puppet[:certname]} to yaml"
nil
end
end
end
|