Class: SpecifictemplateController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/specifictemplate_controller.rb

Constant Summary collapse

FILTERS =

Skip default filters for specific template actions

[
  :require_login,
  :session_expiry,
  :update_activity_time,
  :set_taxonomy,
  :authorize,
  :verify_authenticity_token
].freeze

Instance Method Summary collapse

Instance Method Details

#removeObject



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'app/controllers/specifictemplate_controller.rb', line 62

def remove
  logger.info "Resetting forced TFTP configuration for #{@host.name}"

  # All you need to do to return to proper TFTP settings
  @host.interfaces.each do |iface|
    next unless iface.managed

    iface.send :rebuild_tftp
  end

  render :plain => ''
rescue => e
  render_error(
    :message => 'Failed to reset PXE for host %{host}: %{error}',
    :status => :error,
    :host => @host,
    :error => e
  )
end

#updateObject



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?

  # TODO? Detect PXELinux/PXEGrub/PXEGrub2/iPXE, @host.pxe_loader.split.first maybe
  # Would mean templates could be provided with 'template_name=default local boot'
  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

  # TODO; Check that the template is of the correct PXE type, not just that the OS
  # allows using that type. Don't want to deploy PXELinux on a PXEGrub2 host.
  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