Class: Puppet::Parser::Collector
- Defined in:
- lib/vendor/puppet/parser/collector.rb
Overview
An object that collects stored objects from the central cache and returns them to the current host, yo.
Instance Attribute Summary collapse
-
#collected ⇒ Object
Returns the value of attribute collected.
-
#equery ⇒ Object
Returns the value of attribute equery.
-
#form ⇒ Object
Returns the value of attribute form.
-
#overrides ⇒ Object
Returns the value of attribute overrides.
-
#resources ⇒ Object
Returns the value of attribute resources.
-
#scope ⇒ Object
Returns the value of attribute scope.
-
#type ⇒ Object
Returns the value of attribute type.
-
#vquery ⇒ Object
Returns the value of attribute vquery.
Instance Method Summary collapse
-
#add_override(hash) ⇒ Object
add a resource override to the soon to be exported/realized resources.
-
#evaluate ⇒ Object
Call the collection method, mark all of the returned objects as non-virtual, optionally applying parameter overrides.
-
#initialize(scope, type, equery, vquery, form) ⇒ Collector
constructor
A new instance of Collector.
Constructor Details
#initialize(scope, type, equery, vquery, form) ⇒ Collector
Returns a new instance of Collector.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/vendor/puppet/parser/collector.rb', line 67 def initialize(scope, type, equery, vquery, form) @scope = scope @vquery = vquery @equery = equery # initialisation @collected = {} # Canonize the type @type = Puppet::Resource.new(type, "whatever").type unless [:exported, :virtual].include?(form) raise ArgumentError, "Invalid query form #{form}" end @form = form end |
Instance Attribute Details
#collected ⇒ Object
Returns the value of attribute collected.
4 5 6 |
# File 'lib/vendor/puppet/parser/collector.rb', line 4 def collected @collected end |
#equery ⇒ Object
Returns the value of attribute equery.
4 5 6 |
# File 'lib/vendor/puppet/parser/collector.rb', line 4 def equery @equery end |
#form ⇒ Object
Returns the value of attribute form.
4 5 6 |
# File 'lib/vendor/puppet/parser/collector.rb', line 4 def form @form end |
#overrides ⇒ Object
Returns the value of attribute overrides.
4 5 6 |
# File 'lib/vendor/puppet/parser/collector.rb', line 4 def overrides @overrides end |
#resources ⇒ Object
Returns the value of attribute resources.
4 5 6 |
# File 'lib/vendor/puppet/parser/collector.rb', line 4 def resources @resources end |
#scope ⇒ Object
Returns the value of attribute scope.
4 5 6 |
# File 'lib/vendor/puppet/parser/collector.rb', line 4 def scope @scope end |
#type ⇒ Object
Returns the value of attribute type.
4 5 6 |
# File 'lib/vendor/puppet/parser/collector.rb', line 4 def type @type end |
#vquery ⇒ Object
Returns the value of attribute vquery.
4 5 6 |
# File 'lib/vendor/puppet/parser/collector.rb', line 4 def vquery @vquery end |
Instance Method Details
#add_override(hash) ⇒ Object
add a resource override to the soon to be exported/realized resources
85 86 87 88 89 90 |
# File 'lib/vendor/puppet/parser/collector.rb', line 85 def add_override(hash) raise ArgumentError, "Exported resource try to override without parameters" unless hash[:parameters] # schedule an override for an upcoming collection @overrides = hash end |
#evaluate ⇒ Object
Call the collection method, mark all of the returned objects as non-virtual, optionally applying parameter overrides. The collector can also delete himself from the compiler if there is no more resources to collect (valid only for resource fixed-set collector which get their resources from collect_resources
and not from the catalog)
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/vendor/puppet/parser/collector.rb', line 11 def evaluate # Shortcut if we're not using storeconfigs and they're trying to collect # exported resources. if form == :exported and Puppet[:storeconfigs] != true Puppet.warning "Not collecting exported resources without storeconfigs" return false end if self.resources unless objects = collect_resources and ! objects.empty? return false end else method = "collect_#{@form.to_s}" objects = send(method).each do |obj| obj.virtual = false end return false if objects.empty? end # we have an override for the collected resources if @overrides and !objects.empty? # force the resource to be always child of any other resource overrides[:source].(:child_of?) do true end # tell the compiler we have some override for him unless we already # overrided those resources objects.each do |res| unless @collected.include?(res.ref) newres = Puppet::Parser::Resource. new(res.type, res.title, :parameters => overrides[:parameters], :file => overrides[:file], :line => overrides[:line], :source => overrides[:source], :scope => overrides[:scope]) scope.compiler.add_override(newres) end end end # filter out object that this collector has previously found. objects.reject! { |o| @collected.include?(o.ref) } return false if objects.empty? # keep an eye on the resources we have collected objects.inject(@collected) { |c,o| c[o.ref]=o; c } # return our newly collected resources objects end |