puppetdb_query 0.0.24 → 0.0.25

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4c29a35e9a3f0273da0078d39fc360031e079559
4
- data.tar.gz: c1710d74138ab02f3bbb01d1780b203a02b62924
3
+ metadata.gz: e8472f7c93ea4f65a4ee87ace1642691819290c3
4
+ data.tar.gz: e1106d8da873423d09d5b1b38a3def9e94d7d2e2
5
5
  SHA512:
6
- metadata.gz: cae49d29397e9bb5be849f3018dc8432f08ffb1e950a1c5a2070bd76b53e1e1a12a1c6033b613573cee98967b83a0aae670a52a6f93fa19a5a3d753b1c95b1eb
7
- data.tar.gz: 6d2e55a958dba3917214f66d87ef9882b790e1c096abafe359f39a8c4a4f32dcf06904034cdb065aeb9d0eb2f5ff3e56132414edae8916e6cdf0d3de60f8b855
6
+ metadata.gz: 51ab68da432386ea4e02fed4df626c56fe0a9b3ea942ca5b0dfff7944b48a2039a33b2f26236155868f193ae137a68866abea71445f39d319b4d2329fcd3e386
7
+ data.tar.gz: 63f8fb7e455e04b1767ba51462ad21b23175ea2cf5ae48d7063f96fb2b547b921de6cb291abf8fdeb87a695db6276930eab49fb8a29e840f4609839e87fd37f4
@@ -29,14 +29,36 @@ module PuppetDBQuery
29
29
  @meta_collection = meta
30
30
  end
31
31
 
32
+ # get all nodes and their update dates
33
+ def node_properties
34
+ collection = connection[node_properties_collection]
35
+ result = {}
36
+ collection.find.batch_size(999).each do |values|
37
+ id = values.delete('_id')
38
+ result[id] = values
39
+ end
40
+ result
41
+ end
42
+
43
+ # get all node names
44
+ def all_nodes
45
+ collection = connection[nodes_collection]
46
+ collection.find.batch_size(999).projection(_id: 1).map { |k| k[:_id] }
47
+ end
48
+
32
49
  # get node names that fulfill given mongodb query
50
+ #
51
+ # @param query mongodb query
33
52
  def query_nodes(query)
34
53
  collection = connection[nodes_collection]
35
54
  collection.find(query).batch_size(999).projection(_id: 1).map { |k| k[:_id] }
36
55
  end
37
56
 
38
57
  # get nodes and their facts that fulfill given mongodb query
39
- def query_facts(query, facts)
58
+ #
59
+ # @param query mongodb query
60
+ # @param facts [Array<String>] get these facts in the result, eg ['fqdn'], empty for all
61
+ def query_facts(query, facts = [])
40
62
  fields = Hash[facts.collect { |fact| [fact.to_sym, 1] }]
41
63
  collection = connection[nodes_collection]
42
64
  result = {}
@@ -48,11 +70,12 @@ module PuppetDBQuery
48
70
  end
49
71
 
50
72
  # get nodes and their facts for a pattern
73
+ #
51
74
  # @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
75
+ # @param pattern [RegExp] search for
76
+ # @param facts [Array<String>] get these facts in the result, eg ['fqdn'], empty for all
77
+ # @param facts_found [Array<String>] fact names are added to this array
78
+ # @param check_names [Boolean] also search fact names
56
79
  def search_facts(query, pattern, facts = [], facts_found = [], check_names = false)
57
80
  collection = connection[nodes_collection]
58
81
  result = {}
@@ -76,36 +99,26 @@ module PuppetDBQuery
76
99
  result
77
100
  end
78
101
 
79
- # get all node names
80
- def nodes
81
- collection = connection[nodes_collection]
82
- collection.find.batch_size(999).projection(_id: 1).map { |k| k[:_id] }
83
- end
84
-
85
- # get all nodes and their update dates
86
- def node_properties
87
- collection = connection[node_properties_collection]
88
- result = {}
89
- collection.find.batch_size(999).each do |values|
90
- id = values.delete('_id')
91
- result[id] = values
92
- end
93
- result
94
- end
95
-
96
102
  # get facts for given node name
