ruby-puppetdb 1.3.3 → 1.4.0

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: 392d7e62e4de4fab8893322d3b1566af2115decc
4
- data.tar.gz: b7352a764dac57a95abaabbe444fa87d7fd7dae6
3
+ metadata.gz: b8b23502fed021f532f01055c3ca02a633bd113a
4
+ data.tar.gz: 02b21821bbf0e4f9cd90db15c50ede416abb09cd
5
5
  SHA512:
6
- metadata.gz: d7c7160494a09d173209981e627c09c615d33d472033fdbe0b1034ef6734aff3deaff8471c58a99b75310746faf3177ebda3874f7d7193b507752b7d9ddcae77
7
- data.tar.gz: 6139c779e2ba9057e00cccce7de0adecd5c7568b5fa8283450d1f5b95a8056f3c81a1c47b8e812e702e1289134d5cae0fcc19a8eed3a3c6627510cad4a13d514
6
+ metadata.gz: b2c15fe26908deb2751fa3c08cacb8ff06fb934ca4c101f86e21ae3489d244269bc12b8f5628186e9e0f696bf2d5d99de3b7c03af4c0d46ed5d525cd7296b560
7
+ data.tar.gz: ac6703ed8f562b5bb7a6803c37d009a91e6cc18b478df6b238758d1d9bc2c66d78a10b7008828a75c9b0c5fd40d84ec2fd782a930f779b6896729a279e24782c
@@ -66,10 +66,11 @@ Puppet::Face.define(:query, '1.0.0') do
66
66
  when_invoked do |query, options|
67
67
  puppetdb = PuppetDB::Connection.new options[:puppetdb_host], options[:puppetdb_port]
68
68
  nodes = puppetdb.query(:nodes, puppetdb.parse_query(query, :nodes))
69
+
69
70
  if options[:node_info]
70
- nodes
71
+ Hash[nodes.collect { |node| [node['name'], node.reject{|k,v| k == "name"}] }]
71
72
  else
72
- nodes.collect { |node| node['name'] } unless options[:node_info]
73
+ nodes.collect { |node| node['name'] }
73
74
  end
74
75
  end
75
76
 
data/lib/puppetdb.rb CHANGED
@@ -1,2 +1,4 @@
1
1
  module PuppetDB
2
+ # Current version of this module
3
+ VERSION = [1,4,0]
2
4
  end
@@ -9,6 +9,7 @@ class PuppetDB::ASTNode
9
9
 
10
10
  def capitalize!
11
11
  @value=@value.to_s.split("::").collect { |s| s.capitalize }.join("::")
12
+ @children.each { |c| c.capitalize! }
12
13
  return self
13
14
  end
14
15
 
@@ -73,7 +74,7 @@ class PuppetDB::ASTNode
73
74
  when :boolean
74
75
  return @value
75
76
  when :resourcetitle
76
- return ['=', 'title', @value]
77
+ return [@value, 'title', @children[0].evaluate(mode)]
77
78
  when :resourcetype
78
79
  return ['=', 'type', @value]
79
80
  when :resexported
@@ -4,7 +4,6 @@ class PuppetDB::Connection
4
4
  require 'rubygems'
5
5
  require 'puppetdb/parser'
6
6
  require 'uri'
7
- require 'json'
8
7
 
9
8
  def initialize(host='puppetdb', port=443, use_ssl=true)
10
9
  @host = host
@@ -19,7 +18,9 @@ class PuppetDB::Connection
19
18
  # @param endpoint [Symbol] the endpoint for which the query should be evaluated
20
19
  # @return [Array] the PuppetDB query
21
20
  def parse_query(query, endpoint=:nodes)
22
- @parser.scan_str(query).optimize.evaluate endpoint
21
+ if query = @parser.scan_str(query)
22
+ query.optimize.evaluate endpoint
23
+ end
23
24
  end
24
25
 
25
26
  # Get the listed facts for all nodes matching query
@@ -51,6 +52,8 @@ class PuppetDB::Connection
51
52
  # @param query [Array] query to execute
52
53
  # @return [Array] the results of the query
53
54
  def query(endpoint, query=nil, http=nil, version=:v2)
55
+ require 'json'
56
+
54
57
  unless http then
