Project

General

Profile

0001-Fixes-178-Automate-populating-the-TFTP-directory.patch

Ohad Levy, 10/17/2010 09:11 AM

View differences:

app/controllers/hosts_controller.rb
7 7
    :select_multiple_hostgroup, :select_multiple_environment, :multiple_parameters, :multiple_destroy,
8 8
    :multiple_enable, :multiple_disable, :submit_multiple_disable, :submit_multiple_enable]
9 9
  before_filter :find_host, :only => %w[show edit update destroy puppetrun setBuild cancelBuild report
10
    reports facts storeconfig_klasses clone externalNodes]
10
    reports facts storeconfig_klasses clone externalNodes pxe_config]
11 11

  
12 12
  helper :hosts, :reports
13 13

  
......
228 228
    end
229 229
  end
230 230

  
231
  def pxe_config
232
    redirect_to(:controller => "unattended", :action => "pxe_#{@host.operatingsystem.pxe_type}_config", :host_id => @host) if @host
233
  end
234

  
231 235
  def storeconfig_klasses
232 236
  end
233 237

  
app/controllers/operatingsystems_controller.rb
54 54
    redirect_to operatingsystems_url
55 55
  end
56 56

  
57
  def bootfiles
58
    media = Media.find_by_name(params[:media])
59
    arch =  Architecture.find_by_name(params[:architecture])
60
    respond_to do |format|
61
      format.json { render :json => @operatingsystem.pxe_files(media, arch)}
62
    end
63
  rescue => e
64
    respond_to do |format|
65
      format.json { render :json => e.to_s, :status => :unprocessable_entity }
66
    end
67
  end
68

  
57 69
  private
58 70
  def find_os
59 71
    @operatingsystem = Operatingsystem.find(params[:id])
app/controllers/unattended_controller.rb
1 1
class UnattendedController < ApplicationController
2 2
  layout nil
3 3
  helper :all
4
  before_filter :get_host_details, :allowed_to_install?
5
  before_filter :handle_ca, :except => [:jumpstart_finish, :preseed_finish]
4
  before_filter :get_host_details, :allowed_to_install?, :except => :pxe_kickstart_config
5
  before_filter :handle_ca, :except => [:jumpstart_finish, :preseed_finish, :pxe_kickstart_config]
6 6
  skip_before_filter :require_ssl, :require_login
7
  after_filter :set_content_type, :only => [:kickstart, :preseed, :preseed_finish, :jumpstart_profile, :jumpstart_finish]
7
  after_filter :set_content_type, :only => [:kickstart, :preseed, :preseed_finish,
8
    :jumpstart_profile, :jumpstart_finish, :pxe_kickstart_config]
8 9

  
9 10
  def kickstart
10 11
    logger.info "#{controller_name}: Kickstart host #{@host.name}"
......
43 44
    head(:created) and return
44 45
  end
45 46

  
47
  def pxe_kickstart_config
48
    @host = Host.find_by_name params[:host_id]
49
    prefix = @host.operatingsystem.pxe_prefix(@host.arch)
50
    @kernel = "#{prefix}-#{Redhat::PXEFILES[:kernel]}"
51
    @initrd = "#{prefix}-#{Redhat::PXEFILES[:initrd]}"
52
  end
53

  
46 54
  private
47 55
  # lookup for a host based on the ip address and if possible by a mac address(as sent by anaconda)
48 56
  # if the host was found than its record will be in @host
app/models/operatingsystem.rb
43 43

  
44 44
  def media_uri host, url = nil
45 45
    url ||= host.media.path
46
    URI.parse(url.gsub('$arch',    host.architecture.name).
47
                  gsub('$major',   host.os.major).
48
                  gsub('$minor',   host.os.minor).
49
                  gsub('$version', [ host.os.major, host.os.minor ].compact.join('.'))
46
    media_vars_to_uri(url, host.architecture.name, host.os)
47
  end
48

  
49
  def media_vars_to_uri (url, arch, os)
50
    URI.parse(url.gsub('$arch',  arch).
51
              gsub('$major',  os.major).
52
              gsub('$minor',  os.minor).
53
              gsub('$version', [os.major, os.minor ].compact.join('.'))
50 54
             ).normalize
51 55
  end
52 56

  
......
63 67
    to_label
64 68
  end
65 69

  
70
  # sets the prefix for the tfp files based on the os / arch combination
71
  def pxe_prefix(arch)
72
    "boot/#{to_s}-#{arch}".gsub(" ","-")
73
  end
74

  
75
  def pxe_files(media, arch)
76
    boot_files_uri(media, arch).collect do |img|
77
      { pxe_prefix(arch).to_sym => img.to_s}
78
    end
79
  end
80

  
66 81
  def as_json(options={})
67 82
    {:operatingsystem => {:name => to_s, :id => id}}
68 83
  end
......
84 99
    self.release_name.downcase! unless defined?(Rake) or release_name.nil? or release_name.empty?
85 100
  end
86 101

  
102
  def boot_files_uri(media = nil , architecture = nil)
103
    "Abstract"
104
  end
105

  
87 106
end
app/models/redhat.rb
1 1
class Redhat < Operatingsystem
2

  
3
  PXEDIR   = "images/pxeboot"
4
  PXEFILES = {:kernel => "vmlinuz", :initrd => "initrd.img"}
5

  
2 6
  # outputs kickstart installation media based on the media type (NFS or URL)
3 7
  # it also convert the $arch string to the current host architecture
4 8
  def mediapath host
......
43 47
    Operatingsystem
44 48
  end
45 49

  
50
  def boot_files_uri(media, architecture)
51
    raise "invalid media for #{to_s}" unless medias.include?(media)
52
    raise "invalid architecture for #{to_s}" unless architectures.include?(architecture)
53
    PXEFILES.values.collect do |img|
54
      URI.parse("#{media_vars_to_uri(media.path, architecture.name, self)}/#{PXEDIR}/#{img}").normalize
55
    end
56
  end
57

  
58
  def pxe_type
59
    "kickstart"
60
  end
61

  
46 62
end
app/views/unattended/pxe_kickstart_config.erb
1
default linux
2
label linux
3
kernel <%= @kernel %>
4
append initrd=<%= @initrd %> ks=<%= foreman_url("kickstart")%> ksdevice=bootif network kssendmac
config/routes.rb
9 9
    :requirements => {:id => /[^\/]+/},
10 10
    :member => { :report => :get, :reports => :get, :clone => :get,
11 11
      :environment_selected => :post, :architecture_selected => :post, :os_selected => :post,
12
      :storeconfig_klasses => :get, :externalNodes => :get, :setBuild => :get, :cancelBuild => :get, :puppetrun => :get, :facts => :get },
12
      :storeconfig_klasses => :get, :externalNodes => :get, :setBuild => :get, :cancelBuild => :get, :puppetrun => :get, :facts => :get, :pxe_config => :get },
13 13
    :collection => { :show_search => :get, :multiple_actions => :get, :multiple_parameters => :get,
14 14
      :update_multiple_parameters => :post, :save_checkbox => :post, :select_multiple_hostgroup => :get,
15 15
      :update_multiple_hostgroup => :post, :select_multiple_environment => :get, :update_multiple_environment => :post,
......
24 24
  map.resources :lookup_keys
25 25
  map.connect   "/lookup", :controller => "lookup_keys", :action => "q"
26 26
  map.resources :domains, :requirements => {:id => /[^\/]+/}
27
  map.resources :operatingsystems
27
  map.resources :operatingsystems, :member => {:bootfiles => :get}
28 28
  map.resources :medias
29 29
  map.resources :models
30 30
  map.resources :architectures
31
-