Project

General

Profile

Feature #284 ยป 0001-Fixes-284-Use-MAC-address-if-IP-doesn-t-exist-when-t.patch

Ohad Levy, 10/28/2010 05:17 PM

View differences:

app/controllers/unattended_controller.rb
:jumpstart_profile, :jumpstart_finish, :pxe_kickstart_config, :pxe_debian_config]
def kickstart
logger.info "#{controller_name}: Kickstart host #{@host.name}"
@dynamic = @host.diskLayout=~/^#Dynamic/
@dynamic = @host.diskLayout =~ /^#Dynamic/
@arch = @host.architecture.name
os = @host.operatingsystem
@osver = os.major.to_i
......
unattended_local "preseed_finish"
end
# this actions is called by each operatingsystem post/finish script - it notify us that the OS installation is done.
# this actions is called by each operatingsystem post/finish script - it notify us that the OS installation is done.
def built
logger.info "#{controller_name}: #{@host.name} is Built!"
@host.built
......
ip = request.env["HTTP_X_FORWARDED_FOR"] unless request.env["HTTP_X_FORWARDED_FOR"].nil?
end
# search for a mac address in any of the RHN provsioning headers
# this section is kickstart only relevant
maclist = []
maccond = "mac in ("
unless request.env['HTTP_X_RHN_PROVISIONING_MAC_0'].nil?
request.env.keys.each { | header |
if header =~ /^HTTP_X_RHN_PROVISIONING_MAC_/ then
maccond << "?, "
maclist << request.env[header].split[1].downcase.strip
begin
request.env.keys.each do | header |
maclist << request.env[header].split[1].downcase.strip if header =~ /^HTTP_X_RHN_PROVISIONING_MAC_/
end
}
rescue => e
logger.info "unknown RHN_PROVISIONING header #{e}"
end
end
maccond.sub!(/, $/, ')')
conditions = (ip and (!maclist.empty?)) ? ["ip = ? and " + maccond, ip, *maclist] : ["ip = ?",ip];
logger.info "#{controller_name}: conditions string: " + conditions.to_s
# we try to match first based on the MAC, falling back to the IP
conditions = (!maclist.empty? ? {:mac => maclist} : {:ip => ip})
@host = Host.find(:first, :include => [:architecture, :media, :operatingsystem, :domain], :conditions => conditions)
if @host.nil?
logger.info "#{controller_name}: unable to find ip/mac match for #{ip}"
......
logger.error "#{controller_name}: #{@host.name}'s operatingsytem [#{@host.operatingsystem.fullname}] has no OS family!"
head(:conflict) and return
end
logger.info "Found #{@host}"
end
def allowed_to_install?
@host.build or @spoof ? true : head(:method_not_allowed)
(@host.build or @spoof) ? true : head(:method_not_allowed)
end
# Cleans Certificate and enable autosign
app/models/host.rb
# maybe these should be moved to the common parameters, leaving them in for now
param["puppetmaster"] = puppetmaster
param["domainname"] = domain.fullname unless domain.nil? or domain.fullname.nil?
if SETTINGS[:ignore_puppet_facts_for_provisioning]
param["ip"] = ip
param["mac"] = mac
end
param.update self.params
info_hash = {}
......
end
def populateFieldsFromFacts
self.mac = fv(:macaddress)
self.ip = fv(:ipaddress) if ip.nil?
unless SETTINGS[:ignore_puppet_facts_for_provisioning]
self.mac = fv(:macaddress)
self.ip = fv(:ipaddress) if ip.nil?
end
self.domain = Domain.find_or_create_by_name fv(:domain) unless fv(:domain).empty?
# On solaris architecture fact is harwareisa
if myarch=fv(:architecture) || fv(:hardwareisa)
self.arch=Architecture.find_or_create_by_name myarch unless myarch.empty?
end
# by default, puppet doesnt store an env name in the database
env=fv(:environment) || "production"
env=fv(:environment) || SETTINGS[:default_puppet_environment] || "production"
self.environment ||= Environment.find_or_create_by_name env
os_name = fv(:operatingsystem)
    (1-1/1)