Class BoxGrinder::RPMBasedOSPlugin
In: lib/boxgrinder-build-rpm-based-os-plugin/rpm-based-os-plugin.rb
lib/boxgrinder-build-rpm-based-os-plugin/rpm-based-os-plugin.rb
Parent: BasePlugin

Methods

Public Instance methods

[Source]

    # File lib/boxgrinder-build-rpm-based-os-plugin/rpm-based-os-plugin.rb, line 27
27:     def after_init
28:       register_deliverable(
29:           :disk       => "#{@appliance_config.name}-sda.raw",
30:           :descriptor => "#{@appliance_config.name}.xml"
31:       )
32: 
33:       @linux_helper = LinuxHelper.new(:log => @log)
34:     end

[Source]

    # File lib/boxgrinder-build-rpm-based-os-plugin/rpm-based-os-plugin.rb, line 27
27:     def after_init
28:       register_deliverable(
29:           :disk       => "#{@appliance_config.name}-sda.raw",
30:           :descriptor => "#{@appliance_config.name}.xml"
31:       )
32: 
33:       @linux_helper = LinuxHelper.new(:log => @log)
34:     end

[Source]

     # File lib/boxgrinder-build-rpm-based-os-plugin/rpm-based-os-plugin.rb, line 114
114:     def apply_root_password(guestfs)
115:       @log.debug "Applying root password..."
116:       guestfs.sh("/usr/bin/passwd -d root")
117:       guestfs.sh("/usr/sbin/usermod -p '#{@appliance_config.os.password.crypt((0...8).map { 65.+(rand(25)).chr }.join)}' root")
118:       @log.debug "Password applied."
119:     end

[Source]

     # File lib/boxgrinder-build-rpm-based-os-plugin/rpm-based-os-plugin.rb, line 114
114:     def apply_root_password(guestfs)
115:       @log.debug "Applying root password..."
116:       guestfs.sh("/usr/bin/passwd -d root")
117:       guestfs.sh("/usr/sbin/usermod -p '#{@appliance_config.os.password.crypt((0...8).map { 65.+(rand(25)).chr }.join)}' root")
118:       @log.debug "Password applied."
119:     end

[Source]

     # File lib/boxgrinder-build-rpm-based-os-plugin/rpm-based-os-plugin.rb, line 65
 65:     def build_with_appliance_creator(appliance_definition_file, repos = {})
 66:       if File.extname(appliance_definition_file).eql?('.ks')
 67:         kickstart_file = appliance_definition_file
 68:       else
 69:         kickstart_file = Kickstart.new(@config, @appliance_config, repos, @dir, :log => @log).create
 70:       end
 71: 
 72:       RPMDependencyValidator.new(@config, @appliance_config, @dir, kickstart_file, @options).resolve_packages
 73: 
 74:       @log.info "Building #{@appliance_config.name} appliance..."
 75: 
 76:       @exec_helper.execute "appliance-creator -d -v -t #{@dir.tmp} --cache=#{@config.dir.rpms_cache}/#{@appliance_config.path.main} --config #{kickstart_file} -o #{@dir.tmp} --name #{@appliance_config.name} --vmem #{@appliance_config.hardware.memory} --vcpu #{@appliance_config.hardware.cpus}"
 77: 
 78:       FileUtils.mv(Dir.glob("#{@dir.tmp}/#{@appliance_config.name}/*"), @dir.tmp)
 79:       FileUtils.rm_rf("#{@dir.tmp}/#{@appliance_config.name}/")
 80: 
 81:       @image_helper.customize(@deliverables.disk) do |guestfs, guestfs_helper|
 82:         # TODO is this really needed?
 83:         @log.debug "Uploading '/etc/resolv.conf'..."
 84:         guestfs.upload("/etc/resolv.conf", "/etc/resolv.conf")
 85:         @log.debug "'/etc/resolv.conf' uploaded."
 86: 
 87:         change_configuration(guestfs_helper)
 88:         apply_root_password(guestfs)
 89: 
 90:         guestfs.sh("chkconfig firstboot off") if guestfs.exists('/etc/init.d/firstboot') != 0
 91: 
 92:         @log.info "Executing post operations after build..."
 93: 
 94:         unless @appliance_config.post['base'].nil?
 95:           @appliance_config.post['base'].each do |cmd|
 96:             guestfs_helper.sh(cmd, :arch => @appliance_config.hardware.arch)
 97:           end
 98:           @log.debug "Post commands from appliance definition file executed."
 99:         else
100:           @log.debug "No commands specified, skipping."
101:         end
102: 
103:         set_motd(guestfs)
104:         install_repos(guestfs)
105: 
106:         yield guestfs, guestfs_helper if block_given?
107: 
108:         @log.info "Post operations executed."
109:       end
110: 
111:       @log.info "Base image for #{@appliance_config.name} appliance was built successfully."
112:     end