55
58
  require 'puppet/network/http_pool'
56
59
  http = Puppet::Network::HttpPool.http_instance(@host, @port, @use_ssl)
@@ -16,7 +16,8 @@ class PuppetDB::Parser
16
16
  preclow
17
17
 
18
18
  rule
19
- query: exp
19
+ query:
20
+ |exp
20
21
 
21
22
  exp: LPAREN exp RPAREN { result = val[1] }
22
23
  | NOT exp { result = ASTNode.new :booleanop, :not, [val[1]] }
@@ -46,7 +47,8 @@ rule
46
47
 
47
48
  resexported: EXPORTED
48
49
  restype: STRING { result = ASTNode.new(:resourcetype, val[0]).capitalize! }
49
- restitle: LBRACK STRING RBRACK { result = ASTNode.new :resourcetitle, val[1] }
50
+ restitle: LBRACK STRING RBRACK { result = ASTNode.new :resourcetitle, '=', [ASTNode.new(:string, val[1])] }
51
+ restitle: LBRACK MATCH STRING RBRACK { result = ASTNode.new :resourcetitle, '~', [ASTNode.new(:string, val[2])] }
50
52
  resparams: LBRACE exp RBRACE { result = val[1] }
51
53
 
52
54
  string: STRING { result = ASTNode.new :string, val[0] }
@@ -58,4 +60,3 @@ end
58
60
  require 'puppetdb'
59
61
  require 'puppetdb/lexer'
60
62
  require 'puppetdb/astnode'
61
-
data/lib/puppetdb/lexer.l CHANGED
@@ -26,6 +26,7 @@ rule
26
26
  -?\d+\.\d+ { [:NUMBER, text.to_f] }
27
27
  -?\d+ { [:NUMBER, text.to_i] }
28
28
  \"(\\.|[^\\"])*\" { [:STRING, YAML.load(text)] }
29
+ \'(\\.|[^\\'])*\' { [:STRING, YAML.load(text)] }
29
30
  {STR}+ { [:STRING, text] }
30
31
  @@ { [:EXPORTED, text] }
31
32
  end
@@ -117,6 +117,9 @@ class Lexer < Racc::Parser
117
117
  when (text = ss.scan(/\"(\\.|[^\\"])*\"/))
118
118
  @rex_tokens.push action { [:STRING, YAML.load(text)] }
119
119
 
120
+ when (text = ss.scan(/\'(\\.|[^\\'])*\'/))
121
+ @rex_tokens.push action { [:STRING, YAML.load(text)] }
122
+
120
123
  when (text = ss.scan(/[\w_:]+/))
121
124
  @rex_tokens.push action { [:STRING, text] }
122
125
 
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # DO NOT MODIFY!!!!
3
- # This file is automatically generated by Racc 1.4.9
3
+ # This file is automatically generated by Racc 1.4.11
4
4
  # from Racc grammer file "".
5
5
  #
6
6
 
@@ -14,65 +14,65 @@ module PuppetDB
14
14
  ##### State transition tables begin ###
15
15
 
16
16
  racc_action_table = [
17
- 4, 4, 5, 5, 8, 8, -29, -29, -29, -29,
18
- -29, 3, 3, 36, 47, 9, 9, 12, 12, 4,
19
- 4, 5, 5, 8, 8, 16, 17, 5, 36, 8,
20
- 3, 3, 16, 17, 9, 9, 12, 12, 4, 4,
21
- 5, 5, 8, 8, 5, 32, 8, 41, 8, 3,
22
- 3, 49, 48, 9, 9, 12, 12, 28, 16, 17,
23
- 20, 21, 22, 18, 19, 36, 41, 42, 36, 41,
24
- 42, 25, 8, 51, 16 ]
17
+ 3, 3, 14, 14, 15, 15, 32, 42, 41, 43,
18
+ 15, 4, 4, 31, 37, 13, 13, 12, 12, 3,
19
+ 3, 14, 14, 15, 15, 17, 18, 14, 42, 15,
20
+ 4, 4, 17, 18, 13, 13, 12, 12, 3, 3,
21
+ 14, 14, 15, 15, 14, 42, 15, 41, 34, 4,
22
+ 4, 53, 16, 13, 13, 12, 12, 27, 17, 18,
23
+ 21, 25, 24, 23, 22, -31, -31, -31, -31, -31,
24
+ 42, 41, 43, 51, 52, 15, 17, 54 ]
25
25
 
