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
|
# File 'app/controllers/specifictemplate_controller.rb', line 21
def update
return render(:plain => 'Host not in build mode') unless @host and @host.build?
template_name = params[:template_name]
return remove unless template_name
template = ProvisioningTemplate.find_by_name(template_name)
raise Foreman::Exception.new(N_("Template '%s' was not found"), template_name) unless template
kind = template.template_kind.name
raise Foreman::Exception.new(N_("%s does not support templates of type %s"), @host.operatingsystem, kind) unless @host.operatingsystem.template_kinds.include?(kind)
content = @host.render_template template
raise Foreman::Exception.new(N_("Template '%s' didn't render correctly"), template.name) unless content
logger.info "Deploying requested #{kind} configuration for #{@host.name} from template '#{template.name}'"
@host.interfaces.each do |iface|
next unless iface.tftp? || iface.tftp6?
iface.send(:unique_feasible_tftp_proxies).each do |proxy|
mac_addresses = iface.try(:mac_addresses_for_tftp) || [iface.mac]
mac_addresses.each do |mac_addr|
proxy.set(kind, mac_addr, :pxeconfig => content)
end
end
end
render :plain => ''
rescue => e
render_error(
:message => 'Failed to set PXE to template %{template_name}: %{error}',
:status => :error,
:template_name => template_name,
:error => e
)
end
|