Class: Puppet::Transaction::AdditionalResourceGenerator Private

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet/transaction/additional_resource_generator.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Adds additional resources to the catalog and relationship graph that are generated by existing resources. There are two ways that a resource can generate additional resources, either through the #generate method or the #eval_generate method.

Instance Method Summary collapse

Constructor Details

#initialize(catalog, relationship_graph, prioritizer) ⇒ AdditionalResourceGenerator

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of AdditionalResourceGenerator.



8
9
10
11
12
# File 'lib/puppet/transaction/additional_resource_generator.rb', line 8

def initialize(catalog, relationship_graph, prioritizer)
  @catalog = catalog
  @relationship_graph = relationship_graph
  @prioritizer = prioritizer
end

Instance Method Details

#eval_generate(resource) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Raises:



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/puppet/transaction/additional_resource_generator.rb', line 34

def eval_generate(resource)
  return false unless resource.respond_to?(:eval_generate)
  raise Puppet::DevError,"Depthfirst resources are not supported by eval_generate" if resource.depthfirst?
  begin
    generated = replace_duplicates_with_catalog_resources(resource.eval_generate)
    return false if generated.empty?
  rescue => detail
    resource.log_exception(detail, "Failed to generate additional resources using 'eval_generate': #{detail}")
    return false
  end
  add_resources(generated, resource)

  made = Hash[generated.map(&:name).zip(generated)]
  contain_generated_resources_in(resource, made)
  connect_resources_to_ancestors(resource, made)

  true
end

#generate_additional_resources(resource) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/puppet/transaction/additional_resource_generator.rb', line 14

def generate_additional_resources(resource)
  return unless resource.respond_to?(:generate)
  begin
    generated = resource.generate
  rescue => detail
    resource.log_exception(detail, "Failed to generate additional resources using 'generate': #{detail}")
  end
  return unless generated
  generated = [generated] unless generated.is_a?(Array)
  generated.collect do |res|
    @catalog.resource(res.ref) || res
  end.each do |res|
    priority = @prioritizer.generate_priority_contained_in(resource, res)
    add_resource(res, resource, priority)

    add_conditional_directed_dependency(resource, res)
    generate_additional_resources(res)
  end
end