Revision 7a481d2d
Added by Jochen Schalanda about 14 years ago
- ID 7a481d2df8548ebb0651f38331877fbad901a3f3
lib/family.rb | ||
---|---|---|
# Adds operatingsystem family behaviour to the Operatingsystem class
|
||
# The variant is calculated at run-time
|
||
require 'ostruct'
|
||
require 'uri'
|
||
|
||
module Family
|
||
# NEVER, EVER reorder this list. Additions are allowed but offsets are encoded in the database
|
||
FAMILIES = [:Debian, :RedHat, :Solaris]
|
||
... | ... | |
FAMILIES.map{|e| OpenStruct.new(:name => e, :value => FAMILIES.index(e)) }
|
||
end
|
||
|
||
def media_uri host
|
||
URI.parse(host.media.path.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
|
||
end
|
||
|
||
module Debian
|
||
include Family
|
||
|
||
def preseed_server media
|
||
media.path.match('^(\w+):\/\/((\w|\.)+)((\w|\/)+)$')[2]
|
||
def preseed_server host
|
||
media_uri(host).select(:host, :port).compact.join(':')
|
||
end
|
||
|
||
#TODO: rethink of a more generic way
|
||
def preseed_path media
|
||
media.path.match('^(\w+):\/\/((\w|\.)+)((\w|\/)+)$')[4]
|
||
def preseed_path host
|
||
media_uri(host).select(:path, :query).compact.join('?')
|
||
end
|
||
end
|
||
|
||
... | ... | |
# 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
|
||
server, dir = host.media.path.split(":")
|
||
dir.gsub!('$arch',host.architecture.name)
|
||
uri = media_uri(host)
|
||
server = uri.select(:host, :port).compact.join(':')
|
||
dir = uri.select(:path, :query).compact.join('?')
|
||
|
||
return server =~ /^(h|f)t*p$/ ? "url --url #{server+":"+dir}" : "nfs --server #{server} --dir #{dir}"
|
||
case uri.scheme
|
||
when 'http', 'https', 'ftp'
|
||
"url --url #{uri.to_s}"
|
||
else
|
||
"nfs --server #{server} --dir #{dir}"
|
||
end
|
||
end
|
||
|
||
def epel arch
|
||
["4","5"].include?(major) ? "su -c 'rpm -Uvh http://download.fedora.redhat.com/pub/epel/#{major}/#{arch}/epel-release-#{to_version}.noarch.rpm'" : ""
|
||
end
|
Also available in: Unified diff
fixes #235 - Small refactoring of the media handling for operating system families: * Use URI class for any URI related operations * Added substitution for $version, $major and $minor in media path * Force use of http(s)|ftp|nfs URI schema: NFS shares have now to be entered in URI form: nfs://server/path/.../ instead of server:/path/.../