97
- def node_facts(node)
103
+ #
104
+ # @param node [String] node name
105
+ # @param facts [Array<String>] get these facts in the result, eg ['fqdn'], empty for all
106
+ def single_node_facts(node, facts)
107
+ fields = Hash[facts.collect { |fact| [fact.to_sym, 1] }]
98
108
  collection = connection[nodes_collection]
99
- result = collection.find(_id: node).limit(1).batch_size(1).to_a.first
109
+ result = collection.find(_id: node).limit(1).batch_size(1).projection(fields).to_a.first
100
110
  result.delete("_id") if result
101
111
  result
102
112
  end
103
113
 
104
114
  # get all nodes and their facts
105
- def facts
115
+ #
116
+ # @param facts [Array<String>] get these facts in the result, eg ['fqdn'], empty for all
117
+ def facts(facts = [])
118
+ fields = Hash[facts.collect { |fact| [fact.to_sym, 1] }]
106
119
  collection = connection[nodes_collection]
107
120
  result = {}
108
- collection.find.batch_size(999).each do |values|
121
+ collection.find.batch_size(999).projection(fields).each do |values|
109
122
  id = values.delete('_id')
110
123
  result[id] = values
111
124
  end
@@ -121,6 +134,9 @@ module PuppetDBQuery
121
134
  end
122
135
 
123
136
  # update or insert facts for given node name
137
+ #
138
+ # @param node [String] node name
139
+ # @param facts [Array<String>] get these facts in the result, eg ['fqdn'], empty for all
124
140
  def node_update(node, facts)
125
141
  connection[nodes_collection].find(_id: node).replace_one(facts, upsert: true)
126
142
  rescue ::Mongo::Error::OperationFailure => e
@@ -134,6 +150,8 @@ module PuppetDBQuery
134
150
  end
135
151
 
136
152
  # delete node data for given node name
153
+ #
154
+ # @param node [String] node name
137
155
  def node_delete(node)
138
156
  connection[nodes_collection].find(_id: node).delete_one
139
157
  end
@@ -19,9 +19,7 @@ module PuppetDBQuery
19
19
 
20
20
  # get array of node names
21
21
  def nodes
22
- # TODO: perhaps we have to ignore entries without "deactivated": null?
23
- # in '/v3/nodes' we must take 'name'
24
- api_nodes.map { |data| data['certname'] }
22
+ api_nodes.reject { |data| data['deactivated'] }.map { |data| data['certname'] }
25
23
  end
26
24
 
27
25
  # get hash of node update properties
@@ -1,3 +1,3 @@
1
1
  module PuppetDBQuery
2
- VERSION = "0.0.24".freeze
2
+ VERSION = "0.0.25".freeze
3
3
  end
metadata CHANGED
@@ -1,41 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppetdb_query
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.24
4
+ version: 0.0.25
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Meyling
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-12-31 00:00:00.000000000 Z
11
+ date: 2017-01-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: easy_diff
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  description: Allow puppetdb access from resources like mongodb.
@@ -45,9 +45,9 @@ executables: []
45
45
  extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
- - .gitignore
49
- - .rubocop.yml
50
- - .travis.yml
48
+ - ".gitignore"
49
+ - ".rubocop.yml"
50
+ - ".travis.yml"
51
51
  - Gemfile
52
52
  - LICENSE.txt
53
53
  - README.md
@@ -75,19 +75,19 @@ homepage: https://github.com/m-31/puppetdb_query
75
75
  licenses:
76
76
  - MIT
77
77
  metadata: {}
78
- post_install_message: ' Sitting quietly, doing nothing, spring comes, and grass grows
79
- by itself.'
78
+ post_install_message: " Sitting quietly, doing nothing, spring comes, and grass grows
79
+ by itself."
80
80
  rdoc_options: []
81
81
  require_paths:
82
82
  - lib
83
83
  required_ruby_version: !ruby/object:Gem::Requirement
84
84
  requirements:
85
- - - '>='
85
+ - - ">="
86
86
  - !ruby/object:Gem::Version
87
87
  version: 1.9.3
88
88
  required_rubygems_version: !ruby/object:Gem::Requirement
89
89
  requirements:
90
- - - '>='
90
+ - - ">="
91
91
  - !ruby/object:Gem::Version
92
92
  version: '0'
93
93
  requirements: []