foreman/lib/family.rb @ c781bb1a
5f75dccc | Paul Kelly | # Adds operatingsystem family behaviour to the Operatingsystem class
|
|
# The variant is calculated at run-time
|
|||
require 'ostruct'
|
|||
7a481d2d | Jochen Schalanda | require 'uri'
|
|
5f75dccc | Paul Kelly | module Family
|
|
# NEVER, EVER reorder this list. Additions are allowed but offsets are encoded in the database
|
|||
FAMILIES = [:Debian, :RedHat, :Solaris]
|
|||
def family
|
|||
FAMILIES[family_id]
|
|||
end
|
|||
def self.families_as_collection
|
|||
FAMILIES.map{|e| OpenStruct.new(:name => e, :value => FAMILIES.index(e)) }
|
|||
end
|
|||
c289176c | Ohad Levy | def media_uri host, url = nil
|
|
url ||= host.media.path
|
|||
URI.parse(url.gsub('$arch',host.architecture.name).
|
|||
gsub('$major', host.os.major).
|
|||
gsub('$minor', host.os.minor).
|
|||
gsub('$version', [ host.os.major, host.os.minor ].compact.join('.'))
|
|||
).normalize
|
|||
7a481d2d | Jochen Schalanda | end
|
|
5f75dccc | Paul Kelly | module Debian
|
|
include Family
|
|||
7a481d2d | Jochen Schalanda | def preseed_server host
|
|
media_uri(host).select(:host, :port).compact.join(':')
|
|||
5f75dccc | Paul Kelly | end
|
|
7a481d2d | Jochen Schalanda | def preseed_path host
|
|
media_uri(host).select(:path, :query).compact.join('?')
|
|||
5f75dccc | Paul Kelly | end
|
|
end
|
|||
module RedHat
|
|||
include Family
|
|||
# outputs kickstart installation media based on the media type (NFS or URL)
|
|||
# it also convert the $arch string to the current host architecture
|
|||
def mediapath host
|
|||
7a481d2d | Jochen Schalanda | uri = media_uri(host)
|
|
server = uri.select(:host, :port).compact.join(':')
|
|||
c781bb1a | Ohad Levy | dir = uri.select(:path, :query).compact.join('?') unless uri.scheme == 'ftp'
|
|
5f75dccc | Paul Kelly | ||
7a481d2d | Jochen Schalanda | case uri.scheme
|
|
when 'http', 'https', 'ftp'
|
|||
"url --url #{uri.to_s}"
|
|||
else
|
|||
"nfs --server #{server} --dir #{dir}"
|
|||
end
|
|||
5f75dccc | Paul Kelly | end
|
|
7a481d2d | Jochen Schalanda | ||
c289176c | Ohad Levy | # installs the epel repo
|
|
def epel host
|
|||
epel_url = "http://download.fedora.redhat.com/pub/epel/$major/$arch/epel-release-$os.noarch.rpm"
|
|||
case host.operatingsystem.major
|
|||
when "4"
|
|||
epel_url.gsub!("$os","4-9")
|
|||
when "5"
|
|||
epel_url.gsub!("$os","5-3")
|
|||
c781bb1a | Ohad Levy | when "6"
|
|
epel_url.gsub!("$os","6-1").
|
|||
gsub!("/pub/epel/","/pub/epel/beta/") # workaround for hardcoded beta in url, should be remove once RH6 is released
|
|||
c289176c | Ohad Levy | else
|
|
return ""
|
|||
end
|
|||
c781bb1a | Ohad Levy | return "su -c 'rpm -Uvh #{media_uri(host, epel_url)}'"
|
|
5f75dccc | Paul Kelly | end
|
|
def yumrepo host
|
|||
if host.respond_to? :yumrepo
|
|||
"--enablerepo #{repo}"
|
|||
end
|
|||
end
|
|||
end
|
|||
module Solaris
|
|||
include Family
|
|||
end
|
|||
end
|