Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#2572 implement freebsd support #673

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Binary file added app/assets/images/FreeBSD.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions app/controllers/unattended_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,11 @@ def aif_attributes
@mediapath = os.mediumpath @host
end

def memdisk_attributes
os = @host.operatingsystem
@mediapath = os.mediumpath @host
end

def waik_attributes
end

Expand Down
2 changes: 2 additions & 0 deletions app/helpers/operatingsystems_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ def icon record, opts = {}
"Gentoo"
when /SLC/i
"SLC"
when /freebsd/i
"FreeBSD"
else
return "" if record.family.blank?
record.family
Expand Down
38 changes: 38 additions & 0 deletions app/models/freebsd.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
class Freebsd < Operatingsystem
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As of 1.3 and later this file should be stored under app/models/operatingsystems/freebsd.rb

# We don't fetch any PXEFILES!
# Please copy your mfsbsd boot image into the tftp area.
#
# -as kernel we will use memdisk
# -as initrd we will use your custom FreeBSD-<arch>-<version>-mfs.img in boot
PXEFILES = {}

def class
Operatingsystem
end

def pxe_type
"memdisk"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm.. should we call it maybe differently? so if later on we use memdisk for something else? (or more specific to bsd)

end

def pxedir
"boot/$arch/images"
end

def url_for_boot(file)
pxedir + "/" + PXEFILES[file]
end

def kernel arch
"memdisk"
end

def initrd arch
"boot/FreeBSD-#{arch}-#{release}-mfs.img"
end

def mediumpath host
arch = host.architecture.name.to_s.gsub("x86_64","amd64")
"#{medium_uri(host)}/releases/#{arch}/#{release}-RELEASE"
end
end

3 changes: 2 additions & 1 deletion app/models/operatingsystem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ class Operatingsystem < ActiveRecord::Base
'Windows' => %r{Windows}i,
'Archlinux' => %r{Archlinux}i,
'Gentoo' => %r{Gentoo}i,
'Solaris' => %r{Solaris}i }
'Solaris' => %r{Solaris}i,
'Freebsd' => %r{FreeBSD}i }

class Jail < Safemode::Jail
allow :name, :media_url, :major, :minor, :family, :to_s, :epel, :==, :release_name, :kernel, :initrd, :pxe_type, :medium_uri
Expand Down
67 changes: 67 additions & 0 deletions app/views/unattended/memdisk.rhtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Basic pc-sysinstall based configuration
#
#
installInteractive=no
installMode=fresh
installType=FreeBSD

# install source configuration
installMedium=ftp
ftpPath=<%= @mediapath %>
packageType=tar

# base package name
installFile=base.txz

# set hostname
hostname=<%= @host.name %>

# enable DHCP on all interfaces
netDev=AUTO-DHCP

# inject the disk layout
<%= @host.diskLayout %>

# mount devfs
runExtCommand=mount -t devfs devfs ${FSMNT}/dev

# get and install kernel component
runExtCommand=fetch -o /mnt/tmp/kernel.txz <%= @mediapath %>/kernel.txz
runCommand=tar -xzf /tmp/kernel.txz
runCommand=rm /tmp/kernel.txz

# copy resolv.conf to enable dns in chroot
runExtCommand=cp /etc/resolv.conf /mnt/etc/resolv.conf

# install packages
runCommand=pkg_add -r puppet
runCommand=pkg_add -r wget

# Root Password
rootEncPass=<%= root_pass %>

# setup rc.conf
runCommand=echo 'sshd_enable="YES"' >>/etc/rc.conf
runCommand=echo 'ntpd_enable="YES"' >>/etc/rc.conf

# setup basic networking
runCommand=echo 'ifconfig_bge0="DHCP"' >>/etc/rc.conf
runCommand=echo 'ifconfig_em0="DHCP"' >>/etc/rc.conf
runCommand=echo 'ifconfig_igb0="DHCP"' >>/etc/rc.conf
runCommand=echo 'ifconfig_bce0="DHCP"' >>/etc/rc.conf
runCommand=echo 'ifconfig_nfe0="DHCP"' >>/etc/rc.conf
runCommand=hostname <%= @host.shortname %>

# Set up date/time
runCommand=cp /usr/share/zoneinfo/UTC /etc/localtime
runCommand=touch /etc/wall_cmos_clock
runCommand=adjkerntz -a

