Project

General

Profile

« Previous | Next » 

Revision 68f7a705

Added by Ohad Levy almost 13 years ago

  • ID 68f7a70506d02286eb8518d821d0605123977438

fixes #1058 Adds support for OpenSuSE provisioning

View differences:

app/controllers/unattended_controller.rb
@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
# force static network configuration if static http parameter is defined, in the future this needs to go into the GUI
@static = !params[:static].empty?
end
......
@preseed_server = @host.os.preseed_server @host
end
def yast_attributes
end
private
def safe_render template
app/models/host.rb
include Hostext::Search
include HostCommon
include HostTemplateHelpers
class Jail < Safemode::Jail
allow :name, :diskLayout, :puppetmaster, :operatingsystem, :environment, :ptable, :hostgroup, :url_for_boot,
allow :name, :diskLayout, :puppetmaster, :operatingsystem, :os, :environment, :ptable, :hostgroup, :url_for_boot,
:params, :hostgroup, :domain, :ip, :mac
end
......
# handles all orchestration of smart proxies.
include Foreman::Renderer
include Orchestration
include HostTemplateHelpers
validates_uniqueness_of :ip, :if => Proc.new {|host| host.managed}
validates_uniqueness_of :mac, :unless => Proc.new { |host| host.hypervisor? or !host.managed }
app/models/host_template_helpers.rb
def miniroot
operatingsystem.initrd(architecture)
end
def media_path
operatingsystem.medium_uri(self)
end
#returns the URL for Foreman based on the required action
def foreman_url(action = "provision")
url_for :only_path => false, :controller => "unattended", :action => action, :host => request_url
end
end
app/models/operatingsystem.rb
scoped_search :in => :config_templates, :on => :name, :complete_value => :true, :rename => "template"
scoped_search :in => :os_parameters, :on => :value, :on_key=> :name, :complete_value => true, :rename => :params
FAMILIES = {'Debian' => %r{Debian|Ubuntu}i,
'Redhat' => %r{RedHat|Centos|Fedora|Scientific}i,
'Solaris' => %r{Solaris}i}
FAMILIES = { 'Debian' => %r{Debian|Ubuntu}i,
'Redhat' => %r{RedHat|Centos|Fedora|Scientific}i,
'Suse' => %r{OpenSuSE}i,
'Solaris' => %r{Solaris}i }
class Jail < Safemode::Jail
......
gsub('$release', os.release_name ? os.release_name : "" )
end
# The OS is usually represented as the catenation of the OS and the revision
# The OS is usually represented as the concatenation of the OS and the revision
def to_label
"#{name} #{release}"
end
......
false
end
# The PXE type to use when generating actions and evaluating attributes. jumpstart, kickstart and preseed are currently supported.
# override in sub operatingsystem classes as required.
def pxe_variant
"syslinux"
......
raise "invalid medium for #{to_s}" unless media.include?(medium)
raise "invalid architecture for #{to_s}" unless architectures.include?(architecture)
eval("#{self.family}::PXEFILES").values.collect do |img|
URI.parse("#{medium_vars_to_uri(medium.path, architecture.name, self)}/#{pxedir}/#{img}").normalize
medium_vars_to_uri("#{medium.path}/#{pxedir}/#{img}", architecture.name, self)
end
end
app/models/orchestration/tftp.rb
# therefore some workaround is required to "render" the template.
prefix = operatingsystem.pxe_prefix(arch)
pxefiles = eval "#{os.family}::PXEFILES"
@kernel = "#{prefix}-#{pxefiles[:kernel]}"
@initrd = "#{prefix}-#{pxefiles[:initrd]}"
@kernel = os.kernel(arch)
@initrd = os.initrd(arch)
pxe_render configTemplate({:kind => os.template_kind}).template
rescue => e
failure "Failed to generate #{os.template_kind} template: #{e}"
end
#returns the URL for Foreman based on the required action
def foreman_url(action = "provision")
url_for :only_path => false, :controller => "unattended", :action => action, :host => request_url
end
def queue_tftp
return unless tftp? and errors.empty?
# Jumpstart builds require only minimal tftp services. They do require a tftp object to query for the boot_server.
app/models/suse.rb
class Suse < Operatingsystem
PXEFILES = {:kernel => "linux", :initrd => "initrd"}
# Override the class representation, as this breaks many rails helpers
def class
Operatingsystem
end
def pxe_type
"yast"
end
def pxedir
"boot/$arch/loader"
end
def url_for_boot(file)
pxedir + "/" + PXEFILES[file]
end
end
app/views/unattended/autoyast.xml.erb
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE profile>
<profile xmlns="http://www.suse.com/1.0/yast2ns" xmlns:config="http://www.suse.com/1.0/configns">
<general>
<mode>
<confirm config:type="boolean">false</confirm>
<final_reboot config:type="boolean">true</final_reboot>
</mode>
</general>
<networking>
<dns>
<hostname><%= @host.name %></hostname>
<resolv_conf_policy>auto</resolv_conf_policy>
</dns>
<interfaces config:type="list">
<interface>
<bootproto>dhcp</bootproto>
<device>eth0</device>
<startmode>auto</startmode>
<usercontrol>no</usercontrol>
</interface>
</interfaces>
</networking>
<ntp-client>
<configure_dhcp config:type="boolean">false</configure_dhcp>
<peers config:type="list">
<peer>
<address>ntp</address>
<initial_sync config:type="boolean">true</initial_sync>
<options></options>
<type>server</type>
</peer>
</peers>
<start_at_boot config:type="boolean">true</start_at_boot>
<start_in_chroot config:type="boolean">true</start_in_chroot>
</ntp-client>
<%= @host.diskLayout %>
<runlevel>
<default>3</default>
</runlevel>
<software>
<base>default</base>
<packages config:type="list">
<package>puppet</package>
<package>wget</package>
</packages>
</software>
<users config:type="list">
<user>
<username>root</username>
<encrypted config:type="boolean">true</encrypted>
<fullname>root</fullname>
<gid>0</gid>
<home>/root</home>
<shell>/bin/bash</shell>
<uid>0</uid>
<user_password><%= root_pass %>/</user_password>
</user>
</users>
<scripts>
<post-scripts config:type="list">
<script>
<filename>post.sh</filename>
<interpreter>shell</interpreter>
<network_needed config:type="boolean">true</network_needed>
<notification>Setting up Puppet / Foreman ...</notification>
<debug config:type="boolean">true</debug>
<source><![CDATA[
cat > /etc/puppet/puppet.conf << EOF
<%= snippets "puppet.conf" -%>
EOF
/usr/sbin/puppetd --config /etc/puppet/puppet.conf -o --tags no_such_tag --server puppet --no-daemonize
/usr/bin/wget -q -O /dev/null --no-check-certificate <%= foreman_url %>
/sbin/chkconfig puppet on -f
]]>
</source>
</script>
</post-scripts>
</scripts>
</profile>
app/views/unattended/pxe_autoyast.erb
default linux
label linux
kernel <%= @kernel %>
append initrd=<%= @initrd %> ramdisk_size=65536 install=<%= media_path %> autoyast=<%= foreman_url("provision") + "?format=xml" %>
db/migrate/20110725142054_add_suse_templates.rb
class AddSuseTemplates < ActiveRecord::Migration
def self.up
TemplateKind.all.each do |kind|
case kind.name
when /provision/
ConfigTemplate.create(
:name => "YaST2 Default",
:template_kind_id => kind.id,
:operatingsystem_ids => Suse.all.map(&:id),
:template => File.read("#{RAILS_ROOT}/app/views/unattended/autoyast.xml.erb"))
when /pxelinux/i
ConfigTemplate.create(
:name => "YaST2 default PXELinux",
:template_kind_id => kind.id,
:operatingsystem_ids => Suse.all.map(&:id),
:template => File.read("#{RAILS_ROOT}/app/views/unattended/pxe_autoyast.erb"))
end
end
os = Operatingsystem.find_all_by_type "Suse" || Operatingsystem.name_like("suse")
disk = Ptable.create :name => "SuSE Entire SCSI Disk", :layout =>" <partitioning config:type=\"list\">\n <drive>\n <device>/dev/sda</device> \n <use>all</use>\n </drive>\n </partitioning>"
disk.operatingsystems = os
disk = Ptable.create :name => "SuSE Entire Virtual Disk", :layout =>" <partitioning config:type=\"list\">\n <drive>\n <device>/dev/vda</device> \n <use>all</use>\n </drive>\n </partitioning>"
disk.operatingsystems = os
medium = Medium.create :name => "OpenSuSE mirror", :path => "http://mirror.isoc.org.il/pub/opensuse/distribution/$major.$minor/repo/oss"
medium.operatingsystems = os
rescue Exception => e
# something bad happened, but we don't want to break the migration process
logger.warn "Failed to migrate #{e}" if logger
return true
end
def self.down
end
end
lib/foreman/renderer.rb
def unattended_render template
allowed_helpers = [ :foreman_url, :grub_pass, :snippet, :snippets, :ks_console, :root_pass, :multiboot, :jumpstart_path, :install_path,
:miniroot]
:miniroot, :media_path]
allowed_variables = ({:arch => @arch, :host => @host, :osver => @osver, :mediapath => @mediapath, :static => @static,
:yumrepo => @yumrepo, :dynamic => @dynamic, :epel => @epel, :kernel => @kernel, :initrd => @initrd,
:preseed_server => @preseed_server, :preseed_path => @preseed_path })
test/fixtures/hosts.yml
model: V210
medium: solaris10
domain: yourdomain
suse:
name: suse01.yourdomain.net
ip: 2.3.4.105
mac: ad:bb:cc:da:ae:ff
environment: production
architecture: x86_64
build: true
ptable: suse
domain: yourdomain
medium: suse
operatingsystem: suse
subnet: one
test/fixtures/media.yml
config_path: brsla01:/vol/jumpstart
image_path: brsla01:/vol/solgi_5.10/sol$minor_$release_$arch/flash/
suse:
name: OpenSuse Mirror
path: "http://mirror.isoc.org.il/pub/opensuse/distribution/$major.$minor/repo/oss"
test/fixtures/operatingsystems.yml
architectures: sparc
release_name: hw0910
suse:
name: OpenSuse
major: 11
minor: 4
type: Suse
test/fixtures/ptables.yml
ubuntu:
name: ubuntu default
layout: d-i partman-auto/disk string /dev/sda\nd-i partman-auto/method string regular...
suse:
name: suse default
layout: "<partitioning config:type=\"list\">\n <drive>\n <device>/dev/hda</device>\n <use>all</use>\n </drive>\n</partitioning>"
test/unit/suse_test.rb
require 'test_helper'
class SuseTest < ActiveSupport::TestCase
test "ruby class should be OS" do
assert_equal Operatingsystem, Suse.first.class
end
test "os label for suse" do
assert_equal "OpenSuse 11.4", operatingsystems(:suse).to_label
end
test "pxedir for suse" do
assert_equal "boot/$arch/loader", operatingsystems(:suse).pxedir
end
test "kernel location for 64bit arch suse" do
host = hosts(:suse)
assert_equal "boot/OpenSuse-11.4-x86_64-linux", host.os.kernel(host.arch)
end
test "initrd location for 64bit arch suse" do
host = hosts(:suse)
assert_equal "boot/OpenSuse-11.4-x86_64-initrd", host.os.initrd(host.arch)
end
test "pxe prefix for suse" do
host = hosts(:suse)
prefix = host.os.pxe_prefix(host.arch)
assert_equal "boot/OpenSuse-11.4-x86_64", prefix
end
test "pxe files for suse" do
host = hosts(:suse)
host.medium.operatingsystems << host.os
host.arch.operatingsystems << host.os
prefix = host.os.pxe_prefix(host.arch).to_sym
kernel = { prefix => "http://mirror.isoc.org.il/pub/opensuse/distribution/11.4/repo/oss/boot/x86_64/loader/linux" }
initrd = { prefix => "http://mirror.isoc.org.il/pub/opensuse/distribution/11.4/repo/oss/boot/x86_64/loader/initrd" }
assert host.os.pxe_files(host.medium, host.arch).include?(kernel)
assert host.os.pxe_files(host.medium, host.arch).include?(initrd)
end
end

Also available in: Unified diff