26
26
  racc_action_check = [
27
- 0, 17, 0, 17, 0, 17, 9, 9, 9, 9,
28
- 9, 0, 17, 19, 24, 0, 17, 0, 17, 8,
29
- 3, 8, 3, 8, 3, 24, 24, 11, 18, 11,
30
- 8, 3, 1, 1, 8, 3, 8, 3, 4, 16,
31
- 4, 16, 4, 16, 10, 15, 10, 22, 13, 4,
32
- 16, 26, 25, 4, 16, 4, 16, 10, 26, 26,
33
- 2, 2, 2, 2, 2, 21, 21, 21, 20, 20,
34
- 20, 5, 29, 32, 34 ]
27
+ 0, 18, 0, 18, 0, 18, 14, 25, 25, 25,
28
+ 28, 0, 18, 14, 19, 0, 18, 0, 18, 15,
29
+ 3, 15, 3, 15, 3, 19, 19, 9, 22, 9,
30
+ 15, 3, 2, 2, 15, 3, 15, 3, 4, 17,
31
+ 4, 17, 4, 17, 8, 23, 8, 24, 16, 4,
32
+ 17, 33, 1, 4, 17, 4, 17, 8, 33, 33,
33
+ 5, 5, 5, 5, 5, 13, 13, 13, 13, 13,
34
+ 21, 21, 21, 31, 32, 10, 36, 52 ]
35
35
 
36
36
  racc_action_pointer = [
37
- -2, 18, 52, 18, 36, 54, nil, nil, 17, -2,
38
- 40, 23, nil, 42, nil, 45, 37, -1, 12, -3,
39
- 52, 49, 30, nil, 11, 47, 44, nil, nil, 66,
40
- nil, nil, 73, nil, 60, nil, nil, nil, nil, nil,
37
+ -2, 52, 18, 18, 36, 52, nil, nil, 40, 23,
38
+ 69, nil, nil, 57, -4, 17, 48, 37, -1, 11,
39
+ nil, 54, 12, 29, 30, -9, nil, nil, 4, nil,
40
+ nil, 68, 57, 44, nil, nil, 62, nil, nil, nil,
41
41
  nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
42
- nil, nil ]
42
+ nil, nil, 72, nil, nil ]
43
43
 
44
44
  racc_action_default = [
45
- -32, -1, -32, -32, -32, -32, -15, -16, -32, -26,
46
- -32, -18, -25, -19, -20, -32, -32, -32, -32, -32,
47
- -32, -32, -32, -3, -32, -32, -32, -17, -26, -21,
48
- -23, -22, -32, -4, -5, -10, -30, -9, -6, -7,
49
- -8, -29, -31, -14, -13, -12, -11, -2, -27, -28,
50
- -24, 52 ]
45
+ -1, -34, -2, -34, -34, -34, -16, -17, -34, -19,
46
+ -20, -21, -26, -27, -34, -34, -34, -34, -34, -34,
47
+ -4, -34, -34, -34, -34, -34, -18, -27, -22, -24,
48
+ -23, -34, -34, -34, 55, -5, -6, -3, -7, -8,
49
+ -9, -31, -32, -33, -10, -11, -12, -13, -14, -15,
50
+ -25, -28, -34, -30, -29 ]
51
51
 
52
52
  racc_goto_table = [
53
- 30, 27, 31, 1, 39, 44, 23, 24, 38, 43,
54
- 46, 26, 35, 37, 40, 45, 29, 15, 50, 33,
55
- 34 ]
53
+ 29, 30, 26, 2, 28, 38, 19, 20, 46, 49,
54
+ 39, 40, 44, 45, 48, 47, 1, nil, 33, 50,
55
+ 35, 36 ]
56
56
 
