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 151 151: def add_ec2_user(guestfs) 152: @log.debug "Adding ec2-user user..." 153: guestfs.sh("useradd ec2-user") 154: guestfs.sh("echo -e 'ec2-user\tALL=(ALL)\tNOPASSWD: ALL' >> /etc/sudoers") 155: @log.debug "User ec2-user added." 156: end
issues.jboss.org/browse/BGBUILD-110
# File lib/boxgrinder-build/plugins/platform/ec2/ec2-plugin.rb, line 151 151: def add_ec2_user(guestfs) 152: @log.debug "Adding ec2-user user..." 153: guestfs.sh("useradd ec2-user") 154: guestfs.sh("echo -e 'ec2-user\tALL=(ALL)\tNOPASSWD: ALL' >> /etc/sudoers") 155: @log.debug "User ec2-user added." 156: 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 178 178: def change_configuration(guestfs_helper) 179: guestfs_helper.augeas do 180: # disable password authentication 181: set("/etc/ssh/sshd_config", "PasswordAuthentication", "no") 182: 183: # disable root login 184: set("/etc/ssh/sshd_config", "PermitRootLogin", "no") 185: end 186: end
# File lib/boxgrinder-build/plugins/platform/ec2/ec2-plugin.rb, line 178 178: def change_configuration(guestfs_helper) 179: guestfs_helper.augeas do 180: # disable password authentication 181: set("/etc/ssh/sshd_config", "PasswordAuthentication", "no") 182: 183: # disable root login 184: set("/etc/ssh/sshd_config", "PermitRootLogin", "no") 185: end 186: end
# File lib/boxgrinder-build/plugins/platform/ec2/ec2-plugin.rb, line 87 87: def create_devices(guestfs) 88: return if guestfs.exists('/sbin/MAKEDEV') == 0 89: 90: @log.debug "Creating required devices..." 91: guestfs.sh("/sbin/MAKEDEV -d /dev -x console") 92: guestfs.sh("/sbin/MAKEDEV -d /dev -x null") 93: guestfs.sh("/sbin/MAKEDEV -d /dev -x zero") 94: @log.debug "Devices created." 95: end
# File lib/boxgrinder-build/plugins/platform/ec2/ec2-plugin.rb, line 87 87: def create_devices(guestfs) 88: return if guestfs.exists('/sbin/MAKEDEV') == 0 89: 90: @log.debug "Creating required devices..." 91: guestfs.sh("/sbin/MAKEDEV -d /dev -x console") 92: guestfs.sh("/sbin/MAKEDEV -d /dev -x null") 93: guestfs.sh("/sbin/MAKEDEV -d /dev -x zero") 94: @log.debug "Devices created." 95: end
# File lib/boxgrinder-build/plugins/platform/ec2/ec2-plugin.rb, line 97 97: def disk_device_prefix 98: disk = 'xv' 99: disk = 's' if (@appliance_config.os.name == 'rhel' or @appliance_config.os.name == 'centos') and @appliance_config.os.version == '5' 100: 101: disk 102: end
# File lib/boxgrinder-build/plugins/platform/ec2/ec2-plugin.rb, line 97 97: def disk_device_prefix 98: disk = 'xv' 99: disk = 's' if (@appliance_config.os.name == 'rhel' or @appliance_config.os.name == 'centos') and @appliance_config.os.version == '5' 100: 101: disk 102: end
enable networking on default runlevels
# File lib/boxgrinder-build/plugins/platform/ec2/ec2-plugin.rb, line 159 159: def enable_networking(guestfs) 160: @log.debug "Enabling networking..." 161: guestfs.sh("/sbin/chkconfig network on") 162: guestfs.upload("#{File.dirname(__FILE__)}/src/ifcfg-eth0", "/etc/sysconfig/network-scripts/ifcfg-eth0") 163: @log.debug "Networking enabled." 164: end
enable networking on default runlevels
# File lib/boxgrinder-build/plugins/platform/ec2/ec2-plugin.rb, line 159 159: def enable_networking(guestfs) 160: @log.debug "Enabling networking..." 161: guestfs.sh("/sbin/chkconfig network on") 162: guestfs.upload("#{File.dirname(__FILE__)}/src/ifcfg-eth0", "/etc/sysconfig/network-scripts/ifcfg-eth0") 163: @log.debug "Networking enabled." 164: 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 143 143: def enable_nosegneg_flag(guestfs) 144: @log.debug "Enabling nosegneg flag..." 145: guestfs.sh("echo \"hwcap 1 nosegneg\" > /etc/ld.so.conf.d/libc6-xen.conf") 146: guestfs.sh("/sbin/ldconfig") 147: @log.debug "Nosegneg enabled." 148: 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 143 143: def enable_nosegneg_flag(guestfs) 144: @log.debug "Enabling nosegneg flag..." 145: guestfs.sh("echo \"hwcap 1 nosegneg\" > /etc/ld.so.conf.d/libc6-xen.conf") 146: guestfs.sh("/sbin/ldconfig") 147: @log.debug "Nosegneg enabled." 148: 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: # Remove normal kernel 45: guestfs.sh("yum -y remove kernel") 46: # because we need to install kernel-xen package 47: guestfs.sh("yum -y install kernel-xen") 48: # and add require modules 49: @linux_helper.recreate_kernel_image(guestfs, ['xenblk', 'xennet']) 50: end 51: 52: # TODO is this really needed? 53: @log.debug "Uploading '/etc/resolv.conf'..." 54: guestfs.upload("/etc/resolv.conf", "/etc/resolv.conf") 55: @log.debug "'/etc/resolv.conf' uploaded." 56: 57: create_devices(guestfs) 58: 59: guestfs.mkdir("/data") if @appliance_config.is64bit? 60: 61: upload_fstab(guestfs) 62: enable_networking(guestfs) 63: upload_rc_local(guestfs) 64: add_ec2_user(guestfs) 65: change_configuration(guestfs_helper) 66: install_menu_lst(guestfs) 67: 68: enable_nosegneg_flag(guestfs) if @appliance_config.os.name == 'fedora' 69: 70: execute_post(guestfs_helper) 71: end 72: 73: @log.info "Image converted to EC2 format." 74: 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: # Remove normal kernel 45: guestfs.sh("yum -y remove kernel") 46: # because we need to install kernel-xen package 47: guestfs.sh("yum -y install kernel-xen") 48: # and add require modules 49: @linux_helper.recreate_kernel_image(guestfs, ['xenblk', 'xennet']) 50: end 51: 52: # TODO is this really needed? 53: @log.debug "Uploading '/etc/resolv.conf'..." 54: guestfs.upload("/etc/resolv.conf", "/etc/resolv.conf") 55: @log.debug "'/etc/resolv.conf' uploaded." 56: 57: create_devices(guestfs) 58: 59: guestfs.mkdir("/data") if @appliance_config.is64bit? 60: 61: upload_fstab(guestfs) 62: enable_networking(guestfs) 63: upload_rc_local(guestfs) 64: add_ec2_user(guestfs) 65: change_configuration(guestfs_helper) 66: install_menu_lst(guestfs) 67: 68: enable_nosegneg_flag(guestfs) if @appliance_config.os.name == 'fedora' 69: 70: execute_post(guestfs_helper) 71: end 72: 73: @log.info "Image converted to EC2 format." 74: end
# File lib/boxgrinder-build/plugins/platform/ec2/ec2-plugin.rb, line 76 76: def execute_post(guestfs_helper) 77: unless @appliance_config.post['ec2'].nil? 78: @appliance_config.post['ec2'].each do |cmd| 79: guestfs_helper.sh(cmd, :arch => @appliance_config.hardware.arch) 80: end 81: @log.debug "Post commands from appliance definition file executed." 82: else 83: @log.debug "No commands specified, skipping." 84: end 85: end
# File lib/boxgrinder-build/plugins/platform/ec2/ec2-plugin.rb, line 76 76: def execute_post(guestfs_helper) 77: unless @appliance_config.post['ec2'].nil? 78: @appliance_config.post['ec2'].each do |cmd| 79: guestfs_helper.sh(cmd, :arch => @appliance_config.hardware.arch) 80: end 81: @log.debug "Post commands from appliance definition file executed." 82: else 83: @log.debug "No commands specified, skipping." 84: end 85: end
# File lib/boxgrinder-build/plugins/platform/ec2/ec2-plugin.rb, line 124 124: def install_menu_lst(guestfs) 125: @log.debug "Uploading '/boot/grub/menu.lst' file..." 126: menu_lst_data = File.open("#{File.dirname(__FILE__)}/src/menu.lst").read 127: 128: menu_lst_data.gsub!(/#TITLE#/, @appliance_config.name) 129: menu_lst_data.gsub!(/#KERNEL_VERSION#/, @linux_helper.kernel_version(guestfs)) 130: menu_lst_data.gsub!(/#KERNEL_IMAGE_NAME#/, @linux_helper.kernel_image_name(guestfs)) 131: 132: menu_lst = Tempfile.new('menu_lst') 133: menu_lst << menu_lst_data 134: menu_lst.flush 135: 136: guestfs.upload(menu_lst.path, "/boot/grub/menu.lst") 137: 138: menu_lst.close 139: @log.debug "'/boot/grub/menu.lst' file uploaded." 140: end
# File lib/boxgrinder-build/plugins/platform/ec2/ec2-plugin.rb, line 124 124: def install_menu_lst(guestfs) 125: @log.debug "Uploading '/boot/grub/menu.lst' file..." 126: menu_lst_data = File.open("#{File.dirname(__FILE__)}/src/menu.lst").read 127: 128: menu_lst_data.gsub!(/#TITLE#/, @appliance_config.name) 129: menu_lst_data.gsub!(/#KERNEL_VERSION#/, @linux_helper.kernel_version(guestfs)) 130: menu_lst_data.gsub!(/#KERNEL_IMAGE_NAME#/, @linux_helper.kernel_image_name(guestfs)) 131: 132: menu_lst = Tempfile.new('menu_lst') 133: menu_lst << menu_lst_data 134: menu_lst.flush 135: 136: guestfs.upload(menu_lst.path, "/boot/grub/menu.lst") 137: 138: menu_lst.close 139: @log.debug "'/boot/grub/menu.lst' file uploaded." 140: end
# File lib/boxgrinder-build/plugins/platform/ec2/ec2-plugin.rb, line 104 104: def upload_fstab(guestfs) 105: @log.debug "Uploading '/etc/fstab' file..." 106: 107: fstab_file = @appliance_config.is64bit? ? "#{File.dirname(__FILE__)}/src/fstab_64bit" : "#{File.dirname(__FILE__)}/src/fstab_32bit" 108: 109: fstab_data = File.open(fstab_file).read 110: fstab_data.gsub!(/#DISK_DEVICE_PREFIX#/, disk_device_prefix) 111: fstab_data.gsub!(/#FILESYSTEM_TYPE#/, @appliance_config.hardware.partitions['/']['type']) 112: 113: fstab = Tempfile.new('fstab') 114: fstab << fstab_data 115: fstab.flush 116: 117: guestfs.upload(fstab.path, "/etc/fstab") 118: 119: fstab.close 120: 121: @log.debug "'/etc/fstab' file uploaded." 122: end
# File lib/boxgrinder-build/plugins/platform/ec2/ec2-plugin.rb, line 104 104: def upload_fstab(guestfs) 105: @log.debug "Uploading '/etc/fstab' file..." 106: 107: fstab_file = @appliance_config.is64bit? ? "#{File.dirname(__FILE__)}/src/fstab_64bit" : "#{File.dirname(__FILE__)}/src/fstab_32bit" 108: 109: fstab_data = File.open(fstab_file).read 110: fstab_data.gsub!(/#DISK_DEVICE_PREFIX#/, disk_device_prefix) 111: fstab_data.gsub!(/#FILESYSTEM_TYPE#/, @appliance_config.hardware.partitions['/']['type']) 112: 113: fstab = Tempfile.new('fstab') 114: fstab << fstab_data 115: fstab.flush 116: 117: guestfs.upload(fstab.path, "/etc/fstab") 118: 119: fstab.close 120: 121: @log.debug "'/etc/fstab' file uploaded." 122: end
# File lib/boxgrinder-build/plugins/platform/ec2/ec2-plugin.rb, line 166 166: def upload_rc_local(guestfs) 167: @log.debug "Uploading '/etc/rc.local' file..." 168: rc_local = Tempfile.new('rc_local') 169: rc_local << guestfs.read_file("/etc/rc.local") + File.read("#{File.dirname(__FILE__)}/src/rc_local") 170: rc_local.flush 171: 172: guestfs.upload(rc_local.path, "/etc/rc.local") 173: 174: rc_local.close 175: @log.debug "'/etc/rc.local' file uploaded." 176: end
# File lib/boxgrinder-build/plugins/platform/ec2/ec2-plugin.rb, line 166 166: def upload_rc_local(guestfs) 167: @log.debug "Uploading '/etc/rc.local' file..." 168: rc_local = Tempfile.new('rc_local') 169: rc_local << guestfs.read_file("/etc/rc.local") + File.read("#{File.dirname(__FILE__)}/src/rc_local") 170: rc_local.flush 171: 172: guestfs.upload(rc_local.path, "/etc/rc.local") 173: 174: rc_local.close 175: @log.debug "'/etc/rc.local' file uploaded." 176: end