commit 14dd0353b2c7d16084a13c7b1ab52630887cabe3
Author: Ohad Levy <ohadlevy@gmail.com>
Date:   Tue Nov 16 15:00:32 2010 +0200

    fixes #470 - Add gpxe scripts support
    
    This commit implements the following:
    * dynamic gpxe script that kickstart purly with gpxe - see usage example below
    * add static network option to kickstart, ie if added ?static=true to the url, network configuration would be static
    at the moment this should only be used with gpxe, or alternatviily you would need to
    provide the network information as a kernel argument (see gpxe_kickstart_config file as an example for that.
    
    gpxe usage example
    
    press ctrl-b for interactive mode
    #get network from dhcp
      dhcp net0
    #or set static
      ifopen
      set net0/ip <your host ip>
      set net0/netmask <netmask>
      set net0/gateway <your gateway>
      set net0/dns <dns server>
    
    # tell gpxe to ask foreman for instructions
      kernel http://foreman/unattended/gpxe_kickstart_config
      boot

diff --git a/app/controllers/unattended_controller.rb b/app/controllers/unattended_controller.rb
index e94b9925e..4ea0ac1a3 100644
--- a/app/controllers/unattended_controller.rb
+++ b/app/controllers/unattended_controller.rb
@@ -1,10 +1,10 @@
 class UnattendedController < ApplicationController
   layout nil
   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]
+  before_filter :handle_ca, :except => [:jumpstart_finish, :preseed_finish, :pxe_kickstart_config, :gpxe_kickstart_config, :pxe_debian_config]
   skip_before_filter :require_ssl, :require_login, :authorize, :load_tabs, :manage_tabs
   after_filter :set_content_type, :only => [:kickstart, :preseed, :preseed_finish,
-    :jumpstart_profile, :jumpstart_finish, :pxe_kickstart_config, :pxe_debian_config]
+    :jumpstart_profile, :jumpstart_finish, :pxe_kickstart_config, :gpxe_kickstart_config, :pxe_debian_config]
   before_filter :set_admin_user, :only => :built
 
   def kickstart
@@ -15,6 +15,9 @@ class UnattendedController < ApplicationController
     @mediapath = os.mediapath @host
     @epel      = os.epel      @host
     @yumrepo   = os.yumrepo   @host
+
+    # force static network configurtion if static http parameter is defined, in the future this needs to go into the GUI
+    @static = !params[:static].empty?
     unattended_local "kickstart"
   end
 
@@ -49,6 +52,10 @@ class UnattendedController < ApplicationController
     @initrd = "#{prefix}-#{Redhat::PXEFILES[:initrd]}"
   end
 
+  # Returns a valid GPXE config file to kickstart hosts
+  def gpxe_kickstart_config
+  end
+
   def pxe_debian_config
     @host = Host.find_by_name params[:host_id]
     prefix = @host.operatingsystem.pxe_prefix(@host.arch)
diff --git a/app/models/host.rb b/app/models/host.rb
index 56dec9fae..5285367a2 100644
--- a/app/models/host.rb
+++ b/app/models/host.rb
@@ -476,6 +476,11 @@ class Host < Puppet::Rails::Host
     false
   end
 
+  # Returns a url pointing to boot file
+  def url_for_boot file
+    "#{os.media_uri(self)}/#{os.url_for_boot(file)}"
+  end
+
   private
   # align common mac and ip address input
   def normalize_addresses
diff --git a/app/models/redhat.rb b/app/models/redhat.rb
index 0702691fa..4706a3ade 100644
--- a/app/models/redhat.rb
+++ b/app/models/redhat.rb
@@ -59,4 +59,8 @@ class Redhat < Operatingsystem
     "kickstart"
   end
 
+  def url_for_boot(file)
+    PXEDIR + "/" + PXEFILES[file]
+  end
+
 end
diff --git a/app/views/unattended/gpxe_kickstart_config.erb b/app/views/unattended/gpxe_kickstart_config.erb
new file mode 100644
index 000000000..f159568e2
--- /dev/null
+++ b/app/views/unattended/gpxe_kickstart_config.erb
@@ -0,0 +1,5 @@
+#!gpxe
+kernel <%= "#{@host.url_for_boot(:kernel)}" %> ks=<%= foreman_url("kickstart")%>/static=yes ksdevice=bootif network kssendmac ip=${net0/ip} netmask=${net0/netmask} gateway=${net0/gateway} dns=${net0/dns}
+initrd <%= "#{@host.url_for_boot(:initrd)}" %>
+
+boot
diff --git a/app/views/unattended/kickstart.rhtml b/app/views/unattended/kickstart.rhtml
index c3f6f2265..2318a5665 100644
--- a/app/views/unattended/kickstart.rhtml
+++ b/app/views/unattended/kickstart.rhtml
@@ -6,7 +6,7 @@ lang en_US.UTF-8
 <%= "selinux --disabled\n" if @osver != 3 -%>
 keyboard us
 skipx
-network --bootproto dhcp
+network --bootproto <%= @static ? "static" : "dhcp" %> --hostname <%= @host %>
 rootpw --iscrypted <%= root_pass %>
 firewall --disabled
 authconfig --useshadow --enablemd5 <%= @osver != 3 and @osver != 4 ? '--disablenis' : '' %>
@@ -17,7 +17,6 @@ bootloader --location=mbr --append="nofb quiet splash=quiet <%=ks_console%>" <%=
 <% else -%>
 <%= @host.diskLayout %>
 <% end -%>
-skipx
 text
 reboot
 
