Skip to content

Commit

Permalink
simplifying creation of vmware enterprise images
Browse files Browse the repository at this point in the history
  • Loading branch information
goldmann committed Jan 30, 2009
1 parent 64556eb commit cf6e654
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 49 deletions.
78 changes: 29 additions & 49 deletions lib/jboss-cloud/appliance-vmx-image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def define_precursors
vmware_personal_vmx_file = vmware_personal_output_folder + "/" + File.basename( @appliance_xml_file, ".xml" ) + '.vmx'
vmware_enterprise_output_folder = File.dirname( @appliance_xml_file ) + "/vmware/enterprise"
vmware_enterprise_vmx_file = vmware_enterprise_output_folder + "/" + File.basename( @appliance_xml_file, ".xml" ) + '.vmx'
vmware_enterprise_vmdk_file = vmware_enterprise_output_folder + "/" + File.basename( @appliance_xml_file, ".xml" ) + '.vmdk'

file "#{@appliance_xml_file}.vmx-input" => [ @appliance_xml_file ] do
doc = REXML::Document.new( File.read( @appliance_xml_file ) )
Expand All @@ -42,80 +43,59 @@ def define_precursors
arch_elem.text = @arch
File.open( "#{@appliance_xml_file}.vmx-input", 'w' ) {|f| f.write( doc ) }
end
#desc "Build #{super_simple_name} appliance for VMware personal environments (Server/Workstation/Fusion)"

desc "Build #{super_simple_name} appliance for VMware personal environments (Server/Workstation/Fusion)"
task "appliance:#{@simple_name}:vmware:personal" => [ "#{@appliance_xml_file}.vmx-input" ] do
FileUtils.mkdir_p vmware_personal_output_folder
FileUtils.mkdir_p vmware_personal_output_folder

if ( !File.exists?( vmware_personal_vmx_file ) || File.new( "#{@appliance_xml_file}.vmx-input" ).mtime > File.new( vmware_personal_vmx_file ).mtime )
execute_command( "#{Dir.pwd}/lib/python-virtinst/virt-convert -o vmx -D vmdk #{@appliance_xml_file}.vmx-input #{vmware_personal_output_folder}/" )
end
end

#desc "Build #{super_simple_name} appliance for VMware enterprise environments (ESX/ESXi)"
task "appliance:#{@simple_name}:vmware:enterprise" => [ "appliance:#{@simple_name}:vmware:personal" ] do
desc "Build #{super_simple_name} appliance for VMware enterprise environments (ESX/ESXi)"
task "appliance:#{@simple_name}:vmware:enterprise" => [ @appliance_xml_file ] do
FileUtils.mkdir_p vmware_enterprise_output_folder

# copy RAW disk to VMware enterprise destination folder
FileUtils.cp( File.dirname( @appliance_xml_file ) + "/#{@simple_name}-sda.raw", vmware_enterprise_output_folder + "/#{@simple_name}-sda.raw" )
base_raw_file = File.dirname( @appliance_xml_file ) + "/#{@simple_name}-sda.raw"
vmware_raw_file = vmware_enterprise_output_folder + "/#{@simple_name}-sda.raw"

vmx_data = File.open( vmware_personal_vmx_file ).readlines

vmx_data.map! do |line|
# replace guestOS informations to: other26xlinux or other26xlinux-64, this seems to be the savests values (tm)
line = line.gsub(/guestOS = (.*)/, "guestOS = #{@arch == "x86_64" ? "other26xlinux-64" : "other26xlinux"}")
# copy RAW disk to VMware enterprise destination folder
# todo: consider moving this file

# replace IDE disk with SCSI, it's recommended for workstation and required for ESX
line = line.gsub(/ide0:0/, "scsi0:0")
if ( !File.exists?( vmware_raw_file ) || File.new( base_raw_file ).mtime > File.new( vmware_raw_file ).mtime )
FileUtils.cp( base_raw_file , vmware_enterprise_output_folder )
end

vmx_data = File.open( "src/base.vmx" ).read

