class PackerFiles::Core::Disk

Define the Disk class that can handle disks specified in a Packerfile. Just the barebones attributes that are required for this class are specified here. The conversion of these attributes into a OS build specific file is done by derived classes in the OS specific directories.

Attributes

name[RW]

Specify attributes

partitions[RW]
size[RW]
vg[RW]

Public Class Methods

doc_file() click to toggle source

Documentation for this class

# File lib/PackerFiles/Core/Disk.rb, line 29
def self.doc_file
   PackerFiles.DirPath('Core/example/Disk.txt').first
end
new() { |self| ... } click to toggle source

Constructor to just specify accessor varibales

# File lib/PackerFiles/Core/Disk.rb, line 34
def initialize
  @partitions = []
  yield self if block_given?
end

Public Instance Methods

Partition(&block) click to toggle source

Adds a Partition on this disk by doing an instance-eval

# File lib/PackerFiles/Core/Disk.rb, line 76
def Partition(&block)
   if block_given?
     part = Partition.new
     part.instance_eval &block
     if (part.name.nil?)
        part.name = @partitions.size
     end
     @partitions.push(part)
   end
end
VolumeGroup(&block) click to toggle source

Adds a volume group to this disk by doing an instance-eval

# File lib/PackerFiles/Core/Disk.rb, line 67
def VolumeGroup(&block)
   if block_given?
     vg = VolumeGroup.new
     vg.instance_eval &block
     @vg = vg
   end
end
is_raw?() click to toggle source

Tells if the disk is a raw disk that contains no partitions and Volume group

# File lib/PackerFiles/Core/Disk.rb, line 41
def is_raw?
   return true if @partitions.empty? && @vg.nil?
   false
end
normalize() click to toggle source

Normalize the various values into something useful. Usually this means adding UTF-8 into the default string. if desired

# File lib/PackerFiles/Core/Disk.rb, line 89
def normalize
   raise NilException.new(self, 'name')       if @name.nil?
   raise NilException.new(self, 'size')       if @size.nil?
   raise NilException.new(self, 'partitions') if @partitions.nil?

   # Convert given size into MiB
   @size = MiB(@size)

   # Re-create the object by converting the given size into MiB
   @partitions.each {|p|
      p.size = MiB(p.size)
      p.normalize
   }

   # Add all partition sizes and if they exceed disk size, cry...
   part_size = @partitions.inject(0) {|val, p| val + p.size}
   raise SizeException.new(@partitions.first, self) if (@size < part_size)

   # Normalize the embedded VG, if it is present
   return if @vg.nil?
   @vg.normalize
     
   # Calculate sum of all LVs
   lv_size = @vg.lvs.inject(0) { |val, lv| val + lv.size }

   # Calculate the size of the Physical Volumes. It is either
   # the whole disk or the list of partitions that match the
   # disk names
   if @partitions.nil? || @partitions.empty?
     total_size = @size
   else
     total_size = @vg.disk_names.inject(0) {|val,name|
        match = @partitions.select {|part| (part.name.to_s == name.to_s) }
        raise "Disk name #{name} doesn't match partition names" if match.empty?
        raise "Multiple matches for #{name} in Partitions" if match.size > 1
        val + match.first.size
     }
   end
   raise SizeException.new(@vg.lvs.first, @vg) if lv_size > total_size
end
only_partitions?() click to toggle source

Tells if the disk has only custom partition modifiers and no volume group.

# File lib/PackerFiles/Core/Disk.rb, line 48
def only_partitions?
  return true if !@partitions.empty? && @vg.nil?
  false      
end
only_vg?() click to toggle source

Tells if there is just a custom VG specification on a disk w/o any partitions.

# File lib/PackerFiles/Core/Disk.rb, line 55
def only_vg?
  return true if @partitions.empty? && !@vg.nil?
  false
end
vg_with_partitions?() click to toggle source

Tells if there is both a custom VG specification on a disk and partitions.

# File lib/PackerFiles/Core/Disk.rb, line 62
def vg_with_partitions?
  return true if !@partitions.empty? && !@vg.nil?
end