lib/multidisk-boxgrinder-plugin.rb in multidisk-boxgrinder-plugin-0.1 vs lib/multidisk-boxgrinder-plugin.rb in multidisk-boxgrinder-plugin-0.1.1

- old
+ new

@@ -1,4 +1,39 @@ -require 'multidisk-boxgrinder-plugin/multidisk' +require 'boxgrinder-build/plugins/base-plugin' -plugin :class => BoxGrinder::MultiDiskPlugin, :type => :platform, :name => :multidisk, :full_name => "Multi Disk" +module BoxGrinder + class MultiDiskPlugin < BasePlugin + plugin :type => :platform, :name => :multidisk, :full_name => "Multi Disk" + + def after_init + register_deliverable(:vmdk_sparse => "#{@appliance_config.name}-sparse.vmdk") + register_deliverable(:vmdk_stream => "#{@appliance_config.name}-streamoptimized.vmdk") + register_deliverable(:qcow_sparse => "#{@appliance_config.name}-sparse.qcow2") + register_deliverable(:qcow_compressed => "#{@appliance_config.name}-compressed.qcow2") + end + + def execute + @log.info "Converting RAW to multiple disk formats" + + @log.info "Converting to VMDK Sparse using qemu-img..." + @exec_helper.execute "qemu-img convert -O vmdk '#{@previous_deliverables.disk}' '#{@deliverables.vmdk_sparse}'" + + @log.info "Converting to QCow2 Sparse using qemu-img..." + @exec_helper.execute "qemu-img convert -O qcow2 '#{@previous_deliverables.disk}' '#{@deliverables.qcow_sparse}'" + + @log.info "Converting to QCow2 Compressed Sparse using qemu-img..." + @exec_helper.execute "qemu-img convert -c -O qcow2 '#{@previous_deliverables.disk}' '#{@deliverables.qcow_compressed}'" + + if `which VBoxManage`.empty? + @log.error "VBoxManage binary not found in your path, skipping VMDK Stream format." + else + @log.info "Using VBoxManage to convert the image..." + @exec_helper.execute "VBoxManage clonehd --format VMDK --variant Stream '#{@deliverables.vmdk_sparse}' '#{@deliverables.vmdk_stream}'" + end + + @log.info "Conversions done." + end + + end + +end