# todo add version gsub: #VERSION#
vmx_data.gsub!( /#NAME#/ , @simple_name )
# replace guestOS informations to: other26xlinux or other26xlinux-64, this seems to be the savests values (tm)
vmx_data.gsub!( /#GUESTOS#/ , "#{@arch == "x86_64" ? "other26xlinux-64" : "other26xlinux"}" )
# replace IDE disk with SCSI, it's recommended for workstation and required for ESX
vmx_data.gsub!( /ide0:0/ , "scsi0:0" )

# yes, we want a SCSI controller because we have SCSI disks!
vmx_data += ["scsi0.present = \"true\""] unless vmx_data.grep(/scsi0.present = "true"/).length > 0
vmx_data += ["scsi0.virtualDev = \"lsilogic\""] unless vmx_data.grep(/scsi0.virtualDev = "lsilogic"/).length > 0
vmx_data += "\nscsi0.present = \"true\""
vmx_data += "\nscsi0.virtualDev = \"lsilogic\""

# write changes to file
File.new( vmware_enterprise_vmx_file , "w+" ).puts( vmx_data )

# create new VMDK descriptor file
vmdk_descriptor_file_name = vmware_enterprise_output_folder + "/#{@simple_name}-sda.vmdk"

vmdk_file = File.new( vmdk_descriptor_file_name, "w+" )
vmdk_data = File.open( "src/base.vmdk" ).read
vmdk_data.gsub!( /#NAME#/ , @simple_name )

vmdk_file.puts("# Disk DescriptorFile")
vmdk_file.puts("version=1")
vmdk_file.puts("CID=af54a9d2")
vmdk_file.puts("parentCID=ffffffff")
vmdk_file.puts("createType=\"vmfs\"")

vmdk_file.puts("")

vmdk_file.puts("# Extent description")
# todo: read from kickstart file disk size and put appropriate value after RW:
vmdk_file.puts("RW 4194304 VMFS \"#{@simple_name}-sda.raw\"")

vmdk_file.puts("")

vmdk_file.puts("# The Disk Data Base")
vmdk_file.puts("#DDB")

vmdk_file.puts("")

# todo: update these values according to disk size change
vmdk_file.puts("ddb.toolsVersion = \"0\"")
vmdk_file.puts("ddb.adapterType = \"lsilogic\"")
vmdk_file.puts("ddb.geometry.sectors = \"63\"")
vmdk_file.puts("ddb.geometry.heads = \"255\"")
vmdk_file.puts("ddb.geometry.cylinders = \"261\"")
vmdk_file.puts("ddb.encoding = \"UTF-8\"")
vmdk_file.puts("ddb.virtualHWVersion = \"4\"")

# don't know if this is required, for now - commented
#ddb.uuid = "60 00 C2 97 c7 af 99 c5-bc d9 2a eb 9c 7b 66 10"
# create new VMDK descriptor file
File.new( vmware_enterprise_vmdk_file, "w+" ).puts( vmdk_data )

end

desc "Build #{super_simple_name} appliance for VMware"
task "appliance:#{@simple_name}:vmware" => [ "appliance:#{@simple_name}:vmware:enterprise" ]
#desc "Build #{super_simple_name} appliance for VMware"
#task "appliance:#{@simple_name}:vmware" => [ "appliance:#{@simple_name}:vmware:personal", "appliance:#{@simple_name}:vmware:enterprise" ]
end
end
end
19 changes: 19 additions & 0 deletions src/base.vmdk
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Disk DescriptorFile
version=1
CID=af54a9d2
parentCID=ffffffff
createType="vmfs"

# Extent description
RW 4194304 VMFS "#NAME#-sda.raw"

# The Disk Data Base
#DDB

ddb.toolsVersion = "0"
ddb.adapterType = "lsilogic"
ddb.geometry.sectors = "63"
ddb.geometry.heads = "255"
ddb.geometry.cylinders = "261"
ddb.encoding = "UTF-8"
ddb.virtualHWVersion = "4"
43 changes: 43 additions & 0 deletions src/base.vmx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

#!/usr/bin/vmware

config.version = "8"
virtualHW.version = "4"
guestOS = #GUESTOS#
displayName = "#NAME#"
annotation = "#NAME# | Version: #VERSION#"
guestinfo.vmware.product.long = "#NAME#"
guestinfo.vmware.product.url = "http://oddthesis.org/"
guestinfo.vmware.product.class = "virtual machine"
numvcpus = "1"
memsize = "1024"
MemAllowAutoScaleDown = "FALSE"
MemTrimRate = "-1"
uuid.action = "create"
tools.remindInstall = "TRUE"
hints.hideAll = "TRUE"
tools.syncTime = "TRUE"
serial0.present = "FALSE"
serial1.present = "FALSE"
parallel0.present = "FALSE"
logging = "TRUE"
log.fileName = "#NAME#.log"
log.append = "TRUE"
log.keepOld = "3"
isolation.tools.hgfs.disable = "FALSE"
isolation.tools.dnd.disable = "FALSE"
isolation.tools.copy.enable = "TRUE"
isolation.tools.paste.enabled = "TRUE"
floppy0.present = "FALSE"

ide0:0.present = "TRUE"
ide0:0.fileName = "#NAME#.vmdk"
ide0:0.mode = "persistent"
ide0:0.startConnected = "TRUE"
ide0:0.writeThrough = "TRUE"

ethernet0.present = "TRUE"
ethernet0.connectionType = "nat"
ethernet0.addressType = "generated"
ethernet0.generatedAddressOffset = "0"
ethernet0.autoDetect = "TRUE"

0 comments on commit cf6e654

Please sign in to comment.