# fetch and run finish template
runExtCommand=fetch -o /mnt/tmp/finish.sh <%= foreman_url("finish") %>
runCommand=chmod +x /tmp/finish.sh; /tmp/finish.sh

#Clean up and reboot
runExtCommand=umount ${FSMNT}/dev
runCommand=shutdown -r now
runExtCommand=shutdown -r now
7 changes: 7 additions & 0 deletions app/views/unattended/memdisk_finish.rhtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cat > /usr/local/etc/puppet/puppet.conf << EOF
<%= snippets "puppet.conf" %>
EOF
/usr/local/bin/augtool -s set /files/etc/rc.conf/puppet_enable '\"YES\"'
/usr/bin/touch /usr/local/etc/puppet/namespaceauth.conf
/usr/local/bin/puppet agent --config /urs/local/etc/puppet/puppet.conf --onetime --tags no_such_tag --server <%= @host.puppetmaster %>
/usr/local/bin/wget --quiet --output-document=/dev/null --no-check-certificate <%= foreman_url %>
4 changes: 4 additions & 0 deletions app/views/unattended/pxe_memdisk_config.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
default freebsd
label freebsd
kernel memdisk
append initrd=<%= @initrd %> harddisk raw
4 changes: 4 additions & 0 deletions app/views/unattended/snippets/_puppet.conf.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
[main]
<% if @host.operatingsystem.name == "FreeBSD" -%>vardir = /var/puppet
logdir = \$vardir/log
<% else -%>
vardir = /var/lib/puppet
logdir = /var/log/puppet
<% end -%>
rundir = /var/run/puppet
ssldir = \$vardir/ssl

Expand Down
51 changes: 51 additions & 0 deletions db/migrate/20130528100423_freebsd_os_support.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
class FreebsdOsSupport < ActiveRecord::Migration

class Medium < ActiveRecord::Base
has_and_belongs_to_many :operatingsystems
end

class ConfigTemplate < ActiveRecord::Base
has_and_belongs_to_many :operatingsystems
end

def up
TemplateKind.all.each do |kind|
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we might want to add those templates to the community templates repo?
http://github.com/theforeman/community-templates

case kind.name
when /provision/
ConfigTemplate.create(
:name => "Memdisk Default",
:template_kind_id => kind.id,
:operatingsystem_ids => Freebsd.all.map(&:id),
:template => File.read("#{Rails.root}/app/views/unattended/memdisk.rhtml"))
when /finish/
ConfigTemplate.create(
:name => "Memdisk Default Finish",
:template_kind_id => kind.id,
:operatingsystem_ids => Freebsd.all.map(&:id),
:template => File.read("#{Rails.root}/app/views/unattended/memdisk_finish.rhtml"))
when /pxelinux/i
ConfigTemplate.create(
:name => "Memdisk default PXElinux",
:template_kind_id => kind.id,
:operatingsystem_ids => Freebsd.all.map(&:id),
:template => File.read("#{Rails.root}/app/views/unattended/pxe_memdisk_config.erb"))
end
end

os = Operatingsystem.find_all_by_type "Freebsd" || Operatingsystem.where("name LIKE ?", "freebsd")
disk = Ptable.create :name => "FreeBSD Disk small", :layout => "# Disk Setup\ndisk0=ada0\npartition=ALL\nbootManager=bsd\npartscheme=GPT\ncommitDiskPart\n\n# Partition Setup for da0(ALL)\n# All sizes are expressed in MB\n# Avail FS Types, UFS, UFS+S, UFS+SUJ, UFS+J, ZFS, SWAP\n# UFS.eli, UFS+S.eli, UFS+SUJ, UFS+J.eli, ZFS.eli, SWAP.eli\ndisk0-part=UFS+SUJ 1000 /\ndisk0-part=SWAP 512 none\ndisk0-part=UFS+SUJ 512 /var\ncommitDiskLabel"

medium = Medium.create :name => "FreeBSD mirror", :path => "ftp://ftp.freebsd.org/pub/FreeBSD"
medium.operatingsystems = os

rescue Exception => e
# something bad happened, but we don't want to break the migration process
Rails.logger.warn "Failed to migrate #{e}"
say "Failed to migrate #{e}"
return true

end

def down
end
end