class PackerFiles::Core::CDImage
Used for figuring out the URLs and Checksum values for the installer images of debian.
Attributes
arch[RW]
Accessors that can be set.
check_sum[RW]
check_sum_pattern[RW]
check_sum_type[RW]
impl[W]
Implementation class for CD Image.
index_urls[RW]
Accessors that can be derived if not set
iso_name_pattern[RW]
iso_url[RW]
release[RW]
Public Class Methods
doc_file()
click to toggle source
Documentation for this class
# File lib/PackerFiles/Core/CDImage.rb, line 56 def self.doc_file PackerFiles.DirPath('Core/example/CDImage.txt').first end
new() { |self| ... }
click to toggle source
Constructor that yields self for accessor settings.
# File lib/PackerFiles/Core/CDImage.rb, line 61 def initialize yield self if block_given? end
Public Instance Methods
normalize()
click to toggle source
Overriden normalize
# File lib/PackerFiles/Core/CDImage.rb, line 66 def normalize # Do some basic checks. raise NilException.new(self, 'arch') if @arch.nil? raise NilException.new(self, 'release') if @release.nil? # Get everything else. set_iso_url_and_checksum end
Private Instance Methods
curated_index_urls()
click to toggle source
Curate the URL list by replacing '@release@' with @release and '@arch' with @arch.
# File lib/PackerFiles/Core/CDImage.rb, line 171 def curated_index_urls @index_urls ||= @impl.index_urls if !@impl.nil? raise NilException.new(self, 'index_urls') if @index_urls.nil? raise EmptyArrayException.new(self, 'index_urls') if @index_urls.empty? @index_urls.map! {|url| url.gsub('@release@', @release).gsub('@arch@', @arch) } end
fastest_url()
click to toggle source
Get the Fastest Index URL from the list of curated index URLs
# File lib/PackerFiles/Core/CDImage.rb, line 155 def fastest_url # Slow URL = 5 seconds latency with a trial = 1 f = Utils::FastestURL.new(5.0, 1) urls = curated_index_urls raise EmptyArrayException.new(self, 'index_urls') if urls.empty? all = f.best_urls(urls) if all.empty? return urls.first, false else return all.flatten.first, true end end
get_check_sum(ck_url)
click to toggle source
Return the MD5 Checksum for the ISO URL
# File lib/PackerFiles/Core/CDImage.rb, line 117 def get_check_sum(ck_url) name = URI::parse(@iso_url).path.split('/').last begin open(ck_url) {|f| f.each_line do |line| if match = line.match(name) return line.split(' ').first end end } rescue OpenURI::HTTPError => e raise URLException.new(ck_url, e) end end
get_iso_checksum_url(index_url)
click to toggle source
Return the full URL for the CD Image.
# File lib/PackerFiles/Core/CDImage.rb, line 134 def get_iso_checksum_url(index_url) iso_regex = "href=\"(#{@iso_name_pattern})\"" ck_regex = "href=\"(#{@check_sum_pattern})\"" iso_url = '' ck_url = '' open(index_url) {|f| f.each_line do |line| if match = line.match(iso_regex) iso_url = URI::join(index_url, match[1]).to_s end if match = line.match(ck_regex) ck_url = URI::join(index_url, match[1]).to_s end end } raise "Cannot find file matching #{@iso_name_pattern}" if iso_url.empty? raise "Cannot find file matching #{@check_sum_pattern}" if ck_url.empty? return iso_url, ck_url end
set_iso_name_checksum_pattern()
click to toggle source
Compute the ISO name of the CD Image from other variables, but only if it is not defined already.
# File lib/PackerFiles/Core/CDImage.rb, line 97 def set_iso_name_checksum_pattern if @iso_name_pattern.nil? && !@impl.nil? name = @impl.get_iso_name_pattern @iso_name_pattern = name.gsub('@release@', @release).gsub('@arch@', @arch) end if @check_sum_pattern.nil? && !@impl.nil? name = @impl.get_check_sum_pattern @check_sum_pattern = name.gsub('@release@', @release).gsub('@arch@', @arch) end if @check_sum_type.nil? && !@impl.nil? @check_sum_type = @impl.get_check_sum_type end # Raise more errors if implementation does not fill values. raise NilException.new(self, 'iso_name_pattern') if @iso_name_pattern.nil? raise NilException.new(self, 'check_sum_pattern') if @check_sum_pattern.nil? raise NilException.new(self, 'check_sum_type') if @check_sum_type.nil? end
set_iso_url_and_checksum()
click to toggle source
Compute the ISO URL and Check SUM for the CD Image, but only if it is not defined already.
# File lib/PackerFiles/Core/CDImage.rb, line 79 def set_iso_url_and_checksum if @iso_url.nil? || @check_sum.nil? set_iso_name_checksum_pattern index_url, valid = fastest_url if (valid) (@iso_url, ck_url) = get_iso_checksum_url(index_url) @check_sum = get_check_sum(ck_url) else @iso_url = URI::join(index_url, @iso_name_pattern).to_s @check_sum_type = 'none' @check_sum = '' end end raise NilException.new(self, 'check_sum_type') if @check_sum_type.nil? end