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 |
# 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
# 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
# File lib/boxgrinder-build-rpm-based-os-plugin/rpm-based-os-plugin.rb, line 122 122: def apply_root_password(guestfs) 123: @log.debug "Applying root password..." 124: guestfs.sh("/usr/bin/passwd -d root") 125: guestfs.sh("/usr/sbin/usermod -p '#{@appliance_config.os.password.crypt((0...8).map { 65.+(rand(25)).chr }.join)}' root") 126: @log.debug "Password applied." 127: end
# File lib/boxgrinder-build-rpm-based-os-plugin/rpm-based-os-plugin.rb, line 122 122: def apply_root_password(guestfs) 123: @log.debug "Applying root password..." 124: guestfs.sh("/usr/bin/passwd -d root") 125: guestfs.sh("/usr/sbin/usermod -p '#{@appliance_config.os.password.crypt((0...8).map { 65.+(rand(25)).chr }.join)}' root") 126: @log.debug "Password applied." 127: end
# 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: disable_firewall(guestfs) 90: 91: guestfs.sh("chkconfig firstboot off") if guestfs.exists('/etc/init.d/firstboot') != 0 92: 93: @log.info "Executing post operations after build..." 94: 95: unless @appliance_config.post['base'].nil? 96: @appliance_config.post['base'].each do |cmd| 97: guestfs_helper.sh(cmd, :arch => @appliance_config.hardware.arch) 98: end 99: @log.debug "Post commands from appliance definition file executed." 100: else 101: @log.debug "No commands specified, skipping." 102: end 103: 104: set_motd(guestfs) 105: install_repos(guestfs) 106: 107: yield guestfs, guestfs_helper if block_given? 108: 109: @log.info "Post operations executed." 110: end 111: 112: @log.info "Base image for #{@appliance_config.name} appliance was built successfully." 113: end
# 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: disable_firewall(guestfs) 90: 91: guestfs.sh("chkconfig firstboot off") if guestfs.exists('/etc/init.d/firstboot') != 0 92: 93: @log.info "Executing post operations after build..." 94: 95: unless @appliance_config.post['base'].nil? 96: @appliance_config.post['base'].each do |cmd| 97: guestfs_helper.sh(cmd, :arch => @appliance_config.hardware.arch) 98: end 99: @log.debug "Post commands from appliance definition file executed." 100: else 101: @log.debug "No commands specified, skipping." 102: end 103: 104: set_motd(guestfs) 105: install_repos(guestfs) 106: 107: yield guestfs, guestfs_helper if block_given? 108: 109: @log.info "Post operations executed." 110: end 111: 112: @log.info "Base image for #{@appliance_config.name} appliance was built successfully." 113: end
# File lib/boxgrinder-build-rpm-based-os-plugin/rpm-based-os-plugin.rb, line 129 129: def change_configuration(guestfs_helper) 130: guestfs_helper.augeas do 131: set('/etc/ssh/sshd_config', 'UseDNS', 'no') 132: set('/etc/sysconfig/selinux', 'SELINUX', 'permissive') 133: end 134: end
# File lib/boxgrinder-build-rpm-based-os-plugin/rpm-based-os-plugin.rb, line 129 129: def change_configuration(guestfs_helper) 130: guestfs_helper.augeas do 131: set('/etc/ssh/sshd_config', 'UseDNS', 'no') 132: set('/etc/sysconfig/selinux', 'SELINUX', 'permissive') 133: end 134: end
issues.jboss.org/browse/BGBUILD-177
# File lib/boxgrinder-build-rpm-based-os-plugin/rpm-based-os-plugin.rb, line 116 116: def disable_firewall(guestfs) 117: @log.debug "Disabling firewall..." 118: guestfs.sh("lokkit -q --disabled") 119: @log.debug "Firewall disabled." 120: end
issues.jboss.org/browse/BGBUILD-177
# File lib/boxgrinder-build-rpm-based-os-plugin/rpm-based-os-plugin.rb, line 116 116: def disable_firewall(guestfs) 117: @log.debug "Disabling firewall..." 118: guestfs.sh("lokkit -q --disabled") 119: @log.debug "Firewall disabled." 120: end
# File lib/boxgrinder-build-rpm-based-os-plugin/rpm-based-os-plugin.rb, line 153 153: def install_repos(guestfs) 154: @log.debug "Installing repositories from appliance definition file..." 155: @appliance_config.repos.each do |repo| 156: if repo['ephemeral'] 157: @log.debug "Repository '#{repo['name']}' is an ephemeral repo. It'll not be installed in the appliance." 158: next 159: end 160: 161: @log.debug "Installing #{repo['name']} repo..." 162: repo_file = File.read("#{File.dirname(__FILE__)}/src/base.repo").gsub(/#NAME#/, repo['name']) 163: 164: ['baseurl', 'mirrorlist'].each do |type| 165: repo_file << ("#{type}=#{repo[type]}\n") unless repo[type].nil? 166: end 167: 168: guestfs.write_file("/etc/yum.repos.d/#{repo['name']}.repo", repo_file, 0) 169: end 170: @log.debug "Repositories installed." 171: end
# File lib/boxgrinder-build-rpm-based-os-plugin/rpm-based-os-plugin.rb, line 153 153: def install_repos(guestfs) 154: @log.debug "Installing repositories from appliance definition file..." 155: @appliance_config.repos.each do |repo| 156: if repo['ephemeral'] 157: @log.debug "Repository '#{repo['name']}' is an ephemeral repo. It'll not be installed in the appliance." 158: next 159: end 160: 161: @log.debug "Installing #{repo['name']} repo..." 162: repo_file = File.read("#{File.dirname(__FILE__)}/src/base.repo").gsub(/#NAME#/, repo['name']) 163: 164: ['baseurl', 'mirrorlist'].each do |type| 165: repo_file << ("#{type}=#{repo[type]}\n") unless repo[type].nil? 166: end 167: 168: guestfs.write_file("/etc/yum.repos.d/#{repo['name']}.repo", repo_file, 0) 169: end 170: @log.debug "Repositories installed." 171: end
# 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
# 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
# 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
# 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
# File lib/boxgrinder-build-rpm-based-os-plugin/rpm-based-os-plugin.rb, line 149 149: def recreate_kernel_image(guestfs, modules = []) 150: @linux_helper.recreate_kernel_image(guestfs, modules) 151: end
# File lib/boxgrinder-build-rpm-based-os-plugin/rpm-based-os-plugin.rb, line 149 149: def recreate_kernel_image(guestfs, modules = []) 150: @linux_helper.recreate_kernel_image(guestfs, modules) 151: end
# File lib/boxgrinder-build-rpm-based-os-plugin/rpm-based-os-plugin.rb, line 136 136: def set_motd(guestfs) 137: @log.debug "Setting up '/etc/motd'..." 138: # set nice banner for SSH 139: motd_file = "/etc/init.d/motd" 140: guestfs.upload("#{File.dirname(__FILE__)}/src/motd.init", motd_file) 141: guestfs.sh("sed -i s/#VERSION#/'#{@appliance_config.version}.#{@appliance_config.release}'/ #{motd_file}") 142: guestfs.sh("sed -i s/#APPLIANCE#/'#{@appliance_config.name} appliance'/ #{motd_file}") 143: 144: guestfs.sh("/bin/chmod +x #{motd_file}") 145: guestfs.sh("/sbin/chkconfig --add motd") 146: @log.debug "'/etc/motd' is nice now." 147: end
# File lib/boxgrinder-build-rpm-based-os-plugin/rpm-based-os-plugin.rb, line 136 136: def set_motd(guestfs) 137: @log.debug "Setting up '/etc/motd'..." 138: # set nice banner for SSH 139: motd_file = "/etc/init.d/motd" 140: guestfs.upload("#{File.dirname(__FILE__)}/src/motd.init", motd_file) 141: guestfs.sh("sed -i s/#VERSION#/'#{@appliance_config.version}.#{@appliance_config.release}'/ #{motd_file}") 142: guestfs.sh("sed -i s/#APPLIANCE#/'#{@appliance_config.name} appliance'/ #{motd_file}") 143: 144: guestfs.sh("/bin/chmod +x #{motd_file}") 145: guestfs.sh("/sbin/chkconfig --add motd") 146: @log.debug "'/etc/motd' is nice now." 147: end