summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2007-07-18 17:32:46 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2007-07-18 17:32:46 +0000
commit53a469c0000eb1f487eab456c0986d427d714bd7 (patch)
treedd0f8c72a73f18371f50fa5559bb43d10b7301b5 /lib
parentd5569bcf30ad40b1780c1550368455127114cdd2 (diff)
Fixing #703, mostly. You still cannot do multi-condition queries, but you can at least query against any parameter, and matching any value is sufficient for a match, so the tags work fine.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2705 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib')
-rw-r--r--lib/puppet/parser/ast/collexpr.rb16
-rw-r--r--lib/puppet/parser/collector.rb10
-rw-r--r--lib/puppet/rails/resource.rb5
3 files changed, 19 insertions, 12 deletions
diff --git a/lib/puppet/parser/ast/collexpr.rb b/lib/puppet/parser/ast/collexpr.rb
index f69b2e92e..e9f2e63e0 100644
--- a/lib/puppet/parser/ast/collexpr.rb
+++ b/lib/puppet/parser/ast/collexpr.rb
@@ -43,7 +43,9 @@ class CollExpr < AST::Branch
end
case @oper
- when "and", "or": oper = @oper.upcase
+ when "and", "or":
+ raise Puppet::ParseError, "Puppet does not currently support collecting exported resources with more than one condition"
+ #oper = @oper.upcase
when "==": oper = "="
else
oper = @oper
@@ -54,17 +56,13 @@ class CollExpr < AST::Branch
if str1 == "title"
str = "title #{oper} '#{str2}'"
else
- unless self.form == :virtual or str1 == "title"
- parsefail "Collection from the database only supports " +
- "title matching currently"
- end
- str = "rails_parameters.name = '#{str1}' and " +
- "rails_parameters.value #{oper} '#{str2}'"
+ str = "param_values.value #{oper} '#{str2}' and " +
+ "param_names.name = '#{str1}'"
end
else
- str = [str1, oper, str2].join(" ")
+ str = "(%s) %s (%s)" % [str1, oper, str2]
end
-
+
return str, code
end
diff --git a/lib/puppet/parser/collector.rb b/lib/puppet/parser/collector.rb
index 868946c8c..62eafdd65 100644
--- a/lib/puppet/parser/collector.rb
+++ b/lib/puppet/parser/collector.rb
@@ -22,9 +22,13 @@ class Puppet::Parser::Collector
end
host = Puppet::Rails::Host.find_by_name(@scope.host)
- args = {}
+ args = {:include => {:param_values => :param_name}}
+ args[:conditions] = "restype = '%s'" % [@type]
+ if @equery
+ args[:conditions] += " AND (%s)" % [@equery]
+ end
if host
- args[:conditions] = "host_id != #{host.id}"
+ args[:conditions] = "host_id != %s AND %s" % [host.id, args[:conditions]]
else
#Puppet.info "Host %s is uninitialized" % @scope.host
end
@@ -33,7 +37,7 @@ class Puppet::Parser::Collector
# and such, we'll need to vary the conditions, but this works with no
# attributes, anyway.
time = Puppet::Util.thinmark do
- Puppet::Rails::Resource.find_all_by_restype_and_exported(@type, true,
+ Puppet::Rails::Resource.find(:all, @type, true,
args
).each do |obj|
if resource = export_resource(obj)
diff --git a/lib/puppet/rails/resource.rb b/lib/puppet/rails/resource.rb
index 233982ed9..19aeb9205 100644
--- a/lib/puppet/rails/resource.rb
+++ b/lib/puppet/rails/resource.rb
@@ -106,7 +106,12 @@ class Puppet::Rails::Resource < ActiveRecord::Base
hash[:source] = scope.source
obj = Puppet::Parser::Resource.new(hash)
+ names = []
self.param_names.each do |pname|
+ # We can get the same name multiple times because of how the
+ # db layout works.
+ next if names.include?(pname.name)
+ names << pname.name
obj.set(pname.to_resourceparam(self, scope.source))
end