57
57
  racc_goto_check = [
58
- 11, 7, 11, 2, 4, 4, 2, 2, 3, 3,
59
- 3, 2, 5, 5, 5, 5, 10, 1, 11, 2,
60
- 2 ]
58
+ 11, 11, 7, 2, 10, 3, 2, 2, 3, 3,
59
+ 4, 5, 5, 5, 4, 5, 1, nil, 2, 11,
60
+ 2, 2 ]
61
61
 
62
62
  racc_goto_pointer = [
63
- nil, 17, 3, -12, -16, -6, nil, -9, nil, nil,
64
- 5, -11 ]
63
+ nil, 16, 3, -16, -11, -10, nil, -6, nil, nil,
64
+ -5, -9 ]
65
65
 
66
66
  racc_goto_default = [
67
- nil, nil, nil, 2, nil, nil, 6, 7, 10, 11,
68
- 13, 14 ]
67
+ nil, nil, nil, 5, nil, nil, 6, 7, 8, 9,
68
+ 10, 11 ]
69
69
 
70
70
  racc_reduce_table = [
71
71
  0, 0, :racc_error,
72
+ 0, 21, :_reduce_none,
72
73
  1, 21, :_reduce_none,
73
- 3, 22, :_reduce_2,
74
- 2, 22, :_reduce_3,
75
- 3, 22, :_reduce_4,
74
+ 3, 22, :_reduce_3,
75
+ 2, 22, :_reduce_4,
76
76
  3, 22, :_reduce_5,
77
77
  3, 22, :_reduce_6,
78
78
  3, 22, :_reduce_7,
@@ -83,27 +83,29 @@ racc_reduce_table = [
83
83
  3, 22, :_reduce_12,
84
84
  3, 22, :_reduce_13,
85
85
  3, 22, :_reduce_14,
86
+ 3, 22, :_reduce_15,
86
87
  1, 22, :_reduce_none,
87
- 1, 26, :_reduce_16,
88
- 2, 26, :_reduce_17,
89
- 1, 27, :_reduce_18,
88
+ 1, 26, :_reduce_17,
89
+ 2, 26, :_reduce_18,
90
90
  1, 27, :_reduce_19,
91
91
  1, 27, :_reduce_20,
92
- 2, 27, :_reduce_21,
92
+ 1, 27, :_reduce_21,
93
93
  2, 27, :_reduce_22,
94
94
  2, 27, :_reduce_23,
95
- 3, 27, :_reduce_24,
95
+ 2, 27, :_reduce_24,
96
+ 3, 27, :_reduce_25,
96
97
  1, 28, :_reduce_none,
97
- 1, 29, :_reduce_26,
98
- 3, 30, :_reduce_27,
99
- 3, 31, :_reduce_28,
100
- 1, 23, :_reduce_29,
101
- 1, 25, :_reduce_30,
102
- 1, 24, :_reduce_31 ]
98
+ 1, 29, :_reduce_27,
99
+ 3, 30, :_reduce_28,
100
+ 4, 30, :_reduce_29,
101
+ 3, 31, :_reduce_30,
102
+ 1, 23, :_reduce_31,
103
+ 1, 25, :_reduce_32,
104
+ 1, 24, :_reduce_33 ]
103
105
 
104
- racc_reduce_n = 32
106
+ racc_reduce_n = 34
105
107
 
106
- racc_shift_n = 52
108
+ racc_shift_n = 55
107
109
 
