Class: Puppet::Resource::Catalog::StaticCompiler
Constant Summary
Constants included
from Util
Util::AbsolutePathPosix, Util::AbsolutePathWindows
Constants included
from Util::Docs
Util::Docs::HEADER_LEVELS
Instance Attribute Summary
Attributes included from Util::Docs
#doc, #nodoc
Instance Method Summary
collapse
-
#add_children(host, catalog, resource, file) ⇒ Object
-
#compiler ⇒ Object
-
#find(request) ⇒ Object
-
#find_and_replace_metadata(host, resource, file) ⇒ Object
-
#get_child_resources(host, catalog, resource, file) ⇒ Object
-
#remove_existing_resources(children, catalog) ⇒ Object
-
#replace_metadata(host, resource, metadata) ⇒ Object
-
#store_content(resource) ⇒ Object
abstract_terminus?, const2name, #indirection, indirection_name, inherited, #initialize, mark_as_abstract_terminus, #model, model, #name, name2const, register_terminus_class, terminus_class, terminus_classes, #terminus_type
#instance_docs, #instance_hash, #instance_load, #instance_loader, #instance_loading?, #loaded_instance, #loaded_instances
Methods included from Util
absolute_path?, activerecord_version, benchmark, binread, chuser, classproxy, #execfail, #execpipe, execute, execute_posix, execute_windows, logmethods, memory, path_to_uri, proxy, replace_file, safe_posix_fork, symbolize, symbolizehash, symbolizehash!, synchronize_on, thinmark, #threadlock, uri_to_path, wait_for_output, which, withumask
#get_posix_field, #gid, #idfield, #methodbyid, #methodbyname, #search_posix_field, #uid
Methods included from Util::Docs
#desc, #dochook, #doctable, #markdown_definitionlist, #markdown_header, #nodoc?, #pad, scrub
Instance Method Details
#add_children(host, catalog, resource, file) ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/vendor/puppet/indirector/catalog/static_compiler.rb', line 60
def add_children(host, catalog, resource, file)
file = resource.to_ral
children = get_child_resources(host, catalog, resource, file)
remove_existing_resources(children, catalog)
children.each do |name, res|
catalog.add_resource res
catalog.add_edge(resource, res)
end
end
|
6
7
8
|
# File 'lib/vendor/puppet/indirector/catalog/static_compiler.rb', line 6
def compiler
@compiler ||= indirection.terminus(:compiler)
end
|
#find(request) ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/vendor/puppet/indirector/catalog/static_compiler.rb', line 10
def find(request)
return nil unless catalog = compiler.find(request)
raise "Did not get catalog back" unless catalog.is_a?(model)
catalog.resources.find_all { |res| res.type == "File" }.each do |resource|
next unless source = resource[:source]
next unless source =~ /^puppet:/
file = resource.to_ral
if file.recurse?
add_children(request.key, catalog, resource, file)
else
find_and_replace_metadata(request.key, resource, file)
end
end
catalog
end
|
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/vendor/puppet/indirector/catalog/static_compiler.rb', line 30
def find_and_replace_metadata(host, resource, file)
newsource = file[:source][0].sub("puppet:///", "")
file[:source][0] = newsource
raise "Could not get metadata for #{resource[:source]}" unless metadata = file.parameter(:source).metadata
replace_metadata(host, resource, metadata)
end
|
#get_child_resources(host, catalog, resource, file) ⇒ Object
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
# File 'lib/vendor/puppet/indirector/catalog/static_compiler.rb', line 73
def get_child_resources(host, catalog, resource, file)
sourceselect = file[:sourceselect]
children = {}
source = resource[:source]
total = file[:source].collect do |source|
next unless result = file.perform_recursion(source)
return if top = result.find { |r| r.relative_path == "." } and top.ftype != "directory"
result.each { |data| data.source = "#{source}/#{data.relative_path}" }
break result if result and ! result.empty? and sourceselect == :first
result
end.flatten
unless sourceselect == :first
found = []
total.reject! do |data|
result = found.include?(data.relative_path)
found << data.relative_path unless found.include?(data.relative_path)
result
end
end
total.each do |meta|
if meta.relative_path == "."
replace_metadata(host, resource, meta)
next
end
children[meta.relative_path] ||= Puppet::Resource.new(:file, File.join(file[:path], meta.relative_path))
children[meta.relative_path][:source] = source + "/" + meta.relative_path
replace_metadata(host, children[meta.relative_path], meta)
end
children
end
|
#remove_existing_resources(children, catalog) ⇒ Object
114
115
116
117
118
|
# File 'lib/vendor/puppet/indirector/catalog/static_compiler.rb', line 114
def remove_existing_resources(children, catalog)
existing_names = catalog.resources.collect { |r| r.to_s }
both = (existing_names & children.keys).inject({}) { |hash, name| hash[name] = true; hash }
both.each { |name| children.delete(name) }
end
|
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/vendor/puppet/indirector/catalog/static_compiler.rb', line 42
def replace_metadata(host, resource, metadata)
[:mode, :owner, :group].each do |param|
resource[param] ||= metadata.send(param)
end
resource[:ensure] = metadata.ftype
if metadata.ftype == "file"
unless resource[:content]
resource[:content] = metadata.checksum
resource[:checksum] = metadata.checksum_type
end
end
store_content(resource) if resource[:ensure] == "file"
old_source = resource.delete(:source)
Puppet.info "Metadata for #{resource} in catalog for '#{host}' added from '#{old_source}'"
end
|
#store_content(resource) ⇒ Object
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
# File 'lib/vendor/puppet/indirector/catalog/static_compiler.rb', line 120
def store_content(resource)
@summer ||= Object.new
@summer.extend(Puppet::Util::Checksums)
type = @summer.sumtype(resource[:content])
sum = @summer.sumdata(resource[:content])
if Puppet::FileBucket::File.indirection.find("#{type}/#{sum}")
Puppet.info "Content for '#{resource[:source]}' already exists"
else
Puppet.info "Storing content for source '#{resource[:source]}'"
content = Puppet::FileServing::Content.indirection.find(resource[:source])
file = Puppet::FileBucket::File.new(content.content)
Puppet::FileBucket::File.indirection.save(file)
end
end
|