ruby-puppetdb 1.0.0.pre2

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.
Files changed (40) hide show
  1. data/.gitignore +3 -0
  2. data/COPYING +202 -0
  3. data/Modulefile +7 -0
  4. data/README.md +233 -0
  5. data/Rakefile +24 -0
  6. data/bin/find-nodes +56 -0
  7. data/examples/nova_functions.pp +16 -0
  8. data/examples/query_node_examples.pp +12 -0
  9. data/examples/query_resource_examples.pp +48 -0
  10. data/lib/puppet/application/query.rb +22 -0
  11. data/lib/puppet/face/query.rb +60 -0
  12. data/lib/puppet/parser/functions/pdbfactquery.rb +31 -0
  13. data/lib/puppet/parser/functions/pdbnodequery.rb +38 -0
  14. data/lib/puppet/parser/functions/pdbnodequery_all.rb +40 -0
  15. data/lib/puppet/parser/functions/pdbquery.rb +41 -0
  16. data/lib/puppet/parser/functions/pdbresourcequery.rb +39 -0
  17. data/lib/puppet/parser/functions/pdbresourcequery_all.rb +37 -0
  18. data/lib/puppet/parser/functions/pdbstatusquery.rb +31 -0
  19. data/lib/puppet/parser/functions/query_facts.rb +27 -0
  20. data/lib/puppet/parser/functions/query_nodes.rb +27 -0
  21. data/lib/puppetdb.rb +2 -0
  22. data/lib/puppetdb/astnode.rb +86 -0
  23. data/lib/puppetdb/connection.rb +62 -0
  24. data/lib/puppetdb/grammar.y +57 -0
  25. data/lib/puppetdb/lexer.l +28 -0
  26. data/lib/puppetdb/lexer.rb +135 -0
  27. data/lib/puppetdb/parser.rb +368 -0
  28. data/lib/puppetdb/util.rb +18 -0
  29. data/ruby-puppetdb.gemspec +16 -0
  30. data/spec/spec_helper.rb +4 -0
  31. data/spec/unit/puppet/parser/functions/pdbfactquery_spec.rb +19 -0
  32. data/spec/unit/puppet/parser/functions/pdbnodequery_all_spec.rb +19 -0
  33. data/spec/unit/puppet/parser/functions/pdbnodequery_spec.rb +19 -0
  34. data/spec/unit/puppet/parser/functions/pdbquery_spec.rb +19 -0
  35. data/spec/unit/puppet/parser/functions/pdbresourcequery_all_spec.rb +19 -0
  36. data/spec/unit/puppet/parser/functions/pdbresourcequery_spec.rb +19 -0
  37. data/spec/unit/puppet/parser/functions/pdbstatusquery_spec.rb +19 -0
  38. data/spec/unit/puppet/parser/functions/query_facts_spec.rb +11 -0
  39. data/spec/unit/puppet/parser/functions/query_nodes_spec.rb +11 -0
  40. metadata +118 -0
