Class | BoxGrinder::EC2Plugin |
In: |
lib/boxgrinder-build/plugins/platform/ec2/ec2-plugin.rb
lib/boxgrinder-build/plugins/platform/ec2/ec2-plugin.rb |
Parent: | BasePlugin |
issues.jboss.org/browse/BGBUILD-110
# File lib/boxgrinder-build/plugins/platform/ec2/ec2-plugin.rb, line 160 160: def add_ec2_user(guestfs) 161: @log.debug "Adding ec2-user user..." 162: guestfs.sh("useradd ec2-user") 163: guestfs.sh("echo -e 'ec2-user\tALL=(ALL)\tNOPASSWD: ALL' >> /etc/sudoers") 164: @log.debug "User ec2-user added." 165: end
issues.jboss.org/browse/BGBUILD-110
# File lib/boxgrinder-build/plugins/platform/ec2/ec2-plugin.rb, line 160 160: def add_ec2_user(guestfs) 161: @log.debug "Adding ec2-user user..." 162: guestfs.sh("useradd ec2-user") 163: guestfs.sh("echo -e 'ec2-user\tALL=(ALL)\tNOPASSWD: ALL' >> /etc/sudoers") 164: @log.debug "User ec2-user added." 165: end
# File lib/boxgrinder-build/plugins/platform/ec2/ec2-plugin.rb, line 25 25: def after_init 26: register_deliverable(:disk => "#{@appliance_config.name}.ec2") 27: 28: register_supported_os('fedora', ['13', '14', '15']) 29: register_supported_os('centos', ['5']) 30: register_supported_os('rhel', ['5', '6']) 31: end
# File lib/boxgrinder-build/plugins/platform/ec2/ec2-plugin.rb, line 25 25: def after_init 26: register_deliverable(:disk => "#{@appliance_config.name}.ec2") 27: 28: register_supported_os('fedora', ['13', '14', '15']) 29: register_supported_os('centos', ['5']) 30: register_supported_os('rhel', ['5', '6']) 31: end
# File lib/boxgrinder-build/plugins/platform/ec2/ec2-plugin.rb, line 187 187: def change_configuration(guestfs_helper) 188: guestfs_helper.augeas do 189: # disable password authentication 190: set("/etc/ssh/sshd_config", "PasswordAuthentication", "no") 191: 192: # disable root login 193: set("/etc/ssh/sshd_config", "PermitRootLogin", "no") 194: end 195: end
# File lib/boxgrinder-build/plugins/platform/ec2/ec2-plugin.rb, line 187 187: def change_configuration(guestfs_helper) 188: guestfs_helper.augeas do 189: # disable password authentication 190: set("/etc/ssh/sshd_config", "PasswordAuthentication", "no") 191: 192: # disable root login 193: set("/etc/ssh/sshd_config", "PermitRootLogin", "no") 194: end 195: end
# File lib/boxgrinder-build/plugins/platform/ec2/ec2-plugin.rb, line 96 96: def create_devices(guestfs) 97: return if guestfs.exists('/sbin/MAKEDEV') == 0 98: 99: @log.debug "Creating required devices..." 100: guestfs.sh("/sbin/MAKEDEV -d /dev -x console") 101: guestfs.sh("/sbin/MAKEDEV -d /dev -x null") 102: guestfs.sh("/sbin/MAKEDEV -d /dev -x zero") 103: @log.debug "Devices created." 104: end
# File lib/boxgrinder-build/plugins/platform/ec2/ec2-plugin.rb, line 96 96: def create_devices(guestfs) 97: return if guestfs.exists('/sbin/MAKEDEV') == 0 98: 99: @log.debug "Creating required devices..." 100: guestfs.sh("/sbin/MAKEDEV -d /dev -x console") 101: guestfs.sh("/sbin/MAKEDEV -d /dev -x null") 102: guestfs.sh("/sbin/MAKEDEV -d /dev -x zero") 103: @log.debug "Devices created." 104: end
# File lib/boxgrinder-build/plugins/platform/ec2/ec2-plugin.rb, line 106 106: def disk_device_prefix 107: disk = 'xv' 108: disk = 's' if (@appliance_config.os.name == 'rhel' or @appliance_config.os.name == 'centos') and @appliance_config.os.version == '5' 109: 110: disk 111: end
# File lib/boxgrinder-build/plugins/platform/ec2/ec2-plugin.rb, line 106 106: def disk_device_prefix 107: disk = 'xv' 108: disk = 's' if (@appliance_config.os.name == 'rhel' or @appliance_config.os.name == 'centos') and @appliance_config.os.version == '5' 109: 110: disk 111: end
enable networking on default runlevels
# File lib/boxgrinder-build/plugins/platform/ec2/ec2-plugin.rb, line 168 168: def enable_networking(guestfs) 169: @log.debug "Enabling networking..." 170: guestfs.sh("/sbin/chkconfig network on") 171: guestfs.upload("#{File.dirname(__FILE__)}/src/ifcfg-eth0", "/etc/sysconfig/network-scripts/ifcfg-eth0") 172: @log.debug "Networking enabled." 173: end
enable networking on default runlevels
# File lib/boxgrinder-build/plugins/platform/ec2/ec2-plugin.rb, line 168 168: def enable_networking(guestfs) 169: @log.debug "Enabling networking..." 170: guestfs.sh("/sbin/chkconfig network on") 171: guestfs.upload("#{File.dirname(__FILE__)}/src/ifcfg-eth0", "/etc/sysconfig/network-scripts/ifcfg-eth0") 172: @log.debug "Networking enabled." 173: end
This fixes issues with Fedora 14 on EC2: bugzilla.redhat.com/show_bug.cgi?id=651861#c39
# File lib/boxgrinder-build/plugins/platform/ec2/ec2-plugin.rb, line 152 152: def enable_nosegneg_flag(guestfs) 153: @log.debug "Enabling nosegneg flag..." 154: guestfs.sh("echo \"hwcap 1 nosegneg\" > /etc/ld.so.conf.d/libc6-xen.conf") 155: guestfs.sh("/sbin/ldconfig") 156: @log.debug "Nosegneg enabled." 157: end
This fixes issues with Fedora 14 on EC2: bugzilla.redhat.com/show_bug.cgi?id=651861#c39
# File lib/boxgrinder-build/plugins/platform/ec2/ec2-plugin.rb, line 152 152: def enable_nosegneg_flag(guestfs) 153: @log.debug "Enabling nosegneg flag..." 154: guestfs.sh("echo \"hwcap 1 nosegneg\" > /etc/ld.so.conf.d/libc6-xen.conf") 155: guestfs.sh("/sbin/ldconfig") 156: @log.debug "Nosegneg enabled." 157: end
# File lib/boxgrinder-build/plugins/platform/ec2/ec2-plugin.rb, line 33 33: def execute 34: @linux_helper = LinuxHelper.new(:log => @log) 35: 36: @log.info "Converting #{@appliance_config.name} appliance image to EC2 format..." 37: 38: @image_helper.create_disk(@deliverables.disk, 10) # 10 GB destination disk 39: 40: @image_helper.customize([@previous_deliverables.disk, @deliverables.disk], :automount => false) do |guestfs, guestfs_helper| 41: @image_helper.sync_filesystem(guestfs, guestfs_helper) 42: 43: if (@appliance_config.os.name == 'rhel' or @appliance_config.os.name == 'centos') and @appliance_config.os.version == '5' 44: # Not sure why it's messed but this prevents booting on AWS 45: recreate_journal(guestfs) 46: 47: # Remove normal kernel 48: guestfs.sh("yum -y remove kernel") 49: # because we need to install kernel-xen package 50: guestfs.sh("yum -y install kernel-xen") 51: # and add require modules 52: @linux_helper.recreate_kernel_image(guestfs, ['xenblk', 'xennet']) 53: end 54: 55: # TODO is this really needed? 56: @log.debug "Uploading '/etc/resolv.conf'..." 57: guestfs.upload("/etc/resolv.conf", "/etc/resolv.conf") 58: @log.debug "'/etc/resolv.conf' uploaded." 59: 60: create_devices(guestfs) 61: 62: guestfs.mkdir("/data") if @appliance_config.is64bit? 63: 64: upload_fstab(guestfs) 65: enable_networking(guestfs) 66: upload_rc_local(guestfs) 67: add_ec2_user(guestfs) 68: change_configuration(guestfs_helper) 69: install_menu_lst(guestfs) 70: 71: enable_nosegneg_flag(guestfs) if @appliance_config.os.name == 'fedora' 72: 73: execute_post(guestfs_helper) 74: end 75: 76: @log.info "Image converted to EC2 format." 77: end
# File lib/boxgrinder-build/plugins/platform/ec2/ec2-plugin.rb, line 33 33: def execute 34: @linux_helper = LinuxHelper.new(:log => @log) 35: 36: @log.info "Converting #{@appliance_config.name} appliance image to EC2 format..." 37: 38: @image_helper.create_disk(@deliverables.disk, 10) # 10 GB destination disk 39: 40: @image_helper.customize([@previous_deliverables.disk, @deliverables.disk], :automount => false) do |guestfs, guestfs_helper| 41: @image_helper.sync_filesystem(guestfs, guestfs_helper) 42: 43: if (@appliance_config.os.name == 'rhel' or @appliance_config.os.name == 'centos') and @appliance_config.os.version == '5' 44: # Not sure why it's messed but this prevents booting on AWS 45: recreate_journal(guestfs) 46: 47: # Remove normal kernel 48: guestfs.sh("yum -y remove kernel") 49: # because we need to install kernel-xen package 50: guestfs.sh("yum -y install kernel-xen") 51: # and add require modules 52: @linux_helper.recreate_kernel_image(guestfs, ['xenblk', 'xennet']) 53: end 54: 55: # TODO is this really needed? 56: @log.debug "Uploading '/etc/resolv.conf'..." 57: guestfs.upload("/etc/resolv.conf", "/etc/resolv.conf") 58: @log.debug "'/etc/resolv.conf' uploaded." 59: 60: create_devices(guestfs) 61: 62: guestfs.mkdir("/data") if @appliance_config.is64bit? 63: 64: upload_fstab(guestfs) 65: enable_networking(guestfs) 66: upload_rc_local(guestfs) 67: add_ec2_user(guestfs) 68: change_configuration(guestfs_helper) 69: install_menu_lst(guestfs) 70: 71: enable_nosegneg_flag(guestfs) if @appliance_config.os.name == 'fedora' 72: 73: execute_post(guestfs_helper) 74: end 75: 76: @log.info "Image converted to EC2 format." 77: end
# File lib/boxgrinder-build/plugins/platform/ec2/ec2-plugin.rb, line 79 79: def execute_post(guestfs_helper) 80: unless @appliance_config.post['ec2'].nil? 81: @appliance_config.post['ec2'].each do |cmd| 82: guestfs_helper.sh(cmd, :arch => @appliance_config.hardware.arch) 83: end 84: @log.debug "Post commands from appliance definition file executed." 85: else 86: @log.debug "No commands specified, skipping." 87: end 88: end
# File lib/boxgrinder-build/plugins/platform/ec2/ec2-plugin.rb, line 79 79: def execute_post(guestfs_helper) 80: unless @appliance_config.post['ec2'].nil? 81: @appliance_config.post['ec2'].each do |cmd| 82: guestfs_helper.sh(cmd, :arch => @appliance_config.hardware.arch) 83: end 84: @log.debug "Post commands from appliance definition file executed." 85: else 86: @log.debug "No commands specified, skipping." 87: end 88: end
# File lib/boxgrinder-build/plugins/platform/ec2/ec2-plugin.rb, line 133 133: def install_menu_lst(guestfs) 134: @log.debug "Uploading '/boot/grub/menu.lst' file..." 135: menu_lst_data = File.open("#{File.dirname(__FILE__)}/src/menu.lst").read 136: 137: menu_lst_data.gsub!(/#TITLE#/, @appliance_config.name) 138: menu_lst_data.gsub!(/#KERNEL_VERSION#/, @linux_helper.kernel_version(guestfs)) 139: menu_lst_data.gsub!(/#KERNEL_IMAGE_NAME#/, @linux_helper.kernel_image_name(guestfs)) 140: 141: menu_lst = Tempfile.new('menu_lst') 142: menu_lst << menu_lst_data 143: menu_lst.flush 144: 145: guestfs.upload(menu_lst.path, "/boot/grub/menu.lst") 146: 147: menu_lst.close 148: @log.debug "'/boot/grub/menu.lst' file uploaded." 149: end
# File lib/boxgrinder-build/plugins/platform/ec2/ec2-plugin.rb, line 133 133: def install_menu_lst(guestfs) 134: @log.debug "Uploading '/boot/grub/menu.lst' file..." 135: menu_lst_data = File.open("#{File.dirname(__FILE__)}/src/menu.lst").read 136: 137: menu_lst_data.gsub!(/#TITLE#/, @appliance_config.name) 138: menu_lst_data.gsub!(/#KERNEL_VERSION#/, @linux_helper.kernel_version(guestfs)) 139: menu_lst_data.gsub!(/#KERNEL_IMAGE_NAME#/, @linux_helper.kernel_image_name(guestfs)) 140: 141: menu_lst = Tempfile.new('menu_lst') 142: menu_lst << menu_lst_data 143: menu_lst.flush 144: 145: guestfs.upload(menu_lst.path, "/boot/grub/menu.lst") 146: 147: menu_lst.close 148: @log.debug "'/boot/grub/menu.lst' file uploaded." 149: end
# File lib/boxgrinder-build/plugins/platform/ec2/ec2-plugin.rb, line 90 90: def recreate_journal(guestfs) 91: @log.debug "Recreating EXT3 journal on root partition." 92: guestfs.sh("tune2fs -j #{guestfs.list_devices.first}") 93: @log.debug "Journal recreated." 94: end
# File lib/boxgrinder-build/plugins/platform/ec2/ec2-plugin.rb, line 90 90: def recreate_journal(guestfs) 91: @log.debug "Recreating EXT3 journal on root partition." 92: guestfs.sh("tune2fs -j #{guestfs.list_devices.first}") 93: @log.debug "Journal recreated." 94: end
# File lib/boxgrinder-build/plugins/platform/ec2/ec2-plugin.rb, line 113 113: def upload_fstab(guestfs) 114: @log.debug "Uploading '/etc/fstab' file..." 115: 116: fstab_file = @appliance_config.is64bit? ? "#{File.dirname(__FILE__)}/src/fstab_64bit" : "#{File.dirname(__FILE__)}/src/fstab_32bit" 117: 118: fstab_data = File.open(fstab_file).read 119: fstab_data.gsub!(/#DISK_DEVICE_PREFIX#/, disk_device_prefix) 120: fstab_data.gsub!(/#FILESYSTEM_TYPE#/, @appliance_config.hardware.partitions['/']['type']) 121: 122: fstab = Tempfile.new('fstab') 123: fstab << fstab_data 124: fstab.flush 125: 126: guestfs.upload(fstab.path, "/etc/fstab") 127: 128: fstab.close 129: 130: @log.debug "'/etc/fstab' file uploaded." 131: end
# File lib/boxgrinder-build/plugins/platform/ec2/ec2-plugin.rb, line 113 113: def upload_fstab(guestfs) 114: @log.debug "Uploading '/etc/fstab' file..." 115: 116: fstab_file = @appliance_config.is64bit? ? "#{File.dirname(__FILE__)}/src/fstab_64bit" : "#{File.dirname(__FILE__)}/src/fstab_32bit" 117: 118: fstab_data = File.open(fstab_file).read 119: fstab_data.gsub!(/#DISK_DEVICE_PREFIX#/, disk_device_prefix) 120: fstab_data.gsub!(/#FILESYSTEM_TYPE#/, @appliance_config.hardware.partitions['/']['type']) 121: 122: fstab = Tempfile.new('fstab') 123: fstab << fstab_data 124: fstab.flush 125: 126: guestfs.upload(fstab.path, "/etc/fstab") 127: 128: fstab.close 129: 130: @log.debug "'/etc/fstab' file uploaded." 131: end
# File lib/boxgrinder-build/plugins/platform/ec2/ec2-plugin.rb, line 175 175: def upload_rc_local(guestfs) 176: @log.debug "Uploading '/etc/rc.local' file..." 177: rc_local = Tempfile.new('rc_local') 178: rc_local << guestfs.read_file("/etc/rc.local") + File.read("#{File.dirname(__FILE__)}/src/rc_local") 179: rc_local.flush 180: 181: guestfs.upload(rc_local.path, "/etc/rc.local") 182: 183: rc_local.close 184: @log.debug "'/etc/rc.local' file uploaded." 185: end
# File lib/boxgrinder-build/plugins/platform/ec2/ec2-plugin.rb, line 175 175: def upload_rc_local(guestfs) 176: @log.debug "Uploading '/etc/rc.local' file..." 177: rc_local = Tempfile.new('rc_local') 178: rc_local << guestfs.read_file("/etc/rc.local") + File.read("#{File.dirname(__FILE__)}/src/rc_local") 179: rc_local.flush 180: 181: guestfs.upload(rc_local.path, "/etc/rc.local") 182: 183: rc_local.close 184: @log.debug "'/etc/rc.local' file uploaded." 185: end