puppetdb_query 0.0.22 → 0.0.23
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/puppetdb_query/mongodb.rb +14 -3
- data/lib/puppetdb_query/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: 359b66cb570cf21f12b481392c3beaa7bc6534bb
|
4
|
+
data.tar.gz: bcba75c34ffe214aabe450326ed109bdeb9be67b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d99268035b8adc41e7f8a35c71f2e8b4ae7af39a67fd2a960a52b3176509b1584951baed3e00b4b81609729f12ecd78eb246b5844fa25ca03c18b4bf28aface
|
7
|
+
data.tar.gz: edb8aa5afb543003c3a78dd1c6f40e07464c5c1c810cce159e43cb674fbf48398339684b15d1641b68d340ceca4d739dfbde3f420424e77f6a6240d48767835c
|
@@ -4,6 +4,7 @@ require_relative "logging"
|
|
4
4
|
|
5
5
|
module PuppetDBQuery
|
6
6
|
# access nodes and their facts from mongo database
|
7
|
+
# rubocop:disable Metrics/ClassLength
|
7
8
|
class MongoDB
|
8
9
|
include Logging
|
9
10
|
attr_reader :connection
|
@@ -47,7 +48,12 @@ module PuppetDBQuery
|
|
47
48
|
end
|
48
49
|
|
49
50
|
# get nodes and their facts for a pattern
|
50
|
-
|
51
|
+
# @param query mongodb query
|
52
|
+
# @param pattern RegExp to search for
|
53
|
+
# @param facts Array get these values in the result, eg ['fqdn']
|
54
|
+
# @param facts_found Array fact names are added to this array
|
55
|
+
# @param check_names Boolean also search fact names
|
56
|
+
def search_facts(query, pattern, facts = [], facts_found = [], check_names = false)
|
51
57
|
collection = connection[nodes_collection]
|
52
58
|
result = {}
|
53
59
|
collection.find(query).batch_size(999).each do |values|
|
@@ -60,8 +66,12 @@ module PuppetDBQuery
|
|
60
66
|
found[k] = v
|
61
67
|
end
|
62
68
|
end
|
63
|
-
|
64
|
-
|
69
|
+
facts_found.concat(found.keys).uniq!
|
70
|
+
next if found.empty?
|
71
|
+
facts.each do |f|
|
72
|
+
found = values[f]
|
73
|
+
end
|
74
|
+
result[id] = found
|
65
75
|
end
|
66
76
|
result
|
67
77
|
end
|
@@ -185,4 +195,5 @@ module PuppetDBQuery
|
|
185
195
|
@node_properties_update_timestamp = ts_begin
|
186
196
|
end
|
187
197
|
end
|
198
|
+
# rubocop:enable Metrics/ClassLength
|
188
199
|
end
|