class BoxGrinder::ApplianceConfig

Attributes

appliances[RW]
default_repos[RW]
files[R]
hardware[R]
name[RW]
os[R]
packages[RW]
path[R]
post[R]
release[RW]
repos[RW]
summary[RW]
variables[R]
version[RW]

Public Class Methods

new() click to toggle source
# File lib/boxgrinder-core/models/appliance-config.rb, line 25
def initialize
  @name = nil
  @summary = nil

  @default_repos = true

  @os = AStruct.new

  @os.name = nil
  @os.version = nil
  @os.password = nil
  @os.pae = true

  @hardware = AStruct.new

  @hardware.cpus = 1
  @hardware.memory = 256
  @hardware.network = 'NAT'
  @hardware.partitions = {"/" => {'size' => 1}}

  @variables = {}
  @post = {}
  @files = {}

  @packages = []
  @appliances = []
  @repos = []

  @version = 1
  @release = 0
end

Public Instance Methods

[](k) click to toggle source
# File lib/boxgrinder-core/models/appliance-config.rb, line 73
def [](k)
  instance_variable_get("@#{k}")
end
[]=(k, v) click to toggle source
# File lib/boxgrinder-core/models/appliance-config.rb, line 77
def []=(k, v)
  case k
    when "hardware"
      @hardware.cpus = v['cpus'] if v['cpus']
      @hardware.memory = v['memory'] if v['memory']
      @hardware.network = v['network'] if v['network']
      @hardware.partitions = v['partitions'] if v['partitions']
    when "os"
      @os.name = v['name'] if v['name']
      @os.version = v['version'] if v['version']
      @os.password = v['password'] if v['password']
      # TODO this is OS specific, move it to OS plugin!
      @os.pae = false if v['pae'] == false
    else
      instance_variable_set("@#{k}", v)
  end

end
all_values(input=nil) click to toggle source
# File lib/boxgrinder-core/models/appliance-config.rb, line 120
def all_values(input=nil)
  avoid     = ['@variables']
  input = (self.instance_variables - avoid).
    collect{ |v| self.instance_variable_get(v) } if input.nil?

  vars = input.inject([]) do |arr, var|
    case var
      when Hash
        arr.concat(all_values(var.values))
      when Array
        arr.concat(all_values(var))
      when String
        arr.push var
      end
    arr
    end
  vars
end
clone() click to toggle source
# File lib/boxgrinder-core/models/appliance-config.rb, line 169
def clone
  Marshal::load(Marshal.dump(self))
end
default_filesystem_type() click to toggle source

Returns default filesystem type for current OS

# File lib/boxgrinder-core/models/appliance-config.rb, line 140
    def default_filesystem_type
      fs = 'ext4'

# Since RHEL 5.6 the default filesystem is ext4
#
#      case @os.name
#        when 'rhel', 'centos'
#          case @os.version
#            when '5'
#              fs = 'ext3'
#          end
#      end

      fs
    end
eql?(other) click to toggle source
# File lib/boxgrinder-core/models/appliance-config.rb, line 161
def eql?(other)
  hash.eql?(other.hash)
end
hash() click to toggle source

used to checking if configuration differs from previous in appliance-kickstart

# File lib/boxgrinder-core/models/appliance-config.rb, line 157
def hash
  "#{@name}-#{@summary}-#{@version}-#{@release}-#{@os.name}-#{@os.version}-#{@os.password}-#{@hardware.cpus}-#{@hardware.memory}-#{@hardware.partitions}-#{@appliances}".hash
end
init() click to toggle source
# File lib/boxgrinder-core/models/appliance-config.rb, line 96
def init
  init_arch
  initialize_paths
  self
end
init_arch() click to toggle source
# File lib/boxgrinder-core/models/appliance-config.rb, line 102
def init_arch
  @hardware.arch = %xuname -m`.chomp.strip
  @hardware.base_arch = is64bit? ? "x86_64" : "i386"
  self
end
initialize_paths() click to toggle source
# File lib/boxgrinder-core/models/appliance-config.rb, line 108
def initialize_paths
  @path = AStruct.new

  @path.os = "#{@os.name}/#{@os.version}"
  @path.version = "#{@version}.#{@release}"
  @path.main = "#{@hardware.arch}/#{@path.os}"
  @path.appliance = "appliances/#{@path.main}/#{@name}/#{@path.version}"
  @path.build = "build/#{@path.appliance}"

  self
end
is64bit?() click to toggle source
# File lib/boxgrinder-core/models/appliance-config.rb, line 165
def is64bit?
  @hardware.arch.eql?("x86_64")
end