Class: UnattendedController

Inherits:
ApplicationController show all
Includes:
Foreman::Controller::TemplateRendering
Defined in:
app/controllers/unattended_controller.rb

Constant Summary collapse

MAX_BUILT_BODY =

Maximum size of built/failed request body accepted to prevent DoS (in bytes)

65535

Instance Attribute Summary

Attributes inherited from ApplicationController

#original_search_parameter

Instance Method Summary collapse

Methods inherited from ApplicationController

#api_request?, #current_user, parameter_filter_context, #resource_path, #welcome

Methods included from ApplicationShared

#current_permission, #find_default_taxonomy, #find_session_taxonomy, #scope_by_resource_id, #set_current_taxonomy, #set_current_user, #set_taxonomy, #store_default_taxonomy, #store_taxonomy

Methods included from FindCommon

#controller_permission, #find_resource, #resource_class, #resource_class_for, #resource_finder, #resource_name, #resource_scope, #scope_for

Methods included from Foreman::ThreadSession::Cleaner

#clear_thread

Methods included from Foreman::Controller::Timezone

#set_timezone

Methods included from Foreman::Controller::TopbarSweeper

#set_topbar_sweeper_controller

Methods included from Foreman::Controller::Session

#backup_session_content, #expire_session, #ignore_api_request?, #session_expiry, #set_activity_time, #update_activity_time

Methods included from Foreman::Controller::Authentication

#authenticate, #authorized, #available_sso, #check_user_enabled, #is_admin?, #path_to_authenticate, #require_login

Methods included from Foreman::Controller::MigrationChecker

needs_migration?

Instance Method Details

#builtObject


21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/unattended_controller.rb', line 21

def built
  return unless verify_found_host
  return head(:method_not_allowed) unless allowed_to_install?

  logger.info "#{controller_name}: #{@host.name} is built!"
  # Clear possible previous errors
  @host.build_errors = nil
  update_ip if Setting[:update_ip_from_built_request]
  head(@host.built ? :created : :conflict)
end

#failedObject


32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/controllers/unattended_controller.rb', line 32

def failed
  return unless verify_found_host
  return head(:method_not_allowed) unless allowed_to_install?
  return if preview? || !@host.build

  logger.warn "#{controller_name}: #{@host.name} build failed!"
  @host.build_errors = request.body.read(MAX_BUILT_BODY)&.encode('utf-8', invalid: :replace, undef: :replace, replace: '_')
  body_length = @host.build_errors.try(:size) || 0
  @host.build_errors += "\n\nOutput trimmed\n" if body_length >= MAX_BUILT_BODY
  logger.warn { "Log lines from the OS installer:\n#{@host.build_errors}" }
  head(@host.built ? :created : :conflict)
end

#host_templateObject

Generate an action for each template kind i.e. /unattended/provision will render the provisioning template for the requesting host


57
58
59
60
61
62
63
64
65
66
67
68
# File 'app/controllers/unattended_controller.rb', line 57

def host_template
  kind = params[:kind]
  return head(:not_found) unless kind.present?

  return if render_ipxe_template

  return unless verify_found_host
  return head(:method_not_allowed) unless allowed_to_install?
  (handle_realm || return) if kind == 'provision'

  render_provisioning_template(kind)
end

#hostgroup_templateObject


45
46
47
48
49
50
51
52
53
# File 'app/controllers/unattended_controller.rb', line 45

def hostgroup_template
  return head(:not_found) unless (params.has_key?("id") && params.has_key?(:hostgroup))

  template = ProvisioningTemplate.find_by_name(params['id'].to_s)
  @host = Hostgroup.find_by_title(params['hostgroup'].to_s)
  return head(:not_found) unless template && @host

  safe_render(template)
end