quixoten-puppetdb-terminus 2.2.2 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/puppet/face/storeconfigs.rb +140 -125
- data/lib/puppet/indirector/catalog/puppetdb.rb +28 -19
- data/lib/puppet/indirector/facts/puppetdb.rb +16 -10
- data/lib/puppet/indirector/resource/puppetdb.rb +8 -4
- data/lib/puppet/reports/puppetdb.rb +7 -4
- data/lib/puppet/util/puppetdb.rb +15 -3
- data/lib/puppet/util/puppetdb/command.rb +2 -2
- data/lib/puppetdb/terminus/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6e3b2b250c00a29b9a6e5bbf6c9bb0db86f73f48
|
4
|
+
data.tar.gz: 71047b96882f6cf0d0bc39117397b7db246febeb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 77faccae995c706fa21fa042ea54c7f90eb1fd31f189784aafd4ad15f5d0f7f4276018f562ae974ac9c53ee54fdca9ec1dded6d50a2d870d44be55751b34eb40
|
7
|
+
data.tar.gz: 2aa8fee0becb8e40daba485dbe4d9e327168b1b2734056194d71f30dfc48d10dd86882b7fbf174174a002aa9ad3645db4e7b6cd863cd17d63bed1c61d55459d7
|
@@ -1,177 +1,192 @@
|
|
1
|
+
require 'puppet/util/puppetdb'
|
1
2
|
require 'puppet/face'
|
2
|
-
require 'tmpdir'
|
3
3
|
|
4
|
-
Puppet::
|
5
|
-
|
6
|
-
license "Apache 2 license"
|
4
|
+
if Puppet::Util::Puppetdb.puppet3compat?
|
5
|
+
require 'tmpdir'
|
7
6
|
|
8
|
-
|
9
|
-
|
7
|
+
Puppet::Face.define(:storeconfigs, '0.0.1') do
|
8
|
+
copyright "Puppet Labs", 2011
|
9
|
+
license "Apache 2 license"
|
10
|
+
|
11
|
+
summary "Interact with the storeconfigs database"
|
12
|
+
description <<-DESC
|
10
13
|
This subcommand interacts with the ActiveRecord storeconfigs database, and
|
11
14
|
can be used to export a dump of that data which is suitable for import by
|
12
15
|
PuppetDB.
|
13
16
|
DESC
|
14
17
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
+
action :export do
|
19
|
+
summary "Export the storeconfigs database"
|
20
|
+
description <<-DESC
|
18
21
|
Generate a dump of all catalogs from the storeconfigs database, as a
|
19
22
|
tarball which can be imported by PuppetDB. Only exported resources are
|
20
23
|
included; non-exported resources, edges, facts, or other data are
|
21
24
|
omitted. Returns the location of the output.
|
22
25
|
DESC
|
23
26
|
|
24
|
-
|
27
|
+
when_invoked do |options|
|
25
28
|
|
26
|
-
|
29
|
+
require 'puppet/rails'
|
27
30
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
+
tmpdir = Dir.mktmpdir
|
32
|
+
workdir = File.join(tmpdir, 'puppetdb-bak')
|
33
|
+
Dir.mkdir(workdir)
|
31
34
|
|
32
|
-
|
33
|
-
|
35
|
+
begin
|
36
|
+
Puppet::Rails.connect
|
34
37
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
+
# Fetch all nodes, including exported resources and their params
|
39
|
+
nodes = Puppet::Rails::Host.all(:include => {:resources => [:param_values, :puppet_tags]},
|
40
|
+
:conditions => {:resources => {:exported => true}})
|
38
41
|
|
39
|
-
|
42
|
+
catalogs = nodes.map { |node| node_to_catalog_hash(node) }
|
40
43
|
|
41
|
-
|
42
|
-
|
44
|
+
catalog_dir = File.join(workdir, 'catalogs')
|
45
|
+
FileUtils.mkdir(catalog_dir)
|
43
46
|
|
44
|
-
|
45
|
-
|
47
|
+
catalogs.each do |catalog|
|
48
|
+
filename = File.join(catalog_dir, "#{catalog[:data][:name]}.json")
|
46
49
|
|
47
|
-
|
48
|
-
|
50
|
+
File.open(filename, 'w') do |file|
|
51
|
+
file.puts catalog.to_pson
|
52
|
+
end
|
49
53
|
end
|
50
|
-
end
|
51
54
|
|
52
|
-
|
55
|
+
node_names = nodes.map(&:name).sort
|
53
56
|
|
54
|
-
|
57
|
+
timestamp = Time.now
|
55
58
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
59
|
+
File.open(File.join(workdir, 'export-metadata.json'), 'w') do |file|
|
60
|
+
metadata = {
|
61
|
+
'timestamp' => timestamp,
|
62
|
+
'command-versions' => {
|
63
|
+
'replace-catalog' => 2,
|
64
|
+
}
|
61
65
|
}
|
62
|
-
}
|
63
66
|
|
64
|
-
|
65
|
-
|
67
|
+
file.puts metadata.to_pson
|
68
|
+
end
|
66
69
|
|
67
|
-
|
70
|
+
tarfile = destination_file(timestamp)
|
68
71
|
|
69
|
-
|
70
|
-
|
72
|
+
if tar = Puppet::Util.which('tar')
|
73
|
+
execute("cd #{tmpdir} && #{tar} -cf #{tarfile} puppetdb-bak")
|
71
74
|
|
72
|
-
|
75
|
+
FileUtils.rm_rf(workdir)
|
73
76
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
+
if gzip = Puppet::Util.which('gzip')
|
78
|
+
execute("#{gzip} #{tarfile}")
|
79
|
+
"#{tarfile}.gz"
|
80
|
+
else
|
81
|
+
Puppet.warning "Can't find the `gzip` command to compress the tarball; output will not be compressed"
|
82
|
+
tarfile
|
83
|
+
end
|
77
84
|
else
|
78
|
-
Puppet.warning "Can't find the `
|
79
|
-
|
85
|
+
Puppet.warning "Can't find the `tar` command to produce a tarball; output will remain in the temporary working directory"
|
86
|
+
workdir
|
80
87
|
end
|
81
|
-
|
82
|
-
|
83
|
-
|
88
|
+
rescue => e
|
89
|
+
# Clean up if something goes wrong. We don't want to ensure this,
|
90
|
+
# because we want the directory to stick around in the case where they
|
91
|
+
# don't have tar.
|
92
|
+
FileUtils.rm_rf(workdir)
|
93
|
+
raise
|
84
94
|
end
|
85
|
-
rescue => e
|
86
|
-
# Clean up if something goes wrong. We don't want to ensure this,
|
87
|
-
# because we want the directory to stick around in the case where they
|
88
|
-
# don't have tar.
|
89
|
-
FileUtils.rm_rf(workdir)
|
90
|
-
raise
|
91
95
|
end
|
92
|
-
end
|
93
96
|
|
94
|
-
|
95
|
-
|
97
|
+
when_rendering :console do |filename|
|
98
|
+
"Exported storeconfigs data to #{filename}"
|
99
|
+
end
|
96
100
|
end
|
97
|
-
end
|
98
101
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
102
|
+
# Returns the location to leave the output. This is really only here for testing. :/
|
103
|
+
def destination_file(timestamp)
|
104
|
+
File.expand_path("storeconfigs-#{timestamp.strftime('%Y%m%d%H%M%S')}.tar")
|
105
|
+
end
|
103
106
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
107
|
+
# Execute a command using Puppet's execution static method.
|
108
|
+
#
|
109
|
+
# @param command [Array<String>, String] the command to execute. If it is
|
110
|
+
# an Array the first element should be the executable and the rest of the
|
111
|
+
# elements should be the individual arguments to that executable.
|
112
|
+
# @return [Puppet::Util::Execution::ProcessOutput] output as specified by options
|
113
|
+
# @raise [Puppet::ExecutionFailure] if the executed chiled process did not exit with status == 0 and `failonfail` is
|
114
|
+
# `true`.
|
115
|
+
def execute(command)
|
116
|
+
Puppet::Util::Execution.execute(command)
|
117
|
+
end
|
115
118
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
119
|
+
def node_to_catalog_hash(node)
|
120
|
+
resources = node.resources.map { |resource| resource_to_hash(resource) }
|
121
|
+
edges = node.resources.map { |resource| resource_to_edge_hash(resource) }
|
122
|
+
|
123
|
+
{
|
124
|
+
:metadata => {
|
125
|
+
:api_version => 1,
|
126
|
+
},
|
127
|
+
:data => {
|
128
|
+
:name => node.name,
|
129
|
+
:version => node.last_compile || Time.now,
|
130
|
+
:edges => edges,
|
131
|
+
:resources => resources + [stage_main_hash],
|
132
|
+
},
|
133
|
+
}
|
134
|
+
end
|
132
135
|
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
136
|
+
def resource_to_hash(resource)
|
137
|
+
parameters = resource.param_values.inject({}) do |params,param_value|
|
138
|
+
if params.has_key?(param_value.param_name.name)
|
139
|
+
value = [params[param_value.param_name.name],param_value.value].flatten
|
140
|
+
else
|
141
|
+
value = param_value.value
|
142
|
+
end
|
143
|
+
params.merge(param_value.param_name.name => value)
|
139
144
|
end
|
140
|
-
params.merge(param_value.param_name.name => value)
|
141
|
-
end
|
142
145
|
|
143
|
-
|
146
|
+
tags = resource.puppet_tags.map(&:name).uniq.sort
|
144
147
|
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
148
|
+
hash = {
|
149
|
+
:type => resource.restype,
|
150
|
+
:title => resource.title,
|
151
|
+
:exported => true,
|
152
|
+
:parameters => parameters,
|
153
|
+
:tags => tags,
|
154
|
+
}
|
152
155
|
|
153
|
-
|
154
|
-
|
156
|
+
hash[:file] = resource.file if resource.file
|
157
|
+
hash[:line] = resource.line if resource.line
|
155
158
|
|
156
|
-
|
157
|
-
|
159
|
+
hash
|
160
|
+
end
|
161
|
+
|
162
|
+
# The catalog *must* have edges, so everything is contained by Stage[main]!
|
163
|
+
def resource_to_edge_hash(resource)
|
164
|
+
{
|
165
|
+
'source' => {'type' => 'Stage', 'title' => 'main'},
|
166
|
+
'target' => {'type' => resource.restype, 'title' => resource.title},
|
167
|
+
'relationship' => 'contains',
|
168
|
+
}
|
169
|
+
end
|
158
170
|
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
171
|
+
def stage_main_hash
|
172
|
+
{
|
173
|
+
:type => 'Stage',
|
174
|
+
:title => 'main',
|
175
|
+
:exported => false,
|
176
|
+
:parameters => {},
|
177
|
+
:tags => ['stage', 'main'],
|
178
|
+
}
|
179
|
+
end
|
166
180
|
end
|
181
|
+
else
|
182
|
+
Puppet::Face.define(:storeconfigs, '0.0.1') do
|
183
|
+
copyright "Puppet Labs", 2011
|
184
|
+
license "Apache 2 license"
|
167
185
|
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
:parameters => {},
|
174
|
-
:tags => ['stage', 'main'],
|
175
|
-
}
|
186
|
+
summary "storeconfigs is not supported on Puppet 4.0.0+"
|
187
|
+
description <<-DESC
|
188
|
+
Users needing this feature should migrate using Puppet 3.7.2 or a more recent
|
189
|
+
3.7 release.
|
190
|
+
DESC
|
176
191
|
end
|
177
192
|
end
|
@@ -8,7 +8,7 @@ class Puppet::Resource::Catalog::Puppetdb < Puppet::Indirector::REST
|
|
8
8
|
include Puppet::Util::Puppetdb::CommandNames
|
9
9
|
|
10
10
|
def save(request)
|
11
|
-
profile
|
11
|
+
profile("catalog#save", [:puppetdb, :catalog, :save, request.key]) do
|
12
12
|
catalog = munge_catalog(request.instance, extract_extra_request_data(request))
|
13
13
|
submit_command(request.key, catalog, CommandReplaceCatalog, 5)
|
14
14
|
end
|
@@ -28,13 +28,11 @@ class Puppet::Resource::Catalog::Puppetdb < Puppet::Indirector::REST
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def munge_catalog(catalog, extra_request_data = {})
|
31
|
-
profile
|
32
|
-
|
33
|
-
catalog.
|
31
|
+
profile("Munge catalog", [:puppetdb, :catalog, :munge]) do
|
32
|
+
data = profile("Convert catalog to JSON data hash", [:puppetdb, :catalog, :convert_to_hash]) do
|
33
|
+
catalog.to_data_hash
|
34
34
|
end
|
35
35
|
|
36
|
-
data = hash['data']
|
37
|
-
|
38
36
|
add_parameters_if_missing(data)
|
39
37
|
add_namevar_aliases(data, catalog)
|
40
38
|
stringify_titles(data)
|
@@ -111,7 +109,8 @@ class Puppet::Resource::Catalog::Puppetdb < Puppet::Indirector::REST
|
|
111
109
|
|
112
110
|
def stringify_titles(hash)
|
113
111
|
resources = hash['resources']
|
114
|
-
profile
|
112
|
+
profile("Stringify titles (resource count: #{resources.count})",
|
113
|
+
[:puppetdb, :titles, :stringify]) do
|
115
114
|
resources.each do |resource|
|
116
115
|
resource['title'] = resource['title'].to_s
|
117
116
|
end
|
@@ -122,7 +121,8 @@ class Puppet::Resource::Catalog::Puppetdb < Puppet::Indirector::REST
|
|
122
121
|
|
123
122
|
def add_parameters_if_missing(hash)
|
124
123
|
resources = hash['resources']
|
125
|
-
profile
|
124
|
+
profile("Add parameters if missing (resource count: #{resources.count})",
|
125
|
+
[:puppetdb, :parameters, :add_missing]) do
|
126
126
|
resources.each do |resource|
|
127
127
|
resource['parameters'] ||= {}
|
128
128
|
end
|
@@ -133,7 +133,8 @@ class Puppet::Resource::Catalog::Puppetdb < Puppet::Indirector::REST
|
|
133
133
|
|
134
134
|
def add_namevar_aliases(hash, catalog)
|
135
135
|
resources = hash['resources']
|
136
|
-
profile
|
136
|
+
profile("Add namevar aliases (resource count: #{resources.count})",
|
137
|
+
[:puppetdb, :namevar_aliases, :add]) do
|
137
138
|
resources.each do |resource|
|
138
139
|
real_resource = catalog.resource(resource['type'], resource['title'])
|
139
140
|
|
@@ -175,7 +176,8 @@ class Puppet::Resource::Catalog::Puppetdb < Puppet::Indirector::REST
|
|
175
176
|
|
176
177
|
def sort_unordered_metaparams(hash)
|
177
178
|
resources = hash['resources']
|
178
|
-
profile
|
179
|
+
profile("Sort unordered metaparams (resource count: #{resources.count})",
|
180
|
+
[:puppetdb, :metaparams, :sort]) do
|
179
181
|
resources.each do |resource|
|
180
182
|
params = resource['parameters']
|
181
183
|
UnorderedMetaparams.each do |metaparam|
|
@@ -192,7 +194,8 @@ class Puppet::Resource::Catalog::Puppetdb < Puppet::Indirector::REST
|
|
192
194
|
|
193
195
|
def munge_edges(hash)
|
194
196
|
edges = hash['edges']
|
195
|
-
profile
|
197
|
+
profile("Munge edges (edge count: #{edges.count})",
|
198
|
+
[:puppetdb, :edges, :munge]) do
|
196
199
|
edges.each do |edge|
|
197
200
|
%w[source target].each do |vertex|
|
198
201
|
edge[vertex] = resource_ref_to_hash(edge[vertex]) if edge[vertex].is_a?(String)
|
@@ -208,7 +211,8 @@ class Puppet::Resource::Catalog::Puppetdb < Puppet::Indirector::REST
|
|
208
211
|
resources = hash['resources']
|
209
212
|
aliases = {}
|
210
213
|
|
211
|
-
profile
|
214
|
+
profile("Map aliases to title (resource count: #{resources.count})",
|
215
|
+
[:puppetdb, :aliases, :map_to_title]) do
|
212
216
|
resources.each do |resource|
|
213
217
|
names = resource['parameters']['alias'] || []
|
214
218
|
resource_hash = {'type' => resource['type'], 'title' => resource['title']}
|
@@ -223,23 +227,26 @@ class Puppet::Resource::Catalog::Puppetdb < Puppet::Indirector::REST
|
|
223
227
|
end
|
224
228
|
|
225
229
|
def synthesize_edges(hash, catalog)
|
226
|
-
profile
|
230
|
+
profile("Synthesize edges",
|
231
|
+
[:puppetdb, :edges, :synthesize]) do
|
227
232
|
aliases = map_aliases_to_title(hash)
|
228
233
|
|
229
234
|
resource_table = {}
|
230
|
-
profile
|
235
|
+
profile("Build up resource_table",
|
236
|
+
[:puppetdb, :edges, :synthesize, :resource_table, :build]) do
|
231
237
|
hash['resources'].each do |resource|
|
232
238
|
resource_table[ [resource['type'], resource['title']] ] = resource
|
233
239
|
end
|
234
240
|
end
|
235
241
|
|
236
|
-
profile
|
242
|
+
profile("Primary synthesis",
|
243
|
+
[:puppetdb, :edges, :synthesize, :primary_synthesis])do
|
237
244
|
hash['resources'].each do |resource|
|
238
245
|
# Standard virtual resources don't appear in the catalog. However,
|
239
246
|
# exported resources which haven't been also collected will appears as
|
240
247
|
# exported and virtual (collected ones will only be exported). They will
|
241
248
|
# eventually be removed from the catalog, so we can't add edges involving
|
242
|
-
# them. Puppet::Resource#
|
249
|
+
# them. Puppet::Resource#to_data_hash omits 'virtual', so we have to
|
243
250
|
# look it up in the catalog to find that information. This isn't done in
|
244
251
|
# a separate step because we don't actually want to send the field (it
|
245
252
|
# will always be false). See ticket #16472.
|
@@ -266,7 +273,7 @@ class Puppet::Resource::Catalog::Puppetdb < Puppet::Indirector::REST
|
|
266
273
|
# case problem here: http://projects.puppetlabs.com/issues/19474
|
267
274
|
# Once that problem is solved and older versions of Puppet that have
|
268
275
|
# the bug are no longer supported we can probably remove this code.
|
269
|
-
unless other_ref =~ /^[A-Z][a-z0-9_]*(::[A-Z][a-z0-9_]*)*\[.*\]/
|
276
|
+
unless other_ref =~ /^[A-Z][a-z0-9_-]*(::[A-Z][a-z0-9_-]*)*\[.*\]/
|
270
277
|
rel = edge_to_s(resource_hash_to_ref(resource_hash), other_ref, param)
|
271
278
|
raise Puppet::Error, "Invalid relationship: #{rel}, because " +
|
272
279
|
"#{other_ref} doesn't seem to be in the correct format. " +
|
@@ -328,7 +335,8 @@ class Puppet::Resource::Catalog::Puppetdb < Puppet::Indirector::REST
|
|
328
335
|
end
|
329
336
|
end
|
330
337
|
|
331
|
-
profile
|
338
|
+
profile("Make edges unique",
|
339
|
+
[:puppetdb, :edges, :synthesize, :make_unique]) do
|
332
340
|
hash['edges'].uniq!
|
333
341
|
end
|
334
342
|
|
@@ -337,7 +345,8 @@ class Puppet::Resource::Catalog::Puppetdb < Puppet::Indirector::REST
|
|
337
345
|
end
|
338
346
|
|
339
347
|
def filter_keys(hash)
|
340
|
-
profile
|
348
|
+
profile("Filter extraneous keys from the catalog",
|
349
|
+
[:puppetdb, :keys, :filter_extraneous]) do
|
341
350
|
hash.delete_if do |k,v|
|
342
351
|
! ['name', 'version', 'edges', 'resources'].include?(k)
|
343
352
|
end
|
@@ -17,11 +17,13 @@ class Puppet::Node::Facts::Puppetdb < Puppet::Indirector::REST
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def save(request)
|
20
|
-
profile
|
21
|
-
payload = profile
|
20
|
+
profile("facts#save", [:puppetdb, :facts, :save, request.key]) do
|
21
|
+
payload = profile("Encode facts command submission payload",
|
22
|
+
[:puppetdb, :facts, :encode]) do
|
22
23
|
facts = request.instance.dup
|
23
|
-
facts.values = facts.strip_internal
|
24
|
-
|
24
|
+
facts.values = facts.strip_internal.dup
|
25
|
+
|
26
|
+
if ! Puppet::Util::Puppetdb.puppet3compat? || Puppet[:trusted_node_data]
|
25
27
|
facts.values[:trusted] = get_trusted_info(request.node)
|
26
28
|
end
|
27
29
|
{
|
@@ -40,16 +42,18 @@ class Puppet::Node::Facts::Puppetdb < Puppet::Indirector::REST
|
|
40
42
|
end
|
41
43
|
|
42
44
|
def find(request)
|
43
|
-
profile
|
45
|
+
profile("facts#find", [:puppetdb, :facts, :find, request.key]) do
|
44
46
|
begin
|
45
47
|
url = Puppet::Util::Puppetdb.url_path("/v3/nodes/#{CGI.escape(request.key)}/facts")
|
46
|
-
response = profile
|
48
|
+
response = profile("Query for nodes facts: #{url}",
|
49
|
+
[:puppetdb, :facts, :find, :query_nodes, request.key]) do
|
47
50
|
http_get(request, url, headers)
|
48
51
|
end
|
49
52
|
log_x_deprecation_header(response)
|
50
53
|
|
51
54
|
if response.is_a? Net::HTTPSuccess
|
52
|
-
profile
|
55
|
+
profile("Parse fact query response (size: #{response.body.size})",
|
56
|
+
[:puppetdb, :facts, :find, :parse_response, request.key]) do
|
53
57
|
result = JSON.parse(response.body)
|
54
58
|
# Note: the Inventory Service API appears to expect us to return nil here
|
55
59
|
# if the node isn't found. However, PuppetDB returns an empty array in
|
@@ -87,7 +91,7 @@ class Puppet::Node::Facts::Puppetdb < Puppet::Indirector::REST
|
|
87
91
|
# `operator` may be one of {eq, ne, lt, gt, le, ge}, and will default to 'eq'
|
88
92
|
# if unspecified.
|
89
93
|
def search(request)
|
90
|
-
profile
|
94
|
+
profile("facts#search", [:puppetdb, :facts, :search, request.key]) do
|
91
95
|
return [] unless request.options
|
92
96
|
operator_map = {
|
93
97
|
'eq' => '=',
|
@@ -112,13 +116,15 @@ class Puppet::Node::Facts::Puppetdb < Puppet::Indirector::REST
|
|
112
116
|
|
113
117
|
begin
|
114
118
|
url = Puppet::Util::Puppetdb.url_path("/v3/nodes?query=#{query_param}")
|
115
|
-
response = profile
|
119
|
+
response = profile("Fact query request: #{URI.unescape(url)}",
|
120
|
+
[:puppetdb, :facts, :search, :query_request, request.key]) do
|
116
121
|
http_get(request, url, headers)
|
117
122
|
end
|
118
123
|
log_x_deprecation_header(response)
|
119
124
|
|
120
125
|
if response.is_a? Net::HTTPSuccess
|
121
|
-
profile
|
126
|
+
profile("Parse fact query response (size: #{response.body.size})",
|
127
|
+
[:puppetdb, :facts, :search, :parse_query_response, request.key,]) do
|
122
128
|
JSON.parse(response.body).collect {|s| s["name"]}
|
123
129
|
end
|
124
130
|
else
|
@@ -7,7 +7,8 @@ class Puppet::Resource::Puppetdb < Puppet::Indirector::REST
|
|
7
7
|
include Puppet::Util::Puppetdb
|
8
8
|
|
9
9
|
def search(request)
|
10
|
-
profile
|
10
|
+
profile("resource#search",
|
11
|
+
[:puppetdb, :resource, :search, request.key]) do
|
11
12
|
type = request.key
|
12
13
|
host = request.options[:host]
|
13
14
|
filter = request.options[:filter]
|
@@ -27,7 +28,8 @@ class Puppet::Resource::Puppetdb < Puppet::Indirector::REST
|
|
27
28
|
|
28
29
|
begin
|
29
30
|
url = Puppet::Util::Puppetdb.url_path("/v3/resources?query=#{query_param}")
|
30
|
-
response = profile
|
31
|
+
response = profile("Resources query: #{URI.unescape(url)}",
|
32
|
+
[:puppetdb, :resource, :search, :query, request.key]) do
|
31
33
|
http_get(request, url, headers)
|
32
34
|
end
|
33
35
|
log_x_deprecation_header(response)
|
@@ -40,11 +42,13 @@ class Puppet::Resource::Puppetdb < Puppet::Indirector::REST
|
|
40
42
|
raise Puppet::Error, "Could not retrieve resources from the PuppetDB at #{self.class.server}:#{self.class.port}: #{e}"
|
41
43
|
end
|
42
44
|
|
43
|
-
resources = profile
|
45
|
+
resources = profile("Parse resource query response (size: #{response.body.size})",
|
46
|
+
[:puppetdb, :resource, :search, :parse_query_response, request.key]) do
|
44
47
|
JSON.load(response.body)
|
45
48
|
end
|
46
49
|
|
47
|
-
profile
|
50
|
+
profile("Build up collected resource objects (count: #{resources.count})",
|
51
|
+
[:puppetdb, :resource, :search, :build_up_collected_objects, request.key]) do
|
48
52
|
resources.map do |res|
|
49
53
|
params = res['parameters'] || {}
|
50
54
|
params = params.map do |name,value|
|
@@ -18,7 +18,7 @@ Puppet::Reports.register_report(:puppetdb) do
|
|
18
18
|
#
|
19
19
|
# @return [void]
|
20
20
|
def process
|
21
|
-
profile
|
21
|
+
profile("report#process", [:puppetdb, :report, :process]) do
|
22
22
|
submit_command(self.host, report_to_hash, CommandStoreReport, 4)
|
23
23
|
end
|
24
24
|
|
@@ -31,7 +31,8 @@ Puppet::Reports.register_report(:puppetdb) do
|
|
31
31
|
# @return Hash[<String, Object>]
|
32
32
|
# @api private
|
33
33
|
def report_to_hash
|
34
|
-
profile
|
34
|
+
profile("Convert report to wire format hash",
|
35
|
+
[:puppetdb, :report, :convert_to_wire_format_hash]) do
|
35
36
|
if environment.nil?
|
36
37
|
raise Puppet::Error, "Environment is nil, unable to submit report. This may be due a bug with Puppet. Ensure you are running the latest revision, see PUP-2508 for more details."
|
37
38
|
end
|
@@ -54,7 +55,8 @@ Puppet::Reports.register_report(:puppetdb) do
|
|
54
55
|
# @return Array[Hash]
|
55
56
|
# @api private
|
56
57
|
def build_events_list
|
57
|
-
profile
|
58
|
+
profile("Build events list (count: #{resource_statuses.count})",
|
59
|
+
[:puppetdb, :events_list, :build]) do
|
58
60
|
filter_events(resource_statuses.inject([]) do |events, status_entry|
|
59
61
|
_, status = *status_entry
|
60
62
|
if ! (status.events.empty?)
|
@@ -133,7 +135,8 @@ Puppet::Reports.register_report(:puppetdb) do
|
|
133
135
|
# @api private
|
134
136
|
def filter_events(events)
|
135
137
|
if config.ignore_blacklisted_events?
|
136
|
-
profile
|
138
|
+
profile("Filter blacklisted events",
|
139
|
+
[:puppetdb, :events, :filter_blacklisted]) do
|
137
140
|
events.select { |e| ! config.is_event_blacklisted?(e) }
|
138
141
|
end
|
139
142
|
else
|
data/lib/puppet/util/puppetdb.rb
CHANGED
@@ -30,6 +30,10 @@ module Puppet::Util::Puppetdb
|
|
30
30
|
@config
|
31
31
|
end
|
32
32
|
|
33
|
+
def self.puppet3compat?
|
34
|
+
defined?(Puppet::Parser::AST::HashOrArrayAccess)
|
35
|
+
end
|
36
|
+
|
33
37
|
# This magical stuff is needed so that the indirector termini will make requests to
|
34
38
|
# the correct host/port, because this module gets mixed in to our indirector
|
35
39
|
# termini.
|
@@ -76,7 +80,8 @@ module Puppet::Util::Puppetdb
|
|
76
80
|
# @param version [Number] version number of command
|
77
81
|
# @return [Hash <String, String>]
|
78
82
|
def submit_command(certname, payload, command_name, version)
|
79
|
-
profile
|
83
|
+
profile("Submitted command '#{command_name}' version '#{version}'",
|
84
|
+
[:puppetdb, :command, :submit, command_name, version]) do
|
80
85
|
command = Puppet::Util::Puppetdb::Command.new(command_name, version, certname, payload)
|
81
86
|
command.submit
|
82
87
|
end
|
@@ -90,11 +95,18 @@ module Puppet::Util::Puppetdb
|
|
90
95
|
# in the profiled hierachy.
|
91
96
|
#
|
92
97
|
# @param message [String] A description of the profiled event
|
98
|
+
# @param metric_id [Array] A list of strings making up the ID of a metric to profile
|
93
99
|
# @param block [Block] The segment of code to profile
|
94
100
|
# @api public
|
95
|
-
def profile(message, &block)
|
101
|
+
def profile(message, metric_id, &block)
|
96
102
|
message = "PuppetDB: " + message
|
97
|
-
Puppet::Util::Profiler.profile
|
103
|
+
arity = Puppet::Util::Profiler.method(:profile).arity
|
104
|
+
case arity
|
105
|
+
when 1
|
106
|
+
Puppet::Util::Profiler.profile(message, &block)
|
107
|
+
when 2, -2
|
108
|
+
Puppet::Util::Profiler.profile(message, metric_id, &block)
|
109
|
+
end
|
98
110
|
end
|
99
111
|
|
100
112
|
# @!group Private instance methods
|
@@ -27,7 +27,7 @@ class Puppet::Util::Puppetdb::Command
|
|
27
27
|
@command = command
|
28
28
|
@version = version
|
29
29
|
@certname = certname
|
30
|
-
profile
|
30
|
+
profile("Format payload", [:puppetdb, :payload, :format]) do
|
31
31
|
@payload = self.class.format_payload(command, version, payload)
|
32
32
|
end
|
33
33
|
end
|
@@ -43,7 +43,7 @@ class Puppet::Util::Puppetdb::Command
|
|
43
43
|
for_whom = " for #{certname}" if certname
|
44
44
|
|
45
45
|
begin
|
46
|
-
response = profile
|
46
|
+
response = profile("Submit command HTTP post", [:puppetdb, :command, :submit]) do
|
47
47
|
http = Puppet::Network::HttpPool.http_instance(config.server, config.port)
|
48
48
|
http.post(Puppet::Util::Puppetdb.url_path(CommandsUrl + "?checksum=#{checksum}"),
|
49
49
|
payload, headers)
|