[Source]

     # File lib/boxgrinder-build-rpm-based-os-plugin/rpm-based-os-plugin.rb, line 65
 65:     def build_with_appliance_creator(appliance_definition_file, repos = {})
 66:       if File.extname(appliance_definition_file).eql?('.ks')
 67:         kickstart_file = appliance_definition_file
 68:       else
 69:         kickstart_file = Kickstart.new(@config, @appliance_config, repos, @dir, :log => @log).create
 70:       end
 71: 
 72:       RPMDependencyValidator.new(@config, @appliance_config, @dir, kickstart_file, @options).resolve_packages
 73: 
 74:       @log.info "Building #{@appliance_config.name} appliance..."
 75: 
 76:       @exec_helper.execute "appliance-creator -d -v -t #{@dir.tmp} --cache=#{@config.dir.rpms_cache}/#{@appliance_config.path.main} --config #{kickstart_file} -o #{@dir.tmp} --name #{@appliance_config.name} --vmem #{@appliance_config.hardware.memory} --vcpu #{@appliance_config.hardware.cpus}"
 77: 
 78:       FileUtils.mv(Dir.glob("#{@dir.tmp}/#{@appliance_config.name}/*"), @dir.tmp)
 79:       FileUtils.rm_rf("#{@dir.tmp}/#{@appliance_config.name}/")
 80: 
 81:       @image_helper.customize(@deliverables.disk) do |guestfs, guestfs_helper|
 82:         # TODO is this really needed?
 83:         @log.debug "Uploading '/etc/resolv.conf'..."
 84:         guestfs.upload("/etc/resolv.conf", "/etc/resolv.conf")
 85:         @log.debug "'/etc/resolv.conf' uploaded."
 86: 
 87:         change_configuration(guestfs_helper)
 88:         apply_root_password(guestfs)
 89: 
 90:         guestfs.sh("chkconfig firstboot off") if guestfs.exists('/etc/init.d/firstboot') != 0
 91: 
 92:         @log.info "Executing post operations after build..."
 93: 
 94:         unless @appliance_config.post['base'].nil?
 95:           @appliance_config.post['base'].each do |cmd|
 96:             guestfs_helper.sh(cmd, :arch => @appliance_config.hardware.arch)
 97:           end
 98:           @log.debug "Post commands from appliance definition file executed."
 99:         else
100:           @log.debug "No commands specified, skipping."
101:         end
102: 
103:         set_motd(guestfs)
104:         install_repos(guestfs)
105: 
106:         yield guestfs, guestfs_helper if block_given?
107: 
108:         @log.info "Post operations executed."
109:       end
110: 
111:       @log.info "Base image for #{@appliance_config.name} appliance was built successfully."
112:     end

[Source]

     # File lib/boxgrinder-build-rpm-based-os-plugin/rpm-based-os-plugin.rb, line 121
121:     def change_configuration(guestfs_helper)
122:       guestfs_helper.augeas do
123:         set('/etc/ssh/sshd_config', 'UseDNS', 'no')
124:         set('/etc/sysconfig/selinux', 'SELINUX', 'permissive')
125:       end
126:     end

[Source]

     # File lib/boxgrinder-build-rpm-based-os-plugin/rpm-based-os-plugin.rb, line 121
121:     def change_configuration(guestfs_helper)
122:       guestfs_helper.augeas do
123:         set('/etc/ssh/sshd_config', 'UseDNS', 'no')
124:         set('/etc/sysconfig/selinux', 'SELINUX', 'permissive')
125:       end
126:     end

[Source]

     # File lib/boxgrinder-build-rpm-based-os-plugin/rpm-based-os-plugin.rb, line 145
