Class | BoxGrinder::VMwarePlugin |
In: |
lib/boxgrinder-build-vmware-platform-plugin/vmware-plugin.rb
lib/boxgrinder-build-vmware-platform-plugin/vmware-plugin.rb |
Parent: | BasePlugin |
# File lib/boxgrinder-build-vmware-platform-plugin/vmware-plugin.rb, line 24 24: def after_init 25: set_default_config_value('thin_disk', false) 26: validate_plugin_config(['type'], 'http://community.jboss.org/docs/DOC-15528') 27: 28: register_deliverable(:vmx => "#{@appliance_config.name}.vmx", 29: :readme => "README") 30: 31: if @plugin_config['type'].eql?('personal') and @plugin_config['thin_disk'] 32: register_deliverable(:disk => "#{@appliance_config.name}.vmdk") 33: else 34: register_deliverable(:disk => "#{@appliance_config.name}.raw", 35: :vmdk => "#{@appliance_config.name}.vmdk") 36: end 37: end
# File lib/boxgrinder-build-vmware-platform-plugin/vmware-plugin.rb, line 24 24: def after_init 25: set_default_config_value('thin_disk', false) 26: validate_plugin_config(['type'], 'http://community.jboss.org/docs/DOC-15528') 27: 28: register_deliverable(:vmx => "#{@appliance_config.name}.vmx", 29: :readme => "README") 30: 31: if @plugin_config['type'].eql?('personal') and @plugin_config['thin_disk'] 32: register_deliverable(:disk => "#{@appliance_config.name}.vmdk") 33: else 34: register_deliverable(:disk => "#{@appliance_config.name}.raw", 35: :vmdk => "#{@appliance_config.name}.vmdk") 36: end 37: end
# File lib/boxgrinder-build-vmware-platform-plugin/vmware-plugin.rb, line 176 176: def build_vmware_enterprise 177: @log.debug "Building VMware enterprise image." 178: 179: copy_raw_image 180: 181: # defaults for ESXi (maybe for others too) 182: @appliance_config.hardware.network = "VM Network" if @appliance_config.hardware.network.eql?("NAT") 183: 184: # create .vmx file 185: vmx_data = change_common_vmx_values 186: vmx_data += "ethernet0.networkName = \"#{@appliance_config.hardware.network}\"" 187: 188: File.open(@deliverables.vmx, "w") { |f| f.write(vmx_data) } 189: 190: # create disk descriptor file 191: File.open(@deliverables.vmdk, "w") { |f| f.write(change_vmdk_values("vmfs")) } 192: 193: @log.debug "VMware enterprise image was built." 194: end
# File lib/boxgrinder-build-vmware-platform-plugin/vmware-plugin.rb, line 176 176: def build_vmware_enterprise 177: @log.debug "Building VMware enterprise image." 178: 179: copy_raw_image 180: 181: # defaults for ESXi (maybe for others too) 182: @appliance_config.hardware.network = "VM Network" if @appliance_config.hardware.network.eql?("NAT") 183: 184: # create .vmx file 185: vmx_data = change_common_vmx_values 186: vmx_data += "ethernet0.networkName = \"#{@appliance_config.hardware.network}\"" 187: 188: File.open(@deliverables.vmx, "w") { |f| f.write(vmx_data) } 189: 190: # create disk descriptor file 191: File.open(@deliverables.vmdk, "w") { |f| f.write(change_vmdk_values("vmfs")) } 192: 193: @log.debug "VMware enterprise image was built." 194: end
# File lib/boxgrinder-build-vmware-platform-plugin/vmware-plugin.rb, line 156 156: def build_vmware_personal 157: @log.debug "Building VMware personal image." 158: 159: if @plugin_config['thin_disk'] 160: @log.debug "Using qemu-img to convert the image..." 161: @exec_helper.execute "qemu-img convert -f raw -O vmdk -o compat6 #{@previous_deliverables.disk} #{@deliverables.disk}" 162: @log.debug "Conversion done." 163: else 164: copy_raw_image 165: 166: # create disk descriptor file 167: File.open(@deliverables.vmdk, "w") { |f| f.write(change_vmdk_values("monolithicFlat")) } 168: end 169: 170: # create .vmx file 171: File.open(@deliverables.vmx, "w") { |f| f.write(change_common_vmx_values) } 172: 173: @log.debug "VMware personal image was built." 174: end
# File lib/boxgrinder-build-vmware-platform-plugin/vmware-plugin.rb, line 156 156: def build_vmware_personal 157: @log.debug "Building VMware personal image." 158: 159: if @plugin_config['thin_disk'] 160: @log.debug "Using qemu-img to convert the image..." 161: @exec_helper.execute "qemu-img convert -f raw -O vmdk -o compat6 #{@previous_deliverables.disk} #{@deliverables.disk}" 162: @log.debug "Conversion done." 163: else 164: copy_raw_image 165: 166: # create disk descriptor file 167: File.open(@deliverables.vmdk, "w") { |f| f.write(change_vmdk_values("monolithicFlat")) } 168: end 169: 170: # create .vmx file 171: File.open(@deliverables.vmx, "w") { |f| f.write(change_common_vmx_values) } 172: 173: @log.debug "VMware personal image was built." 174: end
# File lib/boxgrinder-build-vmware-platform-plugin/vmware-plugin.rb, line 114 114: def change_common_vmx_values 115: vmx_data = File.open("#{File.dirname(__FILE__)}/src/base.vmx").read 116: 117: # replace version with current appliance version 118: vmx_data.gsub!(/#VERSION#/, "#{@appliance_config.version}.#{@appliance_config.release}") 119: # replace builder with current builder name and version 120: vmx_data.gsub!(/#BUILDER#/, "#{@config.name} #{@config.version_with_release}") 121: # change name 122: vmx_data.gsub!(/#NAME#/, @appliance_config.name.to_s) 123: # and summary 124: vmx_data.gsub!(/#SUMMARY#/, @appliance_config.summary.to_s) 125: # replace guestOS informations to: linux or otherlinux-64, this seems to be the savests values 126: vmx_data.gsub!(/#GUESTOS#/, "#{@appliance_config.hardware.arch == "x86_64" ? "otherlinux-64" : "linux"}") 127: # memory size 128: vmx_data.gsub!(/#MEM_SIZE#/, @appliance_config.hardware.memory.to_s) 129: # memory size 130: vmx_data.gsub!(/#VCPU#/, @appliance_config.hardware.cpus.to_s) 131: # network name 132: # vmx_data.gsub!( /#NETWORK_NAME#/, @image_config.network_name ) 133: 134: vmx_data 135: end
# File lib/boxgrinder-build-vmware-platform-plugin/vmware-plugin.rb, line 114 114: def change_common_vmx_values 115: vmx_data = File.open("#{File.dirname(__FILE__)}/src/base.vmx").read 116: 117: # replace version with current appliance version 118: vmx_data.gsub!(/#VERSION#/, "#{@appliance_config.version}.#{@appliance_config.release}") 119: # replace builder with current builder name and version 120: vmx_data.gsub!(/#BUILDER#/, "#{@config.name} #{@config.version_with_release}") 121: # change name 122: vmx_data.gsub!(/#NAME#/, @appliance_config.name.to_s) 123: # and summary 124: vmx_data.gsub!(/#SUMMARY#/, @appliance_config.summary.to_s) 125: # replace guestOS informations to: linux or otherlinux-64, this seems to be the savests values 126: vmx_data.gsub!(/#GUESTOS#/, "#{@appliance_config.hardware.arch == "x86_64" ? "otherlinux-64" : "linux"}") 127: # memory size 128: vmx_data.gsub!(/#MEM_SIZE#/, @appliance_config.hardware.memory.to_s) 129: # memory size 130: vmx_data.gsub!(/#VCPU#/, @appliance_config.hardware.cpus.to_s) 131: # network name 132: # vmx_data.gsub!( /#NETWORK_NAME#/, @image_config.network_name ) 133: 134: vmx_data 135: end
# File lib/boxgrinder-build-vmware-platform-plugin/vmware-plugin.rb, line 90 90: def change_vmdk_values(type) 91: vmdk_data = File.open("#{File.dirname(__FILE__)}/src/base.vmdk").read 92: 93: disk_size = 0.0 94: @appliance_config.hardware.partitions.values.each { |part| disk_size += part['size'].to_f } 95: 96: c, h, s, total_sectors = generate_scsi_chs(disk_size) 97: 98: is_enterprise = type.eql?("vmfs") 99: 100: vmdk_data.gsub!(/#NAME#/, @appliance_config.name) 101: vmdk_data.gsub!(/#TYPE#/, type) 102: vmdk_data.gsub!(/#EXTENT_TYPE#/, is_enterprise ? "VMFS" : "FLAT") 103: vmdk_data.gsub!(/#NUMBER#/, is_enterprise ? "" : "0") 104: vmdk_data.gsub!(/#HW_VERSION#/, "7") 105: vmdk_data.gsub!(/#CYLINDERS#/, c.to_s) 106: vmdk_data.gsub!(/#HEADS#/, h.to_s) 107: vmdk_data.gsub!(/#SECTORS#/, s.to_s) 108: vmdk_data.gsub!(/#TOTAL_SECTORS#/, total_sectors.to_s) 109: vmdk_data.gsub!(/#THIN_PROVISIONED#/, @plugin_config['thin_disk'] ? "1" : "0") 110: 111: vmdk_data 112: end
# File lib/boxgrinder-build-vmware-platform-plugin/vmware-plugin.rb, line 90 90: def change_vmdk_values(type) 91: vmdk_data = File.open("#{File.dirname(__FILE__)}/src/base.vmdk").read 92: 93: disk_size = 0.0 94: @appliance_config.hardware.partitions.values.each { |part| disk_size += part['size'].to_f } 95: 96: c, h, s, total_sectors = generate_scsi_chs(disk_size) 97: 98: is_enterprise = type.eql?("vmfs") 99: 100: vmdk_data.gsub!(/#NAME#/, @appliance_config.name) 101: vmdk_data.gsub!(/#TYPE#/, type) 102: vmdk_data.gsub!(/#EXTENT_TYPE#/, is_enterprise ? "VMFS" : "FLAT") 103: vmdk_data.gsub!(/#NUMBER#/, is_enterprise ? "" : "0") 104: vmdk_data.gsub!(/#HW_VERSION#/, "7") 105: vmdk_data.gsub!(/#CYLINDERS#/, c.to_s) 106: vmdk_data.gsub!(/#HEADS#/, h.to_s) 107: vmdk_data.gsub!(/#SECTORS#/, s.to_s) 108: vmdk_data.gsub!(/#TOTAL_SECTORS#/, total_sectors.to_s) 109: vmdk_data.gsub!(/#THIN_PROVISIONED#/, @plugin_config['thin_disk'] ? "1" : "0") 110: 111: vmdk_data 112: end
# File lib/boxgrinder-build-vmware-platform-plugin/vmware-plugin.rb, line 150 150: def copy_raw_image 151: @log.debug "Copying VMware image file, this may take several minutes..." 152: @exec_helper.execute "cp #{@previous_deliverables.disk} #{@deliverables.disk}" 153: @log.debug "VMware image copied." 154: end
# File lib/boxgrinder-build-vmware-platform-plugin/vmware-plugin.rb, line 150 150: def copy_raw_image 151: @log.debug "Copying VMware image file, this may take several minutes..." 152: @exec_helper.execute "cp #{@previous_deliverables.disk} #{@deliverables.disk}" 153: @log.debug "VMware image copied." 154: end
# File lib/boxgrinder-build-vmware-platform-plugin/vmware-plugin.rb, line 58 58: def create_readme 59: readme = File.open("#{File.dirname(__FILE__)}/src/README-#{@plugin_config['type']}").read 60: readme.gsub!(/#APPLIANCE_NAME#/, @appliance_config.name) 61: readme.gsub!(/#NAME#/, @config.name) 62: readme.gsub!(/#VERSION#/, @config.version_with_release) 63: 64: readme 65: end
# File lib/boxgrinder-build-vmware-platform-plugin/vmware-plugin.rb, line 58 58: def create_readme 59: readme = File.open("#{File.dirname(__FILE__)}/src/README-#{@plugin_config['type']}").read 60: readme.gsub!(/#APPLIANCE_NAME#/, @appliance_config.name) 61: readme.gsub!(/#NAME#/, @config.name) 62: readme.gsub!(/#VERSION#/, @config.version_with_release) 63: 64: readme 65: end
# File lib/boxgrinder-build-vmware-platform-plugin/vmware-plugin.rb, line 137 137: def customize_image 138: unless @appliance_config.post['vmware'].nil? 139: @image_helper.customize(@deliverables.disk) do |guestfs, guestfs_helper| 140: @appliance_config.post['vmware'].each do |cmd| 141: guestfs_helper.sh(cmd, :arch => @appliance_config.hardware.arch) 142: end 143: @log.debug "Post commands from appliance definition file executed." 144: end 145: else 146: @log.debug "No commands specified, skipping." 147: end 148: end
# File lib/boxgrinder-build-vmware-platform-plugin/vmware-plugin.rb, line 137 137: def customize_image 138: unless @appliance_config.post['vmware'].nil? 139: @image_helper.customize(@deliverables.disk) do |guestfs, guestfs_helper| 140: @appliance_config.post['vmware'].each do |cmd| 141: guestfs_helper.sh(cmd, :arch => @appliance_config.hardware.arch) 142: end 143: @log.debug "Post commands from appliance definition file executed." 144: end 145: else 146: @log.debug "No commands specified, skipping." 147: end 148: end
# File lib/boxgrinder-build-vmware-platform-plugin/vmware-plugin.rb, line 39 39: def execute 40: @log.info "Converting image to VMware #{@plugin_config['type']} format..." 41: 42: case @plugin_config['type'] 43: when 'personal' 44: build_vmware_personal 45: when 'enterprise' 46: build_vmware_enterprise 47: else 48: raise "Not known VMware format specified. Available are: personal and enterprise. See http://community.jboss.org/docs/DOC-15528 for more info." 49: end 50: 51: customize_image 52: 53: File.open(@deliverables.readme, "w") { |f| f.write(create_readme) } 54: 55: @log.info "Image converted to VMware format." 56: end
# File lib/boxgrinder-build-vmware-platform-plugin/vmware-plugin.rb, line 39 39: def execute 40: @log.info "Converting image to VMware #{@plugin_config['type']} format..." 41: 42: case @plugin_config['type'] 43: when 'personal' 44: build_vmware_personal 45: when 'enterprise' 46: build_vmware_enterprise 47: else 48: raise "Not known VMware format specified. Available are: personal and enterprise. See http://community.jboss.org/docs/DOC-15528 for more info." 49: end 50: 51: customize_image 52: 53: File.open(@deliverables.readme, "w") { |f| f.write(create_readme) } 54: 55: @log.info "Image converted to VMware format." 56: end
returns value of cylinders, heads and sector for selected disk size (in GB) kb.vmware.com/kb/1026254
# File lib/boxgrinder-build-vmware-platform-plugin/vmware-plugin.rb, line 69 69: def generate_scsi_chs(disk_size) 70: if disk_size < 1 71: h = 64 72: s = 32 73: else 74: if disk_size < 2 75: h = 128 76: s = 32 77: else 78: h = 255 79: s = 63 80: end 81: end 82: 83: # GB MB KB B 84: c = disk_size * 1024 * 1024 * 1024 / (h*s*512) 85: total_sectors = disk_size * 1024 * 1024 * 1024 / 512 86: 87: [c.to_i, h.to_i, s.to_i, total_sectors.to_i] 88: end
returns value of cylinders, heads and sector for selected disk size (in GB) kb.vmware.com/kb/1026254
# File lib/boxgrinder-build-vmware-platform-plugin/vmware-plugin.rb, line 69 69: def generate_scsi_chs(disk_size) 70: if disk_size < 1 71: h = 64 72: s = 32 73: else 74: if disk_size < 2 75: h = 128 76: s = 32 77: else 78: h = 255 79: s = 63 80: end 81: end 82: 83: # GB MB KB B 84: c = disk_size * 1024 * 1024 * 1024 / (h*s*512) 85: total_sectors = disk_size * 1024 * 1024 * 1024 / 512 86: 87: [c.to_i, h.to_i, s.to_i, total_sectors.to_i] 88: end