@@ -0,0 +1,368 @@
1
+ #
2
+ # DO NOT MODIFY!!!!
3
+ # This file is automatically generated by Racc 1.4.9
4
+ # from Racc grammer file "".
5
+ #
6
+
7
+ require 'racc/parser.rb'
8
+
9
+ require 'puppetdb'
10
+ require 'puppetdb/lexer'
11
+ require 'puppetdb/astnode'
12
+ module PuppetDB
13
+ class Parser < PuppetDB::Lexer
14
+ ##### State transition tables begin ###
15
+
16
+ racc_action_table = [
17
+ 3, 3, 5, 5, 8, 8, 3, 5, 5, 8,
18
+ 8, 2, 2, 26, 27, 9, 9, 2, 3, 40,
19
+ 5, 9, 8, 3, 3, 5, 5, 8, 8, 2,
20
+ 26, 27, 29, 9, 2, 2, 43, 34, 9, 9,
21
+ 29, 34, 35, 26, 27, -26, -26, -26, -26, -26,
22
+ 15, 16, 17, 13, 14, 29, 34, 35, 29, 41,
23
+ 8, 25, 44, 8, 20, 26 ]
24
+
25
+ racc_action_check = [
26
+ 0, 26, 0, 26, 0, 26, 2, 6, 2, 6,
27
+ 2, 0, 26, 12, 12, 0, 26, 2, 3, 19,
28
+ 3, 2, 3, 27, 8, 27, 8, 27, 8, 3,
29
+ 19, 19, 14, 3, 27, 8, 24, 17, 27, 8,
30
+ 16, 16, 16, 24, 24, 9, 9, 9, 9, 9,
31
+ 1, 1, 1, 1, 1, 15, 15, 15, 13, 20,
32
+ 21, 11, 25, 7, 5, 46 ]
33
+
34
+ racc_action_pointer = [
35
+ -2, 42, 4, 16, nil, 47, 3, 57, 22, 37,
36
+ nil, 61, -1, 42, 16, 39, 24, 20, nil, 16,
37
+ 54, 54, nil, nil, 29, 62, -1, 21, nil, nil,
38
+ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
39
+ nil, nil, nil, nil, nil, nil, 51 ]
40
+
41
+ racc_action_default = [
42
+ -29, -29, -29, -29, -15, -29, -16, -17, -29, -23,
43
+ -18, -29, -1, -29, -29, -29, -29, -29, -3, -29,
44
+ -29, -19, -21, -20, -29, -29, -29, -29, -10, -27,
45
+ -9, -6, -7, -8, -26, -28, -14, -13, -12, -11,
46
+ -2, -24, -22, -25, 47, -4, -5 ]
47
+
48
+ racc_goto_table = [
49
+ 12, 21, 18, 19, 22, 23, 32, 37, 24, 28,
50
+ 30, 33, 38, 31, 36, 39, 11, nil, nil, 42,
51
+ nil, nil, nil, nil, nil, nil, 45, 46 ]
52
+
53
+ racc_goto_check = [
54
+ 2, 8, 2, 2, 9, 9, 4, 4, 2, 5,
55
+ 5, 5, 5, 3, 3, 3, 1, nil, nil, 9,
56
+ nil, nil, nil, nil, nil, nil, 2, 2 ]
57
+
58
+ racc_goto_pointer = [
59
+ nil, 16, 0, -2, -9, -4, nil, nil, -5, -2 ]
60
+
61
+ racc_goto_default = [
62
+ nil, nil, nil, 1, nil, nil, 4, 6, 7, 10 ]
63
+
64
+ racc_reduce_table = [
65
+ 0, 0, :racc_error,
66
+ 1, 20, :_reduce_none,
67
+ 3, 21, :_reduce_2,
68
+ 2, 21, :_reduce_3,
69
+ 3, 21, :_reduce_4,
70
+ 3, 21, :_reduce_5,
71
+ 3, 21, :_reduce_6,
72
+ 3, 21, :_reduce_7,
73
+ 3, 21, :_reduce_8,
74
+ 3, 21, :_reduce_9,
75
+ 3, 21, :_reduce_10,
76
+ 3, 21, :_reduce_11,
77
+ 3, 21, :_reduce_12,
78
+ 3, 21, :_reduce_13,
79
+ 3, 21, :_reduce_14,
80
+ 1, 21, :_reduce_none,
81
+ 1, 25, :_reduce_16,
82
+ 1, 25, :_reduce_17,
83
+ 1, 25, :_reduce_18,
84
+ 2, 25, :_reduce_19,
85
+ 2, 25, :_reduce_20,
86
+ 2, 25, :_reduce_21,
87
+ 3, 25, :_reduce_22,
88
+ 1, 26, :_reduce_23,
89
+ 3, 27, :_reduce_24,
90
+ 3, 28, :_reduce_25,
91
+ 1, 22, :_reduce_26,
92
+ 1, 24, :_reduce_27,
93
+ 1, 23, :_reduce_28 ]
94
+
95
+ racc_reduce_n = 29
96
+
97
+ racc_shift_n = 47
98
+
99
+ racc_token_table = {
100
+ false => 0,
101
+ :error => 1,
102
+ :LPAREN => 2,
103
+ :RPAREN => 3,
104
+ :LBRACK => 4,
105
+ :RBRACK => 5,
106
+ :LBRACE => 6,
107
+ :RBRACE => 7,
108
+ :EQUALS => 8,
109
+ :NOTEQUALS => 9,
110
+ :MATCH => 10,
111
+ :LESSTHAN => 11,
112
+ :GREATERTHAN => 12,
113
+ :NOT => 13,
114
+ :AND => 14,
115
+ :OR => 15,
116
+ :NUMBER => 16,
117
+ :STRING => 17,
118
+ :BOOLEAN => 18 }
119
+
120
+ racc_nt_base = 19
121
+
122
+ racc_use_result_var = true
123
+
124
+ Racc_arg = [
125
+ racc_action_table,
126
+ racc_action_check,
127
+ racc_action_default,
128
+ racc_action_pointer,
129
+ racc_goto_table,
130
+ racc_goto_check,
131
+ racc_goto_default,
132
+ racc_goto_pointer,
133
+ racc_nt_base,
134
+ racc_reduce_table,
135
+ racc_token_table,
136
+ racc_shift_n,
137
+ racc_reduce_n,
138
+ racc_use_result_var ]
139
+
140
+ Racc_token_to_s_table = [
141
+ "$end",
142
+ "error",
143
+ "LPAREN",
144
+ "RPAREN",
145
+ "LBRACK",
146
+ "RBRACK",
147
+ "LBRACE",
148
+ "RBRACE",
149
+ "EQUALS",
150
+ "NOTEQUALS",
151
+ "MATCH",
152
+ "LESSTHAN",
153
+ "GREATERTHAN",
154
+ "NOT",
155
+ "AND",
156
+ "OR",
157
+ "NUMBER",
158
+ "STRING",
159
+ "BOOLEAN",
160
+ "$start",
161
+ "query",
162
+ "exp",
163
+ "string",
164
+ "boolean",
165
+ "number",
166
+ "ressubquery",
167
+ "restype",
168
+ "restitle",
169
+ "resparams" ]
170
+
171
+ Racc_debug_parser = false
172
+
173
+ ##### State transition tables end #####
174
+
175
+ # reduce 0 omitted
176
+
177
+ # reduce 1 omitted
178
+
179
+ module_eval(<<'.,.,', 'grammar.y', 20)
180
+ def _reduce_2(val, _values, result)
181
+ result = val[1]
182
+ result
183
+ end
184
+ .,.,
185
+
186
+ module_eval(<<'.,.,', 'grammar.y', 21)
187
+ def _reduce_3(val, _values, result)
188
+ result = ASTNode.new :booleanop, :not, [val[1]]
189
+ result
190
+ end
191
+ .,.,
192
+
193
+ module_eval(<<'.,.,', 'grammar.y', 22)
194
+ def _reduce_4(val, _values, result)
195
+ result = ASTNode.new :booleanop, :and, [val[0], val[2]]
196
+ result
197
+ end
198
+ .,.,
199
+
200
+ module_eval(<<'.,.,', 'grammar.y', 23)
201
+ def _reduce_5(val, _values, result)
202
+ result = ASTNode.new :booleanop, :or, [val[0], val[2]]
203
+ result
204
+ end
205
+ .,.,
206
+
207
+ module_eval(<<'.,.,', 'grammar.y', 24)
208
+ def _reduce_6(val, _values, result)
209
+ result = ASTNode.new :exp, :equals, [val[0], val[2]]
210
+ result
211
+ end
212
+ .,.,
213
+
214
+ module_eval(<<'.,.,', 'grammar.y', 25)
215
+ def _reduce_7(val, _values, result)
216
+ result = ASTNode.new :exp, :equals, [val[0], val[2]]
217
+ result
218
+ end
219
+ .,.,
220
+
221
+ module_eval(<<'.,.,', 'grammar.y', 26)
222
+ def _reduce_8(val, _values, result)
223
+ result = ASTNode.new :exp, :equals, [val[0], val[2]]
224
+ result
225
+ end
226
+ .,.,
227
+
228
+ module_eval(<<'.,.,', 'grammar.y', 27)
229
+ def _reduce_9(val, _values, result)
230
+ result = ASTNode.new :exp, :greaterthan, [val[0], val[2]]
231
+ result
232
+ end
233
+ .,.,
234
+
235
+ module_eval(<<'.,.,', 'grammar.y', 28)
236
+ def _reduce_10(val, _values, result)
237
+ result = ASTNode.new :exp, :lessthan, [val[0], val[2]]
238
+ result
239
+ end
240
+ .,.,
241
+
242
+ module_eval(<<'.,.,', 'grammar.y', 29)
243
+ def _reduce_11(val, _values, result)
244
+ result = ASTNode.new :exp, :match, [val[0], val[2]]
245
+ result
246
+ end
247
+ .,.,
248
+
249
+ module_eval(<<'.,.,', 'grammar.y', 30)
250
+ def _reduce_12(val, _values, result)
251
+ result = ASTNode.new :booleanop, :not, [ASTNode.new(:exp, :equals, [val[0], val[2]])]
252
+ result
253
+ end
254
+ .,.,
255
+
256
+ module_eval(<<'.,.,', 'grammar.y', 31)
257
+ def _reduce_13(val, _values, result)
258
+ result = ASTNode.new :booleanop, :not, [ASTNode.new(:exp, :equals, [val[0], val[2]])]
259
+ result
260
+ end
261
+ .,.,
262
+
263
+ module_eval(<<'.,.,', 'grammar.y', 32)
264
+ def _reduce_14(val, _values, result)
265
+ result = ASTNode.new :booleanop, :not, [ASTNode.new(:exp, :equals, [val[0], val[2]])]
266
+ result
267
+ end
268
+ .,.,
269
+
270
+ # reduce 15 omitted
271
+
272
+ module_eval(<<'.,.,', 'grammar.y', 35)
273
+ def _reduce_16(val, _values, result)
274
+ result = ASTNode.new :subquery, :resources, [val[0]]
275
+ result
276
+ end
277
+ .,.,
278
+
279
+ module_eval(<<'.,.,', 'grammar.y', 36)
280
+ def _reduce_17(val, _values, result)
281
+ result = ASTNode.new :subquery, :resources, [val[0]]
282
+ result
283
+ end
284
+ .,.,
285
+
286
+ module_eval(<<'.,.,', 'grammar.y', 37)
287
+ def _reduce_18(val, _values, result)
288
+ result = ASTNode.new :subquery, :resources, [val[0]]
289
+ result
290
+ end
291
+ .,.,
292
+
293
+ module_eval(<<'.,.,', 'grammar.y', 38)
294
+ def _reduce_19(val, _values, result)
295
+ result = ASTNode.new :subquery, :resources, [ASTNode.new(:booleanop, :and, [val[0], val[1]])]
296
+ result
297
+ end
298
+ .,.,
299
+
300
+ module_eval(<<'.,.,', 'grammar.y', 39)
301
+ def _reduce_20(val, _values, result)
302
+ result = ASTNode.new :subquery, :resources, [ASTNode.new(:booleanop, :and, [val[0], val[1]])]
303
+ result
304
+ end
305
+ .,.,
306
+
307
+ module_eval(<<'.,.,', 'grammar.y', 40)
308
+ def _reduce_21(val, _values, result)
309
+ result = ASTNode.new :subquery, :resources, [ASTNode.new(:booleanop, :and, [val[0], val[1]])]
310
+ result
311
+ end
312
+ .,.,
313
+
314
+ module_eval(<<'.,.,', 'grammar.y', 41)
315
+ def _reduce_22(val, _values, result)
316
+ result = ASTNode.new :subquery, :resources, [ASTNode.new(:booleanop, :and, [val[0], val[1], val[2]])]
317
+ result
318
+ end
319
+ .,.,
320
+
321
+ module_eval(<<'.,.,', 'grammar.y', 43)
322
+ def _reduce_23(val, _values, result)
323
+ result = ASTNode.new :resourcetype, val[0]
324
+ result
325
+ end
326
+ .,.,
327
+
328
+ module_eval(<<'.,.,', 'grammar.y', 44)
329
+ def _reduce_24(val, _values, result)
330
+ result = ASTNode.new :resourcetitle, val[1]
331
+ result
332
+ end
333
+ .,.,
334
+
335
+ module_eval(<<'.,.,', 'grammar.y', 45)
336
+ def _reduce_25(val, _values, result)
337
+ result = val[1]
338
+ result
339
+ end
340
+ .,.,
341
+
342
+ module_eval(<<'.,.,', 'grammar.y', 47)
343
+ def _reduce_26(val, _values, result)
344
+ result = ASTNode.new :string, val[0]
345
+ result
346
+ end
347
+ .,.,
348
+
349
+ module_eval(<<'.,.,', 'grammar.y', 48)
350
+ def _reduce_27(val, _values, result)
351
+ result = ASTNode.new :number, val[0]
352
+ result
353
+ end
354
+ .,.,
355
+
356
+ module_eval(<<'.,.,', 'grammar.y', 49)
357
+ def _reduce_28(val, _values, result)
358
+ result = ASTNode.new :boolean, val[0]
359
+ result
360
+ end
361
+ .,.,
362
+
363
+ def _reduce_none(val, _values, result)
364
+ val[0]
365
+ end
366
+
367
+ end # class Parser
368
+ end # module PuppetDB
@@ -0,0 +1,18 @@
1
+ class PuppetDB
2
+ module Util
3
+ def self.color(code)
4
+ colors = {:red => "",
5
+ :green => "",
6
+ :yellow => "",
7
+ :cyan => "",
8
+ :bold => "",
9
+ :reset => ""}
10
+
11
+ return colors[code] || ""
12
+ end
13
+
14
+ def self.colorize(code, msg)
15
+ "%s%s%s" % [ color(code), msg, color(:reset) ]
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,16 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "ruby-puppetdb"
3
+ s.version = %x{git describe --tags}.split('-')[0..1].join('.')
4
+ s.platform = Gem::Platform::RUBY
5
+ s.authors = ["Dan Bode", "Erik Dalén"]
6
+ s.email = ["dan@puppetlabs.com", "erik.gustav.dalen@gmail.com"]
7
+ s.homepage = "https://github.com/dalen/puppet-puppetdbquery"
8
+ s.summary = %q{Query functions for PuppetDB}
9
+ s.description = %q{A higher level query language for PuppetDB.}
10
+
11
+
12
+ s.files = `git ls-files`.split("\n")
13
+ s.test_files = `git ls-files -- {test,spec,features,examples}/*`.split("\n")
14
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
15
+ s.require_paths = ["lib"]
16
+ end
@@ -0,0 +1,4 @@
1
+ gem 'rspec', '>=2.0.0'
2
+ require 'rspec/expectations'
3
+
4
+ require 'puppetlabs_spec_helper/module_spec_helper'
@@ -0,0 +1,19 @@
1
+ #! /usr/bin/env ruby -S rspec
2
+
3
+ require 'spec_helper'
4
+
5
+ describe "the pdbfactquery function" do
6
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
7
+
8
+ it "should exist" do
9
+ Puppet::Parser::Functions.function("pdbfactquery").should == "function_pdbfactquery"
10
+ end
11
+
12
+ it "should raise a ParseError if there is less than 1 arguments" do
13
+ lambda { scope.function_pdbfactquery([]) }.should( raise_error(Puppet::ParseError))
14
+ end
15
+
16
+ it "should raise a ParseError if there are more than 2 arguments" do
17
+ lambda { scope.function_pdbfactquery([1, 2, 3]) }.should( raise_error(Puppet::ParseError))
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ #! /usr/bin/env ruby -S rspec
2
+
3
+ require 'spec_helper'
4
+
5
+ describe "the pdbnodequery_all function" do
6
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
7
+
8
+ it "should exist" do
9
+ Puppet::Parser::Functions.function("pdbnodequery_all").should == "function_pdbnodequery_all"
10
+ end
11
+
12
+ it "should raise a ParseError if there is less than 1 arguments" do
13
+ lambda { scope.function_pdbnodequery_all([]) }.should( raise_error(Puppet::ParseError))
14
+ end
15
+
16
+ it "should raise a ParseError if there are more than 2 arguments" do
17
+ lambda { scope.function_pdbnodequery_all([1, 2, 3]) }.should( raise_error(Puppet::ParseError))
18
+ end
19
+ end