145:     def install_repos(guestfs)
146:       @log.debug "Installing repositories from appliance definition file..."
147:       @appliance_config.repos.each do |repo|
148:         if repo['ephemeral']
149:           @log.debug "Repository '#{repo['name']}' is an ephemeral repo. It'll not be installed in the appliance."
150:           next
151:         end
152: 
153:         @log.debug "Installing #{repo['name']} repo..."
154:         repo_file = File.read("#{File.dirname(__FILE__)}/src/base.repo").gsub(/#NAME#/, repo['name'])
155: 
156:         ['baseurl', 'mirrorlist'].each do |type|
157:           repo_file << ("#{type}=#{repo[type]}\n") unless repo[type].nil?
158:         end
159: 
160:         guestfs.write_file("/etc/yum.repos.d/#{repo['name']}.repo", repo_file, 0)
161:       end
162:       @log.debug "Repositories installed."
163:     end

[Source]

     # File lib/boxgrinder-build-rpm-based-os-plugin/rpm-based-os-plugin.rb, line 145
145:     def install_repos(guestfs)
146:       @log.debug "Installing repositories from appliance definition file..."
147:       @appliance_config.repos.each do |repo|
148:         if repo['ephemeral']
149:           @log.debug "Repository '#{repo['name']}' is an ephemeral repo. It'll not be installed in the appliance."
150:           next
151:         end
152: 
153:         @log.debug "Installing #{repo['name']} repo..."
154:         repo_file = File.read("#{File.dirname(__FILE__)}/src/base.repo").gsub(/#NAME#/, repo['name'])
155: 
156:         ['baseurl', 'mirrorlist'].each do |type|
157:           repo_file << ("#{type}=#{repo[type]}\n") unless repo[type].nil?
158:         end
159: 
160:         guestfs.write_file("/etc/yum.repos.d/#{repo['name']}.repo", repo_file, 0)
161:       end
162:       @log.debug "Repositories installed."
163:     end

[Source]

    # File lib/boxgrinder-build-rpm-based-os-plugin/rpm-based-os-plugin.rb, line 36
36:     def read_file(file)
37:       read_kickstart(file) if File.extname(file).eql?('.ks')
38:     end

[Source]

    # File lib/boxgrinder-build-rpm-based-os-plugin/rpm-based-os-plugin.rb, line 36
36:     def read_file(file)
37:       read_kickstart(file) if File.extname(file).eql?('.ks')
38:     end

[Source]

    # File lib/boxgrinder-build-rpm-based-os-plugin/rpm-based-os-plugin.rb, line 40
40:     def read_kickstart(file)
41:       appliance_config      = ApplianceConfig.new
42: 
43:       appliance_config.name = File.basename(file, '.ks')
44: 
45:       name                  = nil
46:       version               = nil
47: 
48:       File.read(file).each do |line|
49:         n = line.scan(/^# bg_os_name: (.*)/).flatten.first
50:         v = line.scan(/^# bg_os_version: (.*)/).flatten.first
51: 
52:         name = n unless n.nil?
53:         version = v unless v.nil?
54:       end
55: 
56:       raise "No operating system name specified, please add comment to you kickstrt file like this: # bg_os_name: fedora" if name.nil?
57:       raise "No operating system version specified, please add comment to you kickstrt file like this: # bg_os_version: 14" if version.nil?
58: 
59:       appliance_config.os.name    = name
60:       appliance_config.os.version = version
61: 
62:       appliance_config
63:     end

[Source]

    # File lib/boxgrinder-build-rpm-based-os-plugin/rpm-based-os-plugin.rb, line 40
40:     def read_kickstart(file)
41:       appliance_config      = ApplianceConfig.new
42: 
43:       appliance_config.name = File.basename(file, '.ks')
44: 
45:       name                  = nil
46:       version               = nil
47: 
48:       File.read(file).each do |line|
49:         n = line.scan(/^# bg_os_name: (.*)/).flatten.first
50:         v = line.scan(/^# bg_os_version: (.*)/).flatten.first
51: 
52:         name = n unless n.nil?
53:         version = v unless v.nil?
54:       end
55: 
56:       raise "No operating system name specified, please add comment to you kickstrt file like this: # bg_os_name: fedora" if name.nil?
57:       raise "No operating system version specified, please add comment to you kickstrt file like this: # bg_os_version: 14" if version.nil?
58: 
59:       appliance_config.os.name    = name
60:       appliance_config.os.version = version
61: 
62:       appliance_config
63:     end

[Source]

     # File lib/boxgrinder-build-rpm-based-os-plugin/rpm-based-os-plugin.rb, line 141
141:     def recreate_kernel_image(guestfs, modules = [])
142:       @linux_helper.recreate_kernel_image(guestfs, modules)
143:     end

[Source]

     # File lib/boxgrinder-build-rpm-based-os-plugin/rpm-based-os-plugin.rb, line 141
141:     def recreate_kernel_image(guestfs, modules = [])
142:       @linux_helper.recreate_kernel_image(guestfs, modules)
143:     end

[Source]

     # File lib/boxgrinder-build-rpm-based-os-plugin/rpm-based-os-plugin.rb, line 128
128:     def set_motd(guestfs)
129:       @log.debug "Setting up '/etc/motd'..."
130:       # set nice banner for SSH
131:       motd_file = "/etc/init.d/motd"
132:       guestfs.upload("#{File.dirname(__FILE__)}/src/motd.init", motd_file)
133:       guestfs.sh("sed -i s/#VERSION#/'#{@appliance_config.version}.#{@appliance_config.release}'/ #{motd_file}")
134:       guestfs.sh("sed -i s/#APPLIANCE#/'#{@appliance_config.name} appliance'/ #{motd_file}")
135: 
136:       guestfs.sh("/bin/chmod +x #{motd_file}")
137:       guestfs.sh("/sbin/chkconfig --add motd")
138:       @log.debug "'/etc/motd' is nice now."
139:     end

[Source]

     # File lib/boxgrinder-build-rpm-based-os-plugin/rpm-based-os-plugin.rb, line 128
128:     def set_motd(guestfs)
129:       @log.debug "Setting up '/etc/motd'..."
130:       # set nice banner for SSH
131:       motd_file = "/etc/init.d/motd"
132:       guestfs.upload("#{File.dirname(__FILE__)}/src/motd.init", motd_file)
133:       guestfs.sh("sed -i s/#VERSION#/'#{@appliance_config.version}.#{@appliance_config.release}'/ #{motd_file}")
134:       guestfs.sh("sed -i s/#APPLIANCE#/'#{@appliance_config.name} appliance'/ #{motd_file}")
135: 
136:       guestfs.sh("/bin/chmod +x #{motd_file}")
137:       guestfs.sh("/sbin/chkconfig --add motd")
138:       @log.debug "'/etc/motd' is nice now."
139:     end

[Validate]