108
110
  racc_token_table = {
109
111
  false => 0,
@@ -189,37 +191,32 @@ Racc_debug_parser = false
189
191
 
190
192
  # reduce 1 omitted
191
193
 
192
- module_eval(<<'.,.,', 'grammar.y', 20)
193
- def _reduce_2(val, _values, result)
194
- result = val[1]
195
- result
196
- end
197
- .,.,
194
+ # reduce 2 omitted
198
195
 
199
196
  module_eval(<<'.,.,', 'grammar.y', 21)
200
197
  def _reduce_3(val, _values, result)
201
- result = ASTNode.new :booleanop, :not, [val[1]]
198
+ result = val[1]
202
199
  result
203
200
  end
204
201
  .,.,
205
202
 
206
203
  module_eval(<<'.,.,', 'grammar.y', 22)
207
204
  def _reduce_4(val, _values, result)
208
- result = ASTNode.new :booleanop, :and, [val[0], val[2]]
205
+ result = ASTNode.new :booleanop, :not, [val[1]]
209
206
  result
210
207
  end
211
208
  .,.,
212
209
 
213
210
  module_eval(<<'.,.,', 'grammar.y', 23)
214
211
  def _reduce_5(val, _values, result)
215
- result = ASTNode.new :booleanop, :or, [val[0], val[2]]
212
+ result = ASTNode.new :booleanop, :and, [val[0], val[2]]
216
213
  result
217
214
  end
218
215
  .,.,
219
216
 
220
217
  module_eval(<<'.,.,', 'grammar.y', 24)
221
218
  def _reduce_6(val, _values, result)
222
- result = ASTNode.new :exp, :equals, [val[0], val[2]]
219
+ result = ASTNode.new :booleanop, :or, [val[0], val[2]]
223
220
  result
224
221
  end
225
222
  .,.,
@@ -240,28 +237,28 @@ module_eval(<<'.,.,', 'grammar.y', 26)
240
237
 
241
238
  module_eval(<<'.,.,', 'grammar.y', 27)
242
239
  def _reduce_9(val, _values, result)
243
- result = ASTNode.new :exp, :greaterthan, [val[0], val[2]]
240
+ result = ASTNode.new :exp, :equals, [val[0], val[2]]
244
241
  result
245
242
  end
246
243
  .,.,
247
244
 
248
245
  module_eval(<<'.,.,', 'grammar.y', 28)
249
246
  def _reduce_10(val, _values, result)
250
- result = ASTNode.new :exp, :lessthan, [val[0], val[2]]
247
+ result = ASTNode.new :exp, :greaterthan, [val[0], val[2]]
251
248
  result
252
249
  end
253
250
  .,.,
254
251
 
255
252
  module_eval(<<'.,.,', 'grammar.y', 29)
256
253
  def _reduce_11(val, _values, result)
257
- result = ASTNode.new :exp, :match, [val[0], val[2]]
254
+ result = ASTNode.new :exp, :lessthan, [val[0], val[2]]
258
255
  result
259
256
  end
260
257
  .,.,
261
258
 
262
259
  module_eval(<<'.,.,', 'grammar.y', 30)
263
260
  def _reduce_12(val, _values, result)
264
- result = ASTNode.new :booleanop, :not, [ASTNode.new(:exp, :equals, [val[0], val[2]])]
261
+ result = ASTNode.new :exp, :match, [val[0], val[2]]
265
262
  result
266
263
  end
267
264
  .,.,
@@ -280,25 +277,25 @@ module_eval(<<'.,.,', 'grammar.y', 32)
280
277
  end
281
278
  .,.,
282
279
 
283
- # reduce 15 omitted
284
-
285
- module_eval(<<'.,.,', 'grammar.y', 35)
286
- def _reduce_16(val, _values, result)
287
- result = ASTNode.new :subquery, :resources, [ASTNode.new(:booleanop, :and, [ASTNode.new(:resexported, false), *val[0]])]
280
+ module_eval(<<'.,.,', 'grammar.y', 33)
281
+ def _reduce_15(val, _values, result)
282
+ result = ASTNode.new :booleanop, :not, [ASTNode.new(:exp, :equals, [val[0], val[2]])]
288
283
  result
289
284
  end
290
285
  .,.,
291
286
 
287
+ # reduce 16 omitted
288
+
292
289
  module_eval(<<'.,.,', 'grammar.y', 36)
293
290
  def _reduce_17(val, _values, result)
294
- result = ASTNode.new :subquery, :resources, [ASTNode.new(:booleanop, :and, [ASTNode.new(:resexported, true), *val[1]])]
291
+ result = ASTNode.new :subquery, :resources, [ASTNode.new(:booleanop, :and, [ASTNode.new(:resexported, false), *val[0]])]
295
292
  result
296
293
  end
297
294
  .,.,
298
295
 
299
- module_eval(<<'.,.,', 'grammar.y', 38)
296
+ module_eval(<<'.,.,', 'grammar.y', 37)
300
297
  def _reduce_18(val, _values, result)
301
- result = [val[0]]
298
+ result = ASTNode.new :subquery, :resources, [ASTNode.new(:booleanop, :and, [ASTNode.new(:resexported, true), *val[1]])]
302
299
  result
303
300
  end
304
301
  .,.,
@@ -319,14 +316,14 @@ module_eval(<<'.,.,', 'grammar.y', 40)
319
316
 
320
317
  module_eval(<<'.,.,', 'grammar.y', 41)
321
318
  def _reduce_21(val, _values, result)
322
- result = val[0].value == "Class" ? [val[0], val[1].capitalize!] : [val[0], val[1]]
319
+ result = [val[0]]
323
320
  result
324
321
  end
325
322
  .,.,
326
323
 
327
324
  module_eval(<<'.,.,', 'grammar.y', 42)
328
325
  def _reduce_22(val, _values, result)
329
- result = [val[0], val[1]]
326
+ result = val[0].value == "Class" ? [val[0], val[1].capitalize!] : [val[0], val[1]]
330
327
  result
331
328
  end
332
329
  .,.,
@@ -340,50 +337,64 @@ module_eval(<<'.,.,', 'grammar.y', 43)
340
337
 
341
338
  module_eval(<<'.,.,', 'grammar.y', 44)
342
339
  def _reduce_24(val, _values, result)
343
- result = val[0].value == "Class" ? [val[0], val[1].capitalize!, val[2]] : [val[0], val[1], val[2]]
340
+ result = [val[0], val[1]]
344
341
  result
345
342
  end
346
343
  .,.,
347
344
 
348
- # reduce 25 omitted
349
-
350
- module_eval(<<'.,.,', 'grammar.y', 47)
351
- def _reduce_26(val, _values, result)
352
- result = ASTNode.new(:resourcetype, val[0]).capitalize!
345
+ module_eval(<<'.,.,', 'grammar.y', 45)
346
+ def _reduce_25(val, _values, result)
347
+ result = val[0].value == "Class" ? [val[0], val[1].capitalize!, val[2]] : [val[0], val[1], val[2]]
353
348
  result
354
349
  end
355
350
  .,.,
356
351
 
352
+ # reduce 26 omitted
353
+
357
354
  module_eval(<<'.,.,', 'grammar.y', 48)
358
355
  def _reduce_27(val, _values, result)
359
- result = ASTNode.new :resourcetitle, val[1]
356
+ result = ASTNode.new(:resourcetype, val[0]).capitalize!
360
357
  result
361
358
  end
362
359
  .,.,
363
360
 
364
361
  module_eval(<<'.,.,', 'grammar.y', 49)
365
362
  def _reduce_28(val, _values, result)
366
- result = val[1]
363
+ result = ASTNode.new :resourcetitle, '=', [ASTNode.new(:string, val[1])]
367
364
  result
368
365
  end
369
366
  .,.,
370
367
 
371
- module_eval(<<'.,.,', 'grammar.y', 51)
368
+ module_eval(<<'.,.,', 'grammar.y', 50)
372
369
  def _reduce_29(val, _values, result)
373
- result = ASTNode.new :string, val[0]
370
+ result = ASTNode.new :resourcetitle, '~', [ASTNode.new(:string, val[2])]
374
371
  result
375
372
  end
376
373
  .,.,
377
374
 
378
- module_eval(<<'.,.,', 'grammar.y', 52)
375
+ module_eval(<<'.,.,', 'grammar.y', 51)
379
376
  def _reduce_30(val, _values, result)
380
- result = ASTNode.new :number, val[0]
377
+ result = val[1]
381
378
  result
382
379
  end
383
380
  .,.,
384
381
 
385
382
  module_eval(<<'.,.,', 'grammar.y', 53)
386
383
  def _reduce_31(val, _values, result)
384
+ result = ASTNode.new :string, val[0]
385
+ result
386
+ end
387
+ .,.,
388
+
389
+ module_eval(<<'.,.,', 'grammar.y', 54)
390
+ def _reduce_32(val, _values, result)
391
+ result = ASTNode.new :number, val[0]
392
+ result
393
+ end
394
+ .,.,
395
+
396
+ module_eval(<<'.,.,', 'grammar.y', 55)
397
+ def _reduce_33(val, _values, result)
387
398
  result = ASTNode.new :boolean, val[0]
388
399
  result
389
400
  end