foreman/app/controllers/unattended_controller.rb @ d97375e0
18738311 | Ohad Levy | class UnattendedController < ApplicationController
|
|
b4b14336 | Ohad Levy | layout nil
|
|
a98d5dcf | Ohad Levy | helper :all
|
|
6352d882 | Jochen Schalanda | before_filter :get_host_details, :allowed_to_install?, :except => [:pxe_kickstart_config, :pxe_debian_config]
|
|
before_filter :handle_ca, :except => [:jumpstart_finish, :preseed_finish, :pxe_kickstart_config, :pxe_debian_config]
|
|||
6c6713de | Ohad Levy | skip_before_filter :require_ssl, :require_login
|
|
0f77c7f2 | Ohad Levy | after_filter :set_content_type, :only => [:kickstart, :preseed, :preseed_finish,
|
|
6352d882 | Jochen Schalanda | :jumpstart_profile, :jumpstart_finish, :pxe_kickstart_config, :pxe_debian_config]
|
|
18738311 | Ohad Levy | ||
def kickstart
|
|||
d97375e0 | Ohad Levy | @dynamic = @host.diskLayout =~ /^#Dynamic/
|
|
5f75dccc | Paul Kelly | @arch = @host.architecture.name
|
|
os = @host.operatingsystem
|
|||
@osver = os.major.to_i
|
|||
@mediapath = os.mediapath @host
|
|||
c289176c | Ohad Levy | @epel = os.epel @host
|
|
5f75dccc | Paul Kelly | @yumrepo = os.yumrepo @host
|
|
0c759d7b | Ohad Levy | unattended_local "kickstart"
|
|
18738311 | Ohad Levy | end
|
|
6775117c | Ohad Levy | def jumpstart_profile
|
|
0c759d7b | Ohad Levy | unattended_local "jumpstart_profile"
|
|
6775117c | Ohad Levy | end
|
|
def jumpstart_finish
|
|||
0c759d7b | Ohad Levy | unattended_local "jumpstart_finish"
|
|
18738311 | Ohad Levy | end
|
|
def preseed
|
|||
7a481d2d | Jochen Schalanda | @preseed_path = @host.os.preseed_path @host
|
|
@preseed_server = @host.os.preseed_server @host
|
|||
0c759d7b | Ohad Levy | unattended_local "preseed"
|
|
18738311 | Ohad Levy | end
|
|
26a8190e | Ohad Levy | def preseed_finish
|
|
0c759d7b | Ohad Levy | unattended_local "preseed_finish"
|
|
26a8190e | Ohad Levy | end
|
|
d97375e0 | Ohad Levy | # this actions is called by each operatingsystem post/finish script - it notify us that the OS installation is done.
|
|
b4b14336 | Ohad Levy | def built
|
|
22924f15 | Ohad Levy | logger.info "#{controller_name}: #{@host.name} is Built!"
|
|
b4b14336 | Ohad Levy | @host.built
|
|
head(:created) and return
|
|||
end
|
|||
0f77c7f2 | Ohad Levy | def pxe_kickstart_config
|
|
@host = Host.find_by_name params[:host_id]
|
|||
prefix = @host.operatingsystem.pxe_prefix(@host.arch)
|
|||
@kernel = "#{prefix}-#{Redhat::PXEFILES[:kernel]}"
|
|||
@initrd = "#{prefix}-#{Redhat::PXEFILES[:initrd]}"
|
|||
end
|
|||
6352d882 | Jochen Schalanda | def pxe_debian_config
|
|
@host = Host.find_by_name params[:host_id]
|
|||
prefix = @host.operatingsystem.pxe_prefix(@host.arch)
|
|||
@kernel = "#{prefix}-#{Debian::PXEFILES[:kernel]}"
|
|||
@initrd = "#{prefix}-#{Debian::PXEFILES[:initrd]}"
|
|||
end
|
|||
18738311 | Ohad Levy | private
|
|
1b23d712 | Ohad Levy | # lookup for a host based on the ip address and if possible by a mac address(as sent by anaconda)
|
|
# if the host was found than its record will be in @host
|
|||
# if the host doesn't exists, it will return 404 and the requested method will not be reached.
|
|||
18738311 | Ohad Levy | def get_host_details
|
|
# find out ip info
|
|||
if params.has_key? "spoof"
|
|||
ip = params.delete("spoof")
|
|||
a79cf03f | Ohad Levy | @spoof = true
|
|
18738311 | Ohad Levy | elsif (ip = request.env['REMOTE_ADDR']) =~ /127.0.0/
|
|
ip = request.env["HTTP_X_FORWARDED_FOR"] unless request.env["HTTP_X_FORWARDED_FOR"].nil?
|
|||
end
|
|||
d97375e0 | Ohad Levy | # search for a mac address in any of the RHN provsioning headers
|
|
# this section is kickstart only relevant
|
|||
924cdd0a | Frank Sweetser | maclist = []
|
|
18738311 | Ohad Levy | unless request.env['HTTP_X_RHN_PROVISIONING_MAC_0'].nil?
|
|
d97375e0 | Ohad Levy | begin
|
|
request.env.keys.each do | header |
|
|||
maclist << request.env[header].split[1].downcase.strip if header =~ /^HTTP_X_RHN_PROVISIONING_MAC_/
|
|||
924cdd0a | Frank Sweetser | end
|
|
d97375e0 | Ohad Levy | rescue => e
|
|
logger.info "unknown RHN_PROVISIONING header #{e}"
|
|||
end
|
|||
18738311 | Ohad Levy | end
|
|
d97375e0 | Ohad Levy | # we try to match first based on the MAC, falling back to the IP
|
|
conditions = (!maclist.empty? ? {:mac => maclist} : {:ip => ip})
|
|||
286a2207 | Ohad Levy | @host = Host.find(:first, :include => [:architecture, :media, :operatingsystem, :domain], :conditions => conditions)
|
|
18738311 | Ohad Levy | if @host.nil?
|
|
924cdd0a | Frank Sweetser | logger.info "#{controller_name}: unable to find ip/mac match for #{ip}"
|
|
286a2207 | Ohad Levy | head(:not_found) and return
|
|
18738311 | Ohad Levy | end
|
|
3b828aad | Ohad Levy | if @host.operatingsystem.type.nil?
|
|
2c83f744 | Paul Kelly | # Then, for some reason, the OS has not been specialized into a Redhat or Debian class
|
|
logger.error "#{controller_name}: #{@host.name}'s operatingsytem [#{@host.operatingsystem.fullname}] has no OS family!"
|
|||
head(:conflict) and return
|
|||
end
|
|||
d97375e0 | Ohad Levy | logger.info "Found #{@host}"
|
|
18738311 | Ohad Levy | end
|
|
a79cf03f | Ohad Levy | def allowed_to_install?
|
|
d97375e0 | Ohad Levy | (@host.build or @spoof) ? true : head(:method_not_allowed)
|
|
a79cf03f | Ohad Levy | end
|
|
07723734 | Ohad Levy | # Cleans Certificate and enable autosign
|
|
a79cf03f | Ohad Levy | def handle_ca
|
|
#the reason we do it here is to minimize the amount of time it is possible to automatically get a certificate
|
|||
#through puppet.
|
|||
07723734 | Ohad Levy | ||
# we don't do anything if we are in spoof mode.
|
|||
return if @spoof
|
|||
2a1e31dc | Frank Sweetser | return false unless GW::Puppetca.clean @host.name
|
|
07723734 | Ohad Levy | return false unless GW::Puppetca.sign @host.name
|
|
a79cf03f | Ohad Levy | end
|
|
0c759d7b | Ohad Levy | ||
def unattended_local type
|
|||
render :template => "unattended/#{type}.local" if File.exists?("#{RAILS_ROOT}/app/views/unattended/#{type}.local.rhtml")
|
|||
end
|
|||
d8dd4f92 | Jon Fautley | def set_content_type
|
|
response.headers['Content-Type'] = 'text/plain' if @spoof
|
|||
end
|
|||
18738311 | Ohad Levy | end
|