Class: Vmit::AutoYaST

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

Instance Attribute Summary

Attributes inherited from UnattendedInstall

#config, #location

Instance Method Summary collapse

Constructor Details

#initialize(location) ⇒ AutoYaST

Returns a new instance of AutoYaST.



29
30
31
32
# File 'lib/vmit/autoyast.rb', line 29

def initialize(location)
  super(location)
  base!
end

Instance Method Details

#base!Object



34
35
36
37
38
# File 'lib/vmit/autoyast.rb', line 34

def base!
  config.add_patterns! 'base'
  config.add_packages! 'zypper'
  config.add_packages! 'openssh'
end

#execute_autoinstall(vm, args) ⇒ Object

Parameters:

  • args (Hash)

    Arguments for 1st stage



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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
99
100
101
102
103
104
105
106
107
108
# File 'lib/vmit/autoyast.rb', line 49

def execute_autoinstall(vm, args)
  vm.config.push!
  begin
    vm.config.configure(args)
    media = Vmit::VFS.from(location)
    kernel_append_arg = case media
      when Vmit::VFS::URI then "install=#{location}"
      when Vmit::VFS::ISO then 'install=cdrom'
      else raise ArgumentError.new("Unsupported autoinstallation: #{location}")
    end
    vm.config.add_kernel_cmdline!(kernel_append_arg)

    if media.is_a?(Vmit::VFS::ISO)
      vm.config.cdrom = location.to_s
    end

    Dir.mktmpdir do |floppy_dir|
      FileUtils.chmod_R 0775, floppy_dir
      vm.config.floppy = floppy_dir
      #vm.config.add_kernel_cmdline!('autoyast=device://fd0/autoinst.xml')
      vm.config.add_kernel_cmdline!('autoyast=floppy')
      vm.config.reboot = false

      # WTF SLE and openSUSE have different
      # base pattern names
      #media.open('/content') do |content_file|
      #  content_file.each_line do |line|
      #    case line
      #      when /^DISTRIBUTION (.+)$/
      #        case $1
      #          when /SUSE_SLE/ then autoyast.minimal_sle!
      #          when /openSUSE/ then autoyast.minimal_opensuse!
      #        end
      #    end
      #  end
      #end

      File.write(File.join(floppy_dir, 'autoinst.xml'), to_xml)
      Vmit.logger.info "AutoYaST: 1st stage."
      puts vm.config.inspect
      vm.up
      vm.wait_until_shutdown! do
        vm.vnc
      end
      vm.config.pop!

      Vmit.logger.info "AutoYaST: 2st stage."
      # 2nd stage
      vm.config.push!
      vm.config.configure(:reboot => false)
      vm.up
      vm.wait_until_shutdown! do
        vm.vnc
      end

    end
  ensure
    vm.config.pop!
  end
end

#minimal!Object

minimal installation does not work with openSUSE



42
43
44
45
46
# File 'lib/vmit/autoyast.rb', line 42

def minimal!
  config.add_patterns! 'Minimal'
  config.add_packages! 'zypper'
  config.add_packages! 'openssh'
end

#to_xmlObject



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/vmit/autoyast.rb', line 110

def to_xml
  builder = Nokogiri::XML::Builder.new do |xml|
    xml.profile('xmlns' => 'http://www.suse.com/1.0/yast2ns',
      'xmlns:config' => 'http://www.suse.com/1.0/configns') {
      xml.users('config:type' => 'list') {
        xml.user {
          xml.username 'root'
          xml.user_password 'linux'
          xml.encrypted(false,'config:type' => 'boolean')
          xml.forename
          xml.surname
        }
      }
      xml.general {
        xml.mode {
          xml.confirm(false, 'config:type' => 'boolean')
          xml.forceboot('config:type' => 'boolean')
          xml.final_reboot(true, 'config:type' => 'boolean')
          xml.second_stage(true, 'config:type' => 'boolean')
        }
      }
      xml.runlevel {
        xml.default 3
        xml.services {
          xml.service {
            xml.service_name 'sshd'
            xml.service_status 'enable'
            xml.service_start '3 5'
            xml.service_stop '3 5'
          }
        }
      }
      xml.software {
        xml.patterns('config:type' => 'list') {
          config.patterns.each do |pat|
            xml.pattern pat
          end
        }
        xml.packages('config:type' => 'list') {
          config.packages.each do |pkg|
            xml.package pkg
          end
        }
      }
      # SLE 11 can do without this basic partitioning but
      # SLE 10 is not that smart.
      xml.partitioning('config:type' => 'list') {
        xml.drive {
          xml.use 'all'
        }
      }
      xml.networking {
        xml.keep_install_network(true, 'config:type' => 'boolean')
      }
    }
  end
  builder.to_xml
end