ruby-puppetdb 1.6.1 → 2.0.0
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 +8 -8
- data/bin/find-nodes +34 -21
- data/lib/hiera/backend/puppetdb_backend.rb +15 -12
- data/lib/puppet/application/query.rb +10 -4
- data/lib/puppet/face/query.rb +37 -31
- data/lib/puppet/parser/functions/query_facts.rb +9 -4
- data/lib/puppet/parser/functions/query_nodes.rb +13 -8
- data/lib/puppet/parser/functions/query_resources.rb +35 -6
- data/lib/puppetdb.rb +1 -1
- data/lib/puppetdb/astnode.rb +92 -44
- data/lib/puppetdb/connection.rb +14 -69
- data/lib/puppetdb/grammar.racc +75 -40
- data/lib/puppetdb/lexer.rb +23 -4
- data/lib/puppetdb/lexer.rex +30 -24
- data/lib/puppetdb/parser.rb +245 -223
- data/lib/puppetdb/parser_helper.rb +48 -0
- data/spec/unit/puppetdb/parser_spec.rb +129 -0
- metadata +7 -28
- data/lib/puppet/parser/functions/pdbfactquery.rb +0 -31
- data/lib/puppet/parser/functions/pdbnodequery.rb +0 -38
- data/lib/puppet/parser/functions/pdbnodequery_all.rb +0 -40
- data/lib/puppet/parser/functions/pdbquery.rb +0 -41
- data/lib/puppet/parser/functions/pdbresourcequery.rb +0 -39
- data/lib/puppet/parser/functions/pdbresourcequery_all.rb +0 -37
- data/lib/puppet/parser/functions/pdbstatusquery.rb +0 -31
- data/lib/puppetdb/util.rb +0 -18
- data/spec/unit/puppet/parser/functions/pdbfactquery_spec.rb +0 -19
- data/spec/unit/puppet/parser/functions/pdbnodequery_all_spec.rb +0 -19
- data/spec/unit/puppet/parser/functions/pdbnodequery_spec.rb +0 -19
- data/spec/unit/puppet/parser/functions/pdbquery_spec.rb +0 -19
- data/spec/unit/puppet/parser/functions/pdbresourcequery_all_spec.rb +0 -19
- data/spec/unit/puppet/parser/functions/pdbresourcequery_spec.rb +0 -19
- data/spec/unit/puppet/parser/functions/pdbstatusquery_spec.rb +0 -19
- data/spec/unit/puppetdb/connection_spec.rb +0 -67
@@ -1,37 +0,0 @@
|
|
1
|
-
module Puppet::Parser::Functions
|
2
|
-
newfunction(:pdbresourcequery_all, :type => :rvalue, :doc => "\
|
3
|
-
Perform a PuppetDB resource query
|
4
|
-
|
5
|
-
The first argument is the resource query.
|
6
|
-
Second argument is optional but allows you to specify the item you want
|
7
|
-
from the returned hash.
|
8
|
-
|
9
|
-
Returns an array of hashes or array of strings if second argument is provided.
|
10
|
-
|
11
|
-
Examples:
|
12
|
-
# Return an array of hashes describing all files that are owned by root.
|
13
|
-
$ret = pdbresourcequery_all(
|
14
|
-
['and',
|
15
|
-
['=','type','File'],
|
16
|
-
['=',['parameter','owner'],'root']])
|
17
|
-
|
18
|
-
# Return an array of host names having those resources
|
19
|
-
$ret = pdbresourcequery_all(
|
20
|
-
['and',
|
21
|
-
['=','type','File'],
|
22
|
-
['=',['parameter','owner'],'root']], 'certname')") do |args|
|
23
|
-
|
24
|
-
raise(Puppet::ParseError, "pdbresourcequery_all(): Wrong number of arguments " +
|
25
|
-
"given (#{args.size} for 1 or 2)") if args.size < 1 or args.size > 2
|
26
|
-
|
27
|
-
Puppet::Parser::Functions.autoloader.load(:pdbquery) unless Puppet::Parser::Functions.autoloader.loaded?(:pdbquery)
|
28
|
-
|
29
|
-
resq, info = args
|
30
|
-
ret = function_pdbquery(['resources', resq])
|
31
|
-
if info then
|
32
|
-
ret.collect {|x| x[info]}
|
33
|
-
else
|
34
|
-
ret
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
module Puppet::Parser::Functions
|
2
|
-
newfunction(:pdbstatusquery, :type => :rvalue, :doc => "\
|
3
|
-
Perform a PuppetDB node status query
|
4
|
-
|
5
|
-
The first argument is the node to get the status for.
|
6
|
-
Second argument is optional, if specified only return that specific bit of
|
7
|
-
status, one of 'name', 'deactivated', 'catalog_timestamp' and 'facts_timestamp'.
|
8
|
-
|
9
|
-
Returns an array of hashes or a array of strings if second argument is supplied.
|
10
|
-
|
11
|
-
Examples:
|
12
|
-
# Get status for foo.example.com
|
13
|
-
pdbstatusquery('foo.example.com')
|
14
|
-
# Get catalog_timestamp for foo.example.com
|
15
|
-
pdbstatusquery('foo.example.com', 'catalog_timestamp')") do |args|
|
16
|
-
|
17
|
-
raise(Puppet::ParseError, "pdbquery(): Wrong number of arguments " +
|
18
|
-
"given (#{args.size} for 1 or 2)") if args.size < 1 or args.size > 2
|
19
|
-
|
20
|
-
Puppet::Parser::Functions.autoloader.load(:pdbquery) unless Puppet::Parser::Functions.autoloader.loaded?(:pdbquery)
|
21
|
-
|
22
|
-
node, status = args
|
23
|
-
|
24
|
-
ret = function_pdbquery(["status/nodes/#{node}"])
|
25
|
-
if status then
|
26
|
-
ret[status]
|
27
|
-
else
|
28
|
-
ret
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
data/lib/puppetdb/util.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
class PuppetDB
|
2
|
-
module Util
|
3
|
-
def self.color(code)
|
4
|
-
colors = {:red => "[31m",
|
5
|
-
:green => "[32m",
|
6
|
-
:yellow => "[33m",
|
7
|
-
:cyan => "[36m",
|
8
|
-
:bold => "[1m",
|
9
|
-
:reset => "[0m"}
|
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
|
@@ -1,19 +0,0 @@
|
|
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
|
@@ -1,19 +0,0 @@
|
|
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
|
@@ -1,19 +0,0 @@
|
|
1
|
-
#! /usr/bin/env ruby -S rspec
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe "the pdbnodequery function" do
|
6
|
-
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
|
7
|
-
|
8
|
-
it "should exist" do
|
9
|
-
Puppet::Parser::Functions.function("pdbnodequery").should == "function_pdbnodequery"
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should raise a ParseError if there is less than 1 arguments" do
|
13
|
-
lambda { scope.function_pdbnodequery([]) }.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([1, 2, 3]) }.should( raise_error(Puppet::ParseError))
|
18
|
-
end
|
19
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
#! /usr/bin/env ruby -S rspec
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe "the pdbquery function" do
|
6
|
-
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
|
7
|
-
|
8
|
-
it "should exist" do
|
9
|
-
Puppet::Parser::Functions.function("pdbquery").should == "function_pdbquery"
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should raise a ParseError if there is less than 1 arguments" do
|
13
|
-
lambda { scope.function_pdbquery([]) }.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_pdbquery([1, 2, 3]) }.should( raise_error(Puppet::ParseError))
|
18
|
-
end
|
19
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
#! /usr/bin/env ruby -S rspec
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe "the pdbresourcequery_all function" do
|
6
|
-
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
|
7
|
-
|
8
|
-
it "should exist" do
|
9
|
-
Puppet::Parser::Functions.function("pdbresourcequery_all").should == "function_pdbresourcequery_all"
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should raise a ParseError if there is less than 1 arguments" do
|
13
|
-
lambda { scope.function_pdbresourcequery_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_pdbresourcequery_all([1, 2, 3]) }.should( raise_error(Puppet::ParseError))
|
18
|
-
end
|
19
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
#! /usr/bin/env ruby -S rspec
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe "the pdbresourcequery function" do
|
6
|
-
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
|
7
|
-
|
8
|
-
it "should exist" do
|
9
|
-
Puppet::Parser::Functions.function("pdbresourcequery").should == "function_pdbresourcequery"
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should raise a ParseError if there is less than 1 arguments" do
|
13
|
-
lambda { scope.function_pdbresourcequery([]) }.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_pdbresourcequery([1, 2, 3]) }.should( raise_error(Puppet::ParseError))
|
18
|
-
end
|
19
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
#! /usr/bin/env ruby -S rspec
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe "the pdbstatusquery function" do
|
6
|
-
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
|
7
|
-
|
8
|
-
it "should exist" do
|
9
|
-
Puppet::Parser::Functions.function("pdbstatusquery").should == "function_pdbstatusquery"
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should raise a ParseError if there is less than 1 arguments" do
|
13
|
-
lambda { scope.function_pdbstatusquery([]) }.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_pdbstatusquery([1, 2, 3]) }.should( raise_error(Puppet::ParseError))
|
18
|
-
end
|
19
|
-
end
|
@@ -1,67 +0,0 @@
|
|
1
|
-
#! /usr/bin/env ruby -S rspec
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
require 'puppetdb/connection'
|
5
|
-
|
6
|
-
describe PuppetDB::Connection do
|
7
|
-
context "Query parsing" do
|
8
|
-
let(:connection) { PuppetDB::Connection.new }
|
9
|
-
it "should handle empty queries" do
|
10
|
-
connection.parse_query('').should be_nil
|
11
|
-
end
|
12
|
-
|
13
|
-
it "should handle double quoted strings" do
|
14
|
-
connection.parse_query('foo="bar"').should eq ["in", "name", ["extract", "certname", ["select-facts", ["and", ["=", "name", "foo"], ["=", "value", "bar"]]]]]
|
15
|
-
end
|
16
|
-
|
17
|
-
it "should handle single quoted strings" do
|
18
|
-
connection.parse_query('foo=\'bar\'').should eq ["in", "name", ["extract", "certname", ["select-facts", ["and", ["=", "name", "foo"], ["=", "value", "bar"]]]]]
|
19
|
-
end
|
20
|
-
|
21
|
-
it "should handle precedence" do
|
22
|
-
connection.parse_query('foo=1 or bar=2 and baz=3').should eq ["or", ["in", "name", ["extract", "certname", ["select-facts", ["and", ["=", "name", "foo"], ["=", "value", 1]]]]], ["and", ["in", "name", ["extract", "certname", ["select-facts", ["and", ["=", "name", "bar"], ["=", "value", 2]]]]], ["in", "name", ["extract", "certname", ["select-facts", ["and", ["=", "name", "baz"], ["=", "value", 3]]]]]]]
|
23
|
-
connection.parse_query('(foo=1 or bar=2) and baz=3').should eq ["and", ["or", ["in", "name", ["extract", "certname", ["select-facts", ["and", ["=", "name", "foo"], ["=", "value", 1]]]]], ["in", "name", ["extract", "certname", ["select-facts", ["and", ["=", "name", "bar"], ["=", "value", 2]]]]]], ["in", "name", ["extract", "certname", ["select-facts", ["and", ["=", "name", "baz"], ["=", "value", 3]]]]]]
|
24
|
-
end
|
25
|
-
|
26
|
-
it "should parse resource queries with only type name" do
|
27
|
-
connection.parse_query('file').should eq ["in", "name", ["extract", "certname", ["select-resources", ["and", ["=", "exported", false], ["=", "type", "File"]]]]]
|
28
|
-
end
|
29
|
-
|
30
|
-
it "should parse resource queries with only title" do
|
31
|
-
connection.parse_query('[foo]').should eq ["in", "name", ["extract", "certname", ["select-resources", ["and", ["=", "exported", false], ["=", "title", "foo"]]]]]
|
32
|
-
end
|
33
|
-
|
34
|
-
it "should parse resource queries with only parameters" do
|
35
|
-
connection.parse_query('{foo=bar}').should eq ["in", "name", ["extract", "certname", ["select-resources", ["and", ["=", "exported", false], ["=", ["parameter", "foo"], "bar"]]]]]
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should parse resource queries for exported resources" do
|
39
|
-
connection.parse_query('@@file').should eq ["in", "name", ["extract", "certname", ["select-resources", ["and", ["=", "exported", true], ["=", "type", "File"]]]]]
|
40
|
-
end
|
41
|
-
|
42
|
-
it "should parse resource queries with type, title and parameters" do
|
43
|
-
connection.parse_query('file[foo]{bar=baz}').should eq ["in", "name", ["extract", "certname", ["select-resources", ["and", ["=", "exported", false], ["=", "type", "File"], ["=", "title", "foo"], ["=", ["parameter", "bar"], "baz"]]]]]
|
44
|
-
end
|
45
|
-
|
46
|
-
it "should parse resource queries with tags" do
|
47
|
-
connection.parse_query('file[foo]{tag=baz}').should eq ["in", "name", ["extract", "certname", ["select-resources", ["and", ["=", "exported", false], ["=", "type", "File"], ["=", "title", "foo"], ["=", "tag", "baz"]]]]]
|
48
|
-
end
|
49
|
-
|
50
|
-
it "should handle precedence within resource parameter queries" do
|
51
|
-
connection.parse_query('{foo=1 or bar=2 and baz=3}').should eq ["in", "name", ["extract", "certname", ["select-resources", ["and", ["=", "exported", false], ["or", ["=", ["parameter", "foo"], 1], ["and", ["=", ["parameter", "bar"], 2], ["=", ["parameter", "baz"], 3]]]]]]]
|
52
|
-
connection.parse_query('{(foo=1 or bar=2) and baz=3}').should eq ["in", "name", ["extract", "certname", ["select-resources", ["and", ["=", "exported", false], ["or", ["=", ["parameter", "foo"], 1], ["=", ["parameter", "bar"], 2]], ["=", ["parameter", "baz"], 3]]]]]
|
53
|
-
end
|
54
|
-
|
55
|
-
it "should capitalize class names" do
|
56
|
-
connection.parse_query('class[foo::bar]').should eq ["in", "name", ["extract", "certname", ["select-resources", ["and", ["=", "exported", false], ["=", "type", "Class"], ["=", "title", "Foo::Bar"]]]]]
|
57
|
-
end
|
58
|
-
|
59
|
-
it "should parse resource queries with regeexp title matching" do
|
60
|
-
connection.parse_query('[~foo]').should eq ["in", "name", ["extract", "certname", ["select-resources", ["and", ["=", "exported", false], ["~", "title", "foo"]]]]]
|
61
|
-
end
|
62
|
-
|
63
|
-
it "should be able to negate expressions" do
|
64
|
-
connection.parse_query('not foo=bar').should eq ["not", ["in", "name", ["extract", "certname", ["select-facts", ["and", ["=", "name", "foo"], ["=", "value", "bar"]]]]]]
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|