quixoten-puppetdb-terminus 2.0.0 → 2.1.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/puppet/face/node/status.rb +1 -1
- data/lib/puppet/indirector/facts/puppetdb.rb +3 -3
- data/lib/puppet/indirector/resource/puppetdb.rb +1 -1
- data/lib/puppet/reports/puppetdb.rb +55 -90
- data/lib/puppet/util/puppetdb/command.rb +3 -2
- data/lib/puppet/util/puppetdb/config.rb +18 -1
- data/lib/puppet/util/puppetdb.rb +8 -0
- data/lib/puppetdb/terminus/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6ec041c3332210b8491e8e7867f4a7c1b08e3c9d
|
4
|
+
data.tar.gz: a8ad9e389b33309ecd2b99e25b987283d0d84739
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e4d435e16b3d6aec80101b8020fce096b8f639056139f046d570bdbd1617ced6d79d2c1dde2c95597b0766db092bffb9932fc2321f7e370e115a884b10ab21fe
|
7
|
+
data.tar.gz: 39df67b4547a42b34c1af11429b64f9b587d767d2b9e5a51f70769972d4d41f22c4ffc1eedf946e32fafe083e72d20487c012bc6297c1ef6ae5f86801d994bb0
|
@@ -26,7 +26,7 @@ Puppet::Face.define(:node, '0.0.1') do
|
|
26
26
|
|
27
27
|
args.map do |node|
|
28
28
|
begin
|
29
|
-
response = http.get("/v3/nodes/#{CGI.escape(node)}", headers)
|
29
|
+
response = http.get(Puppet::Util::Puppetdb.url_path("/v3/nodes/#{CGI.escape(node)}"), headers)
|
30
30
|
if response.is_a? Net::HTTPSuccess
|
31
31
|
result = JSON.parse(response.body)
|
32
32
|
elsif response.is_a? Net::HTTPNotFound
|
@@ -17,7 +17,7 @@ class Puppet::Node::Facts::Puppetdb < Puppet::Indirector::REST
|
|
17
17
|
profile "facts#save" do
|
18
18
|
payload = profile "Encode facts command submission payload" do
|
19
19
|
facts = request.instance.dup
|
20
|
-
facts.values = facts.
|
20
|
+
facts.values = facts.strip_internal
|
21
21
|
facts.stringify
|
22
22
|
{
|
23
23
|
"name" => facts.name,
|
@@ -36,7 +36,7 @@ class Puppet::Node::Facts::Puppetdb < Puppet::Indirector::REST
|
|
36
36
|
def find(request)
|
37
37
|
profile "facts#find" do
|
38
38
|
begin
|
39
|
-
url = "/v3/nodes/#{CGI.escape(request.key)}/facts"
|
39
|
+
url = Puppet::Util::Puppetdb.url_path("/v3/nodes/#{CGI.escape(request.key)}/facts")
|
40
40
|
response = profile "Query for nodes facts: #{url}" do
|
41
41
|
http_get(request, url, headers)
|
42
42
|
end
|
@@ -105,7 +105,7 @@ class Puppet::Node::Facts::Puppetdb < Puppet::Indirector::REST
|
|
105
105
|
query_param = CGI.escape(query.to_json)
|
106
106
|
|
107
107
|
begin
|
108
|
-
url = "/v3/nodes?query=#{query_param}"
|
108
|
+
url = Puppet::Util::Puppetdb.url_path("/v3/nodes?query=#{query_param}")
|
109
109
|
response = profile "Fact query request: #{URI.unescape(url)}" do
|
110
110
|
http_get(request, url, headers)
|
111
111
|
end
|
@@ -31,7 +31,7 @@ class Puppet::Resource::Puppetdb < Puppet::Indirector::REST
|
|
31
31
|
query_param = CGI.escape(expr.to_json)
|
32
32
|
|
33
33
|
begin
|
34
|
-
url = "/v3/resources?query=#{query_param}"
|
34
|
+
url = Puppet::Util::Puppetdb.url_path("/v3/resources?query=#{query_param}")
|
35
35
|
response = profile "Resources query: #{URI.unescape(url)}" do
|
36
36
|
http_get(request, url, headers)
|
37
37
|
end
|
@@ -15,52 +15,45 @@ Puppet::Reports.register_report(:puppetdb) do
|
|
15
15
|
command.
|
16
16
|
DESC
|
17
17
|
|
18
|
-
|
18
|
+
# Process the report by formatting it into a PuppetDB 'store report'
|
19
|
+
# command and submitting it.
|
20
|
+
#
|
21
|
+
# @return [void]
|
19
22
|
def process
|
20
23
|
profile "report#process" do
|
21
|
-
submit_command(self.host, report_to_hash, CommandStoreReport,
|
24
|
+
submit_command(self.host, report_to_hash, CommandStoreReport, 4)
|
22
25
|
end
|
23
|
-
end
|
24
26
|
|
25
|
-
|
26
|
-
# report_format directly as instance variables. I've filed the following
|
27
|
-
# ticket / pull req against puppet to expose them via accessors, which
|
28
|
-
# seems more consistent and safer for the long-term. However, for reasons
|
29
|
-
# relating to backwards compatibility we won't be able to switch over to
|
30
|
-
# the accessors until version 3.x of puppet is our oldest supported version.
|
31
|
-
#
|
32
|
-
# This was resolved in puppet 3.x via ticket #16139 (puppet pull request #1073).
|
33
|
-
|
34
|
-
# @api private
|
35
|
-
def report_format
|
36
|
-
@report_format
|
37
|
-
end
|
38
|
-
|
39
|
-
# @api private
|
40
|
-
def puppet_version
|
41
|
-
@puppet_version
|
27
|
+
nil
|
42
28
|
end
|
43
29
|
|
44
30
|
# Convert `self` (an instance of `Puppet::Transaction::Report`) to a hash
|
45
31
|
# suitable for sending over the wire to PuppetDB
|
46
32
|
#
|
33
|
+
# @return Hash[<String, Object>]
|
47
34
|
# @api private
|
48
35
|
def report_to_hash
|
49
36
|
profile "Convert report to wire format hash" do
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
37
|
+
if environment.nil?
|
38
|
+
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."
|
39
|
+
end
|
40
|
+
|
41
|
+
{
|
42
|
+
"certname" => host,
|
43
|
+
"puppet-version" => puppet_version,
|
44
|
+
"report-format" => report_format,
|
45
|
+
"configuration-version" => configuration_version.to_s,
|
46
|
+
"start-time" => Puppet::Util::Puppetdb.to_wire_time(time),
|
47
|
+
"end-time" => Puppet::Util::Puppetdb.to_wire_time(time + run_duration),
|
48
|
+
"resource-events" => build_events_list,
|
49
|
+
"environment" => environment,
|
50
|
+
"transaction-uuid" => transaction_uuid,
|
51
|
+
"status" => status,
|
52
|
+
}
|
61
53
|
end
|
62
54
|
end
|
63
55
|
|
56
|
+
# @return Array[Hash]
|
64
57
|
# @api private
|
65
58
|
def build_events_list
|
66
59
|
profile "Build events list (count: #{resource_statuses.count})" do
|
@@ -70,19 +63,13 @@ Puppet::Reports.register_report(:puppetdb) do
|
|
70
63
|
events.concat(status.events.map { |event| event_to_hash(status, event) })
|
71
64
|
elsif status.skipped
|
72
65
|
events.concat([fabricate_event(status, "skipped")])
|
73
|
-
elsif status.failed
|
74
|
-
# PP-254:
|
75
|
-
# We have to fabricate resource events here due to a bug/s in report providers
|
76
|
-
# that causes them not to include events on a resource status that has failed.
|
77
|
-
# When PuppetDB is able to make a hard break from older version of Puppet that
|
78
|
-
# have this bug, we can remove this behavior.
|
79
|
-
events.concat([fabricate_event(status, "failure")])
|
80
66
|
end
|
81
67
|
events
|
82
68
|
end)
|
83
69
|
end
|
84
70
|
end
|
85
71
|
|
72
|
+
# @return Number
|
86
73
|
# @api private
|
87
74
|
def run_duration
|
88
75
|
# TODO: this is wrong in puppet. I am consistently seeing reports where
|
@@ -97,71 +84,49 @@ Puppet::Reports.register_report(:puppetdb) do
|
|
97
84
|
if metrics["time"] and metrics["time"]["total"]
|
98
85
|
metrics["time"]["total"]
|
99
86
|
else
|
100
|
-
|
87
|
+
0
|
101
88
|
end
|
102
89
|
end
|
103
90
|
|
104
91
|
# Convert an instance of `Puppet::Transaction::Event` to a hash
|
105
92
|
# suitable for sending over the wire to PuppetDB
|
106
93
|
#
|
94
|
+
# @return Hash[<String, Object>]
|
107
95
|
# @api private
|
108
96
|
def event_to_hash(resource_status, event)
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
97
|
+
{
|
98
|
+
"status" => event.status,
|
99
|
+
"timestamp" => Puppet::Util::Puppetdb.to_wire_time(event.time),
|
100
|
+
"resource-type" => resource_status.resource_type,
|
101
|
+
"resource-title" => resource_status.title.to_s,
|
102
|
+
"property" => event.property,
|
103
|
+
"new-value" => event.desired_value,
|
104
|
+
"old-value" => event.previous_value,
|
105
|
+
"message" => event.message,
|
106
|
+
"file" => resource_status.file,
|
107
|
+
"line" => resource_status.line,
|
108
|
+
"containment-path" => resource_status.containment_path,
|
109
|
+
}
|
122
110
|
end
|
123
111
|
|
124
|
-
# Given an instance of `Puppet::Resource::Status` and a status
|
125
|
-
# this method fabricates a PuppetDB event object with the
|
126
|
-
# `"status"`.
|
112
|
+
# Given an instance of `Puppet::Resource::Status` and a status
|
113
|
+
# string, this method fabricates a PuppetDB event object with the
|
114
|
+
# provided `"status"`.
|
127
115
|
#
|
128
116
|
# @api private
|
129
117
|
def fabricate_event(resource_status, event_status)
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
})
|
143
|
-
end
|
144
|
-
|
145
|
-
# Backwards compatibility with versions of Puppet prior to report format 4
|
146
|
-
#
|
147
|
-
# @api private
|
148
|
-
def add_v4_fields_to_report(report_hash)
|
149
|
-
if report_format >= 4
|
150
|
-
report_hash.merge("transaction-uuid" => transaction_uuid)
|
151
|
-
else
|
152
|
-
report_hash.merge("transaction-uuid" => nil)
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
# Backwards compatibility with versions of Puppet prior to report format 4
|
157
|
-
#
|
158
|
-
# @api private
|
159
|
-
def add_v4_fields_to_event(resource_status, event_hash)
|
160
|
-
if report_format >= 4
|
161
|
-
event_hash.merge("containment-path" => resource_status.containment_path)
|
162
|
-
else
|
163
|
-
event_hash.merge("containment-path" => nil)
|
164
|
-
end
|
118
|
+
{
|
119
|
+
"status" => event_status,
|
120
|
+
"timestamp" => Puppet::Util::Puppetdb.to_wire_time(resource_status.time),
|
121
|
+
"resource-type" => resource_status.resource_type,
|
122
|
+
"resource-title" => resource_status.title.to_s,
|
123
|
+
"property" => nil,
|
124
|
+
"new-value" => nil,
|
125
|
+
"old-value" => nil,
|
126
|
+
"message" => nil,
|
127
|
+
"file" => resource_status.file,
|
128
|
+
"line" => resource_status.line,
|
129
|
+
}
|
165
130
|
end
|
166
131
|
|
167
132
|
# Filter out blacklisted events, if we're configured to do so
|
@@ -9,7 +9,7 @@ class Puppet::Util::Puppetdb::Command
|
|
9
9
|
include Puppet::Util::Puppetdb
|
10
10
|
include Puppet::Util::Puppetdb::CommandNames
|
11
11
|
|
12
|
-
|
12
|
+
CommandsUrl = "/v3/commands"
|
13
13
|
|
14
14
|
# Public instance methods
|
15
15
|
|
@@ -45,7 +45,8 @@ class Puppet::Util::Puppetdb::Command
|
|
45
45
|
begin
|
46
46
|
response = profile "Submit command HTTP post" do
|
47
47
|
http = Puppet::Network::HttpPool.http_instance(config.server, config.port)
|
48
|
-
http.post(
|
48
|
+
http.post(Puppet::Util::Puppetdb.url_path(CommandsUrl + "?checksum=#{checksum}"),
|
49
|
+
payload, headers)
|
49
50
|
end
|
50
51
|
|
51
52
|
Puppet::Util::Puppetdb.log_x_deprecation_header(response)
|
@@ -11,6 +11,7 @@ class Config
|
|
11
11
|
defaults = {
|
12
12
|
:server => "puppetdb",
|
13
13
|
:port => 8081,
|
14
|
+
:url_prefix => "",
|
14
15
|
:soft_write_failure => false,
|
15
16
|
:ignore_blacklisted_events => true,
|
16
17
|
}
|
@@ -52,11 +53,12 @@ class Config
|
|
52
53
|
main_section = main_section.inject({}) {|h, (k,v)| h[k.to_sym] = v ; h}
|
53
54
|
# merge with defaults but filter out anything except the legal settings
|
54
55
|
config_hash = defaults.merge(main_section).reject do |k, v|
|
55
|
-
!([:server, :port, :ignore_blacklisted_events, :soft_write_failure].include?(k))
|
56
|
+
!([:server, :port, :url_prefix, :ignore_blacklisted_events, :soft_write_failure].include?(k))
|
56
57
|
end
|
57
58
|
|
58
59
|
config_hash[:server] = config_hash[:server].strip
|
59
60
|
config_hash[:port] = config_hash[:port].to_i
|
61
|
+
config_hash[:url_prefix] = normalize_url_prefix(config_hash[:url_prefix].strip)
|
60
62
|
config_hash[:ignore_blacklisted_events] =
|
61
63
|
Puppet::Util::Puppetdb.to_bool(config_hash[:ignore_blacklisted_events])
|
62
64
|
config_hash[:soft_write_failure] =
|
@@ -84,6 +86,10 @@ class Config
|
|
84
86
|
config[:port]
|
85
87
|
end
|
86
88
|
|
89
|
+
def url_prefix
|
90
|
+
config[:url_prefix]
|
91
|
+
end
|
92
|
+
|
87
93
|
def ignore_blacklisted_events?
|
88
94
|
config[:ignore_blacklisted_events]
|
89
95
|
end
|
@@ -96,6 +102,17 @@ class Config
|
|
96
102
|
config[:soft_write_failure]
|
97
103
|
end
|
98
104
|
|
105
|
+
# @!group Private class methods
|
106
|
+
def self.normalize_url_prefix(prefix)
|
107
|
+
if prefix == ""
|
108
|
+
prefix
|
109
|
+
elsif prefix.start_with?("/")
|
110
|
+
prefix
|
111
|
+
else
|
112
|
+
"/" + prefix
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
99
116
|
# @!group Private instance methods
|
100
117
|
|
101
118
|
# @!attribute [r] count
|
data/lib/puppet/util/puppetdb.rb
CHANGED
@@ -19,6 +19,13 @@ module Puppet::Util::Puppetdb
|
|
19
19
|
config.port
|
20
20
|
end
|
21
21
|
|
22
|
+
def self.url_path(path)
|
23
|
+
unless path.start_with?("/")
|
24
|
+
path = "/" + path
|
25
|
+
end
|
26
|
+
config.url_prefix + path
|
27
|
+
end
|
28
|
+
|
22
29
|
def self.config
|
23
30
|
@config ||= Puppet::Util::Puppetdb::Config.load
|
24
31
|
@config
|
@@ -68,6 +75,7 @@ module Puppet::Util::Puppetdb
|
|
68
75
|
# @param payload [String] payload
|
69
76
|
# @param command_name [String] name of command
|
70
77
|
# @param version [Number] version number of command
|
78
|
+
# @return [Hash <String, String>]
|
71
79
|
def submit_command(certname, payload, command_name, version)
|
72
80
|
profile "Submitted command '#{command_name}' version '#{version}'" do
|
73
81
|
command = Puppet::Util::Puppetdb::Command.new(command_name, version, certname, payload)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: quixoten-puppetdb-terminus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.1.0.rc1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Devin Christensen
|
@@ -87,9 +87,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
87
87
|
version: '0'
|
88
88
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
89
|
requirements:
|
90
|
-
- - "
|
90
|
+
- - ">"
|
91
91
|
- !ruby/object:Gem::Version
|
92
|
-
version:
|
92
|
+
version: 1.3.1
|
93
93
|
requirements: []
|
94
94
|
rubyforge_project:
|
95
95
|
rubygems_version: 2.2.2
|