Class: Vmit::Kickstart

Inherits:
UnattendedInstall show all
Defined in:
lib/vmit/kickstart.rb

Instance Attribute Summary

Attributes inherited from UnattendedInstall

#config, #location

Instance Method Summary collapse

Constructor Details

#initialize(location) ⇒ Kickstart

Returns a new instance of Kickstart.



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/vmit/kickstart.rb', line 29

def initialize(location)
  super(location)

  media = Vmit::VFS.from(location)
  case media
    when Vmit::VFS::URI
      @install = location
    when Vmit::VFS::ISO
      @install = :cdrom
      vm.config.configure(:cdrom => location.to_s)
    else raise ArgumentError.new("Unsupported autoinstallation: #{location}")
  end
end

Instance Method Details

#execute_autoinstall(vm, args) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/vmit/kickstart.rb', line 43

def execute_autoinstall(vm, args)
  vm.config.push!
  begin
    vm.config.configure(args)
    if @install == :cdrom
      vm.config.configure(:cdrom => location.to_s)
    end

    Dir.mktmpdir do |floppy_dir|
      FileUtils.chmod_R 0755, floppy_dir
      vm.config.floppy = floppy_dir
      vm.config.add_kernel_cmdline!('ks=floppy')
      vm.config.add_kernel_cmdline!("repo=#{@install}")
      vm.config.reboot = false

      File.write(File.join(floppy_dir, 'ks.cfg'), to_ks_script)
      Vmit.logger.info "Kickstart: 1st stage."
      vm.up
      vm.wait_until_shutdown! do
        vm.vnc
      end
    end
  ensure
    vm.config.pop!
  end
end

#to_ks_scriptObject



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/vmit/kickstart.rb', line 70

def to_ks_script
template = ERB.new <<-EOF
cmdline
halt
rootpw linux
lang en_US.UTF-8
keyboard us
timezone --utc America/New_York
bootloader --location=mbr --driveorder=sda --append="rhgb quiet"
install
<% if @install.is_a?(String) || @install.is_a?(::URI)%>
url --url=<%= @install.to_s.strip %>
<% else %>
<%= @install %>
<% end %>
network --device eth0 --bootproto dhcp
zerombr yes
clearpart --all --initlabel
autopart
%packages --nobase
@core
@server-policy
wget
mc

%end
EOF
template.result(binding)
end