Skip to content
Snippets Groups Projects
Verified Commit 595f5989 authored by Alexander Olofsson's avatar Alexander Olofsson
Browse files

Add CSR render endpoint, to ease use in unattend

parent 19f8ee17
No related branches found
No related tags found
No related merge requests found
module ForemanWds module ForemanWds
module UnattendedControllerExtensions module UnattendedControllerExtensions
def host_template def host_template
return super unless params[:kind] == 'wds_localboot' return wds_render_csr if params[:kind] == 'csr_attributes.yaml'
return wds_deploy_localboot if params[:kind] == 'wds_localboot'
begin super
iface = @host.provision_interface end
# Deploy regular DHCP and local boot TFTP def load_template_vars
@host.provision_method = 'build' super unless params[:kind] == 'wds_localboot'
@host.build = false end
iface.send :rebuild_tftp
iface.send :rebuild_dhcp private
render inline: "Success. Local boot template was deployed successfully.\n" def wds_render_csr
rescue StandardError => e return render(:plain => 'Host not in build mode') unless @host and @host.build?
message = format('Failed to set local boot template: %{error}', error: e)
logger.error message template = ProvisioningTemplate.find_by_name('csr_attributes.yaml')
render text: message, status: :error, content_type: 'text/plain'
end content = @host.render_template template: template
raise Foreman::Exception.new(N_("Template '%s' didn't render correctly"), template.name) unless content
render plain: content
end
def wds_deploy_localboot
return render(:plain => 'Host not in build mode') unless @host and @host.build?
iface = @host.provision_interface
# Deploy regular DHCP and local boot TFTP
@host.provision_method = 'build'
@host.build = false
iface.send :rebuild_tftp
iface.send :rebuild_dhcp
render inline: "Success. Local boot template was deployed successfully.\n"
rescue StandardError => e
message = format('Failed to set local boot template: %{error}', error: e)
logger.error message
render text: message, status: :error, content_type: 'text/plain'
end